Skip to content

Commit

Permalink
Fix output settings to determine-docker-image-tag action and release …
Browse files Browse the repository at this point in the history
…branch build tag name (#2423)

* fix: add outut settings for action

Signed-off-by: hlts2 <[email protected]>

* fix: tag name for release branch build

Signed-off-by: hlts2 <[email protected]>

* fix: refactor

Signed-off-by: hlts2 <[email protected]>

---------

Signed-off-by: hlts2 <[email protected]>
  • Loading branch information
hlts2 authored Feb 27, 2024
1 parent e97fb0c commit 8a77a5d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 14 deletions.
30 changes: 17 additions & 13 deletions .github/actions/determine-docker-image-tag/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ outputs:
PRIMARY_TAG:
description: "highest priority docker image tag in tag list"
value: ${{ steps.determine_tag_name.outputs.PRIMARY_TAG }}
SECONDARY_TAGS:
description: "List of tags excluding the first one"
value: ${{ steps.determine_tag_name.outputs.SECONDARY_TAGS }}
runs:
using: "composite"
steps:
Expand All @@ -39,34 +42,35 @@ runs:
run: |
if [[ "$GITHUB_REF" =~ ^refs/tags/.* ]]; then
# The following is the priority of tags:
# tag -> release/vx.x tag (release branch build tag) -> commit hash tag -> vx.x -> latest tag
# tag -> release-vx.x tag (release branch build tag) -> commit hash tag -> vx.x -> latest tag
# When a tag is created, the image build for the tag may not be finished.
# In that case, the CI container will use the tag for the release branch.
# At the timing of the creation of the tag, the vx.x points to the previous version, so the priority is lowered.
# (At the timing of the start of the image build for tag, vx.x and tag are equal.)
tag=$(echo $GITHUB_REF | sed -e 's:^refs/tags/::') # e.g) v1.7.6
tags="${tag}"
release_branch_tag="release/${major_minor_tag}" # e.g) release/v1.7
tags="${tags} ${release_branch_tag}"
major_minor_tag="$(echo "${tag}" | sed -E 's/^v?([0-9]+\.[0-9]+).*$/v\1/')" # e.g) v.1.7
tags="${tags} ${major_minor_tag}"
release_branch_tag="release-${major_minor_tag}" # e.g) release-v1.7
tags="${tags} ${release_branch_tag}"
commit_hash_tag=${GITHUB_SHA::8}
tags="${tags} ${commit_hash_tag}"
tags="${tags} ${major_minor_tag}"
tags="${tags} latest"
elif [[ "${{ github.event_name }}" = "pull_request" || "${{ github.event_name }}" = "pull_request_target" ]]; then
# The following is the priority of tags:
# pr-xxx tag (PR build tag) -> release/vx.x tag (release branch tag) or nightly tag
# pr-xxx tag (PR build tag) -> release-vx.x tag (release branch tag) or nightly tag
pr_num=$(cat $GITHUB_EVENT_PATH | jq -r ".number")
tags="pr-${pr_num}"
# For pull request to the release branch, use the release branch latest tag as the default tag (release/vx.x).
# For pull request to the release branch, use the release branch latest tag as the default tag (release-vx.x).
# This is only set if the event that triggers the workflow execution is pull_request or pull_request_target.
if [[ "$GITHUB_BASE_REF" =~ ^release/v([0-9]+)\.([0-9]+)$ ]]; then
tags="${tags} $(echo "$GITHUB_BASE_REF")"
release_branch_tag="$(echo "$GITHUB_BASE_REF" | sed 's:/:-:g')"
tags="${tags} ${release_branch_tag}"
else
# Currently, it is assumed to be nightly.
# However, further conditions will be added in the future if they cause inconvenience.
Expand All @@ -81,18 +85,18 @@ runs:
elif [[ "$GITHUB_REF" =~ ^refs/heads/release/v([0-9]+)\.([0-9]+)$ ]]; then
# The following is the priority of tags:
# release/vx.x tag (release branch build tag) -> commit hash tag -> nightly tag
release_branch_tag=$(echo $GITHUB_REF | sed -e 's:^refs/heads/::') # e.g) release/v1.7
# release-vx.x tag (release branch build tag) -> commit hash tag
release_branch_tag="$(echo $GITHUB_REF | sed -e 's:^refs/heads/release/:release-:')" # e.g) release-v1.7
tags="${release_branch_tag}"
commit_hash_tag=${GITHUB_SHA::8}
tags="${tags} ${commit_hash_tag}"
else
tag_prefix="unknown/${{ github.event_name }}"
tag_prefix="unknown-${{ github.event_name }}"
if [[ "$GITHUB_BASE_REF" != "" ]]; then
tags="${tag_prefix}/${GITHUB_BASE_REF}"
tags="${tag_prefix}-${GITHUB_BASE_REF}"
else
tags="${tag_prefix}/${GITHUB_SHA::8}"
tags="${tag_prefix}-${GITHUB_SHA::8}"
fi
fi
primary_tag=$(echo ${tags} | awk '{print $1}')
Expand Down
1 change: 0 additions & 1 deletion .github/actions/docker-build/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ runs:
env:
IMAGE_NAME: ${{ steps.image_name.outputs.IMAGE_NAME }}
ALTER_IMAGE_NAME: ${{ steps.image_name.outputs.ALTER_IMAGE_NAME }}
PRIMARY_TAG: ${{ steps.determine_tag_name.outputs.PRIMARY_TAG }}
SECONDARY_TAGS: ${{ steps.determine_tag_name.outputs.SECONDARY_TAGS }}
- name: Build and Push
shell: bash
Expand Down

0 comments on commit 8a77a5d

Please sign in to comment.