Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(cicd): update tag extractor to support prereleases #1218

Merged
merged 3 commits into from
Jan 29, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 18 additions & 4 deletions .github/workflows/_docker-build-push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,28 @@ jobs:
id: regex
with:
text: ${{ github.ref }}
regex: '^(refs\/tags\/${{ inputs.service-name }}\/(v\d+\.\d+\.\d+))|(refs\/heads\/(main))$'
# https://semver.org/#is-there-a-suggested-regular-expression-regex-to-check-a-semver-string
regex: '^(refs\/tags\/${{ inputs.service-name }}\/v((0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?))|(refs\/heads\/(main))$'
sevenzing marked this conversation as resolved.
Show resolved Hide resolved

- name: Extract tag name
id: tags_extractor
run: |
t=${{ steps.regex.outputs.group2 }}
m=${{ steps.regex.outputs.group4 }}
(if ! [[ "$t" == "" ]]; then echo tags=${{ env.IMAGE_NAME }}:$t, ${{ env.IMAGE_NAME }}:latest; elif ! [[ "$m" == "" ]]; then echo tags=${{ env.IMAGE_NAME }}:$m; else echo tags=; fi) >> $GITHUB_OUTPUT
version=${{ steps.regex.outputs.group2 }}
bragov4ik marked this conversation as resolved.
Show resolved Hide resolved
prerelease=${{ steps.regex.outputs.group6 }}
main=${{ steps.regex.outputs.group9 }}

if [[ -n "$version" ]]; then
if [[ -n "$prerelease" ]]; then
echo "tags=${{ env.IMAGE_NAME }}:$version" >> $GITHUB_OUTPUT
else
echo "tags=${{ env.IMAGE_NAME }}:$version, ${{ env.IMAGE_NAME }}:latest" >> $GITHUB_OUTPUT
fi
elif [[ -n "$main" ]]; then
echo "tags=${{ env.IMAGE_NAME }}:$main" >> $GITHUB_OUTPUT
else
echo "tags=" >> $GITHUB_OUTPUT
fi


- name: Extract metadata for Docker
id: meta
Expand Down
6 changes: 4 additions & 2 deletions .github/workflows/_push_swagger.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,14 @@ jobs:

- name: Get the current tag, branch, or commit hash
id: git_info
# regex from:
# https://semver.org/#is-there-a-suggested-regular-expression-regex-to-check-a-semver-string
run: |
if [ "${{ github.event_name }}" = "workflow_dispatch" ] && [ ! -z "${{ inputs.version }}" ]; then
echo "version=${{ inputs.version }}" >> $GITHUB_ENV
else
if [[ "${GITHUB_REF}" =~ refs/tags/${{ inputs.service_name }}/v[0-9]+\.[0-9]+\.[0-9]+ ]]; then
version=$(echo "${GITHUB_REF}" | grep -o 'v[0-9]\+\.[0-9]\+\.[0-9]\+')
if [[ "${GITHUB_REF}" =~ refs/tags/${{ inputs.service_name }}/v(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)(-((0|[1-9][0-9]*|[0-9]*[a-zA-Z-][0-9a-zA-Z-]*)(\.(0|[1-9][0-9]*|[0-9]*[a-zA-Z-][0-9a-zA-Z-]*))*))?(\+([0-9a-zA-Z-]+(\.[0-9a-zA-Z-]+)*))?$ ]]; then
version=$(echo "${GITHUB_REF}" | sed -E 's|.*/v||')
echo "version=${version}" >> $GITHUB_ENV

# If it's the main branch
Expand Down
Loading