Skip to content

Commit

Permalink
🐛 try to fix tags for PRs
Browse files Browse the repository at this point in the history
Signed-off-by: Joe Runde <[email protected]>
  • Loading branch information
joerunde committed Feb 29, 2024
1 parent b7a45db commit d3e3241
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
8 changes: 5 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,15 +78,17 @@ jobs:
fi
echo "CACHE_TO=$CACHE_TO" >> $GITHUB_ENV
- name: "short sha"
run: echo "SHORT_SHA=${GITHUB_SHA::7}" >> $GITHUB_ENV
- name: "push tags"
run: echo "PUSH_TAGS=$(scripts/get_image_tags.sh ${QUAY_ORG})" >> $GITHUB_ENV

- name: ""

- name: "Build and push"
uses: docker/build-push-action@v5
with:
context: .
target: router-release
tags: ${{ env.QUAY_ORG }}:latest,${{ env.QUAY_ORG }}:${{ github.ref_name }},${{ env.QUAY_ORG }}:${{ env.SHORT_SHA }}
tags: ${{ env.PUSH_TAGS }}
cache-from: type=registry,ref=${{ env.CACHE_IMAGE }}
cache-to: ${{ env.CACHE_TO }}
push: ${{ github.event_name != 'pull_request' }}
22 changes: 16 additions & 6 deletions scripts/get_image_tags.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,36 @@

# Returns a space separated list of container image tags to be pushed to the
# registry
# If a repository is supplied as the first arg, (e.g. quay.io/foo/bar") then the tags will be fully qualified

tags_to_push=""

if [[ -n $1 ]]; then
repo_bit="${1}:"
else
repo_bit=""
fi

# if running locally, i.e. CI is unset
if [[ -z "${CI+x}" ]];
then
commit="$(git rev-parse --short HEAD)"
branch="$(git rev-parse --abbrev-ref HEAD)"

tags_to_push+="${commit}"
tags_to_push+=" ${branch}"
tags_to_push+=" ${branch}.${commit}"
tags_to_push+="${repo_bit}${commit}"
tags_to_push+=" ${repo_bit}${branch}"
tags_to_push+=" ${repo_bit}${branch}.${commit}"
else
# In CI, pull info from github env vars
commit="${GITHUB_SHA:0:7}"
build_ref="${GITHUB_REF_NAME}"

tags_to_push+="${commit}"
tags_to_push+=" ${build_ref}"
tags_to_push+=" ${build_ref}.${commit}"
tags_to_push+="${repo_bit}${commit}"
if [[ ! ${build_ref} =~ "merge" ]];
then
tags_to_push+=" ${repo_bit}${build_ref}"
tags_to_push+=" ${repo_bit}${build_ref}.${commit}"
fi
fi

echo "${tags_to_push}"

0 comments on commit d3e3241

Please sign in to comment.