fix(ci): handle missing github ref (#13714)

This commit is contained in:
david-leifker 2025-06-08 01:14:19 -05:00 committed by GitHub
parent ab5b08e725
commit 289abb6463
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 31 additions and 16 deletions

View File

@ -1,6 +1,12 @@
#!/bin/bash #!/bin/bash
echo "GITHUB_REF: $GITHUB_REF" REF="${GITHUB_REF:-${GITHUB_REF_FALLBACK:-}}"
if [ -z "$REF" ]; then
echo "Error: No ref available from GITHUB_REF or fallback"
exit 1
fi
echo "GITHUB_REF: $REF"
echo "GITHUB_SHA: $GITHUB_SHA" echo "GITHUB_SHA: $GITHUB_SHA"
export MAIN_BRANCH="master" export MAIN_BRANCH="master"
@ -14,19 +20,19 @@ export SHORT_SHA=$(get_short_sha)
echo "SHORT_SHA: $SHORT_SHA" echo "SHORT_SHA: $SHORT_SHA"
function get_tag { function get_tag {
echo $(echo ${GITHUB_REF} | sed -e "s,refs/heads/${MAIN_BRANCH},${MAIN_BRANCH_TAG},g" -e 's,refs/tags/,,g' -e 's,refs/heads/,,g' -e 's,refs/heads/,,g' -e 's,refs/pull/\([0-9]*\).*,pr\1,g' -e 's,/,-,g') echo $(echo ${REF} | sed -e "s,refs/heads/${MAIN_BRANCH},${MAIN_BRANCH_TAG},g" -e 's,refs/tags/,,g' -e 's,refs/heads/,,g' -e 's,refs/heads/,,g' -e 's,refs/pull/\([0-9]*\).*,pr\1,g' -e 's,/,-,g')
} }
function get_tag_slim { function get_tag_slim {
echo $(echo ${GITHUB_REF} | sed -e "s,refs/heads/${MAIN_BRANCH},${MAIN_BRANCH_TAG}-slim,g" -e 's,refs/tags/\(.*\),\1-slim,g' -e 's,refs/heads/\(.*\),\1-slim,g' -e 's,refs/heads/\(.*\),\1-slim,g' -e 's,refs/pull/\([0-9]*\).*,pr\1-slim,g' -e 's,/,-,g') echo $(echo ${REF} | sed -e "s,refs/heads/${MAIN_BRANCH},${MAIN_BRANCH_TAG}-slim,g" -e 's,refs/tags/\(.*\),\1-slim,g' -e 's,refs/heads/\(.*\),\1-slim,g' -e 's,refs/heads/\(.*\),\1-slim,g' -e 's,refs/pull/\([0-9]*\).*,pr\1-slim,g' -e 's,/,-,g')
} }
function get_tag_full { function get_tag_full {
echo $(echo ${GITHUB_REF} | sed -e "s,refs/heads/${MAIN_BRANCH},${MAIN_BRANCH_TAG}-full,g" -e 's,refs/tags/\(.*\),\1-full,g' -e 's,refs/heads/\(.*\),\1-full,g' -e 's,refs/heads/\(.*\),\1-full,g' -e 's,refs/pull/\([0-9]*\).*,pr\1-full,g' -e 's,/,-,g') echo $(echo ${REF} | sed -e "s,refs/heads/${MAIN_BRANCH},${MAIN_BRANCH_TAG}-full,g" -e 's,refs/tags/\(.*\),\1-full,g' -e 's,refs/heads/\(.*\),\1-full,g' -e 's,refs/heads/\(.*\),\1-full,g' -e 's,refs/pull/\([0-9]*\).*,pr\1-full,g' -e 's,/,-,g')
} }
function get_python_docker_release_v() { function get_python_docker_release_v() {
echo "$(echo "${GITHUB_REF}" | \ echo "$(echo "${REF}" | \
sed -e "s,refs/heads/${MAIN_BRANCH},1\!0.0.0+docker.${SHORT_SHA},g" \ sed -e "s,refs/heads/${MAIN_BRANCH},1\!0.0.0+docker.${SHORT_SHA},g" \
-e 's,refs/heads/\(.*\),1!0.0.0+docker.\1,g' \ -e 's,refs/heads/\(.*\),1!0.0.0+docker.\1,g' \
-e 's,refs/heads/\(.*\),1!0.0.0+docker.\1,g' \ -e 's,refs/heads/\(.*\),1!0.0.0+docker.\1,g' \
@ -37,12 +43,12 @@ function get_python_docker_release_v() {
} }
# To run these, set TEST_DOCKER_HELPERS=1 and then copy the function + test cases into a bash shell. # To run these, set TEST_DOCKER_HELPERS=1 and then copy the function + test cases into a bash shell.
if [ ${TEST_DOCKER_HELPERS:-0} -eq 1 ]; then if [ ${TEST_DOCKER_HELPERS:-0} -eq 1 ]; then
GITHUB_REF="refs/pull/4788/merge" get_python_docker_release_v # '1!0.0.0+docker.pr4788' REF="refs/pull/4788/merge" get_python_docker_release_v # '1!0.0.0+docker.pr4788'
GITHUB_REF="refs/tags/v0.1.2-test" get_python_docker_release_v # '0.1.2' REF="refs/tags/v0.1.2-test" get_python_docker_release_v # '0.1.2'
GITHUB_REF="refs/tags/v0.1.2.1-test" get_python_docker_release_v # '0.1.2.1' REF="refs/tags/v0.1.2.1-test" get_python_docker_release_v # '0.1.2.1'
GITHUB_REF="refs/tags/v0.1.2rc1-test" get_python_docker_release_v # '0.1.2rc1' REF="refs/tags/v0.1.2rc1-test" get_python_docker_release_v # '0.1.2rc1'
GITHUB_REF="refs/heads/branch-name" get_python_docker_release_v # '1!0.0.0+docker.branch-name' REF="refs/heads/branch-name" get_python_docker_release_v # '1!0.0.0+docker.branch-name'
GITHUB_REF="refs/heads/releases/branch-name" get_python_docker_release_v # 1!0.0.0+docker.releases-branch-name' REF="refs/heads/releases/branch-name" get_python_docker_release_v # 1!0.0.0+docker.releases-branch-name'
GITHUB_REF="refs/tags/v0.1.2rc1" get_tag # '0.1.2rc1' GITHUB_REF="refs/tags/v0.1.2rc1" get_tag # '0.1.2rc1'
GITHUB_REF="refs/tags/v0.1.2rc1" get_tag_slim # '0.1.2rc1-slim' GITHUB_REF="refs/tags/v0.1.2rc1" get_tag_slim # '0.1.2rc1-slim'
@ -62,19 +68,19 @@ if [ ${TEST_DOCKER_HELPERS:-0} -eq 1 ]; then
fi fi
function get_unique_tag { function get_unique_tag {
echo $(echo ${GITHUB_REF} | sed -e "s,refs/heads/${MAIN_BRANCH},${SHORT_SHA},g" -e 's,refs/tags/,,g' -e "s,refs/heads/.*,${SHORT_SHA},g" -e 's,refs/pull/\([0-9]*\).*,pr\1,g') echo $(echo ${REF} | sed -e "s,refs/heads/${MAIN_BRANCH},${SHORT_SHA},g" -e 's,refs/tags/,,g' -e "s,refs/heads/.*,${SHORT_SHA},g" -e 's,refs/pull/\([0-9]*\).*,pr\1,g')
} }
function get_unique_tag_slim { function get_unique_tag_slim {
echo $(echo ${GITHUB_REF} | sed -e "s,refs/heads/${MAIN_BRANCH},${SHORT_SHA}-slim,g" -e 's,refs/tags/\(.*\),\1-slim,g' -e "s,refs/heads/.*,${SHORT_SHA}-slim,g" -e 's,refs/pull/\([0-9]*\).*,pr\1-slim,g') echo $(echo ${REF} | sed -e "s,refs/heads/${MAIN_BRANCH},${SHORT_SHA}-slim,g" -e 's,refs/tags/\(.*\),\1-slim,g' -e "s,refs/heads/.*,${SHORT_SHA}-slim,g" -e 's,refs/pull/\([0-9]*\).*,pr\1-slim,g')
} }
function get_unique_tag_full { function get_unique_tag_full {
echo $(echo ${GITHUB_REF} | sed -e "s,refs/heads/${MAIN_BRANCH},${SHORT_SHA}-full,g" -e 's,refs/tags/\(.*\),\1-full,g' -e "s,refs/heads/.*,${SHORT_SHA}-full,g" -e 's,refs/pull/\([0-9]*\).*,pr\1-full,g') echo $(echo ${REF} | sed -e "s,refs/heads/${MAIN_BRANCH},${SHORT_SHA}-full,g" -e 's,refs/tags/\(.*\),\1-full,g' -e "s,refs/heads/.*,${SHORT_SHA}-full,g" -e 's,refs/pull/\([0-9]*\).*,pr\1-full,g')
} }
function get_platforms_based_on_branch { function get_platforms_based_on_branch {
if [ "${{ github.event_name }}" == 'push' && "${{ github.ref }}" == "refs/heads/${MAIN_BRANCH}" ]; then if [ "${GITHUB_EVENT_NAME}" == "push" ] && [ "${REF}" == "refs/heads/${MAIN_BRANCH}" ]; then
echo "linux/amd64,linux/arm64" echo "linux/amd64,linux/arm64"
else else
echo "linux/amd64" echo "linux/amd64"
@ -90,6 +96,6 @@ function echo_tags {
echo "unique_slim_tag=$(get_unique_tag_slim)" echo "unique_slim_tag=$(get_unique_tag_slim)"
echo "unique_full_tag=$(get_unique_tag_full)" echo "unique_full_tag=$(get_unique_tag_full)"
echo "python_release_version=$(get_python_docker_release_v)" echo "python_release_version=$(get_python_docker_release_v)"
echo "branch_name=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}" echo "branch_name=${GITHUB_HEAD_REF:-${REF#refs/heads/}}"
echo "repository_name=${GITHUB_REPOSITORY#*/}" echo "repository_name=${GITHUB_REPOSITORY#*/}"
} }

View File

@ -28,6 +28,9 @@ jobs:
uses: acryldata/sane-checkout-action@v3 uses: acryldata/sane-checkout-action@v3
- name: Compute Tag - name: Compute Tag
id: tag id: tag
env:
GITHUB_REF_FALLBACK: ${{ github.ref }}
GITHUB_EVENT_NAME: ${{ github.event_name }}
run: | run: |
source .github/scripts/docker_helpers.sh source .github/scripts/docker_helpers.sh
echo "tag=$(get_tag)" >> $GITHUB_OUTPUT echo "tag=$(get_tag)" >> $GITHUB_OUTPUT

View File

@ -76,6 +76,9 @@ jobs:
uses: acryldata/sane-checkout-action@v3 uses: acryldata/sane-checkout-action@v3
- name: Compute Tag - name: Compute Tag
id: tag id: tag
env:
GITHUB_REF_FALLBACK: ${{ github.event_name == 'release' && format('refs/tags/{0}', github.event.release.tag_name) || github.ref}}
GITHUB_EVENT_NAME: ${{ github.event_name }}
run: | run: |
source .github/scripts/docker_helpers.sh source .github/scripts/docker_helpers.sh
{ {

View File

@ -39,6 +39,9 @@ jobs:
uses: acryldata/sane-checkout-action@v3 uses: acryldata/sane-checkout-action@v3
- name: Compute Tag - name: Compute Tag
id: tag id: tag
env:
GITHUB_REF_FALLBACK: ${{ github.ref }}
GITHUB_EVENT_NAME: ${{ github.event_name }}
run: | run: |
source .github/scripts/docker_helpers.sh source .github/scripts/docker_helpers.sh
TAG=$(echo ${GITHUB_REF} | sed -e 's,refs/tags/v,,g') TAG=$(echo ${GITHUB_REF} | sed -e 's,refs/tags/v,,g')