Skip to content

Commit

Permalink
Skip build and push if image already exists on ICR (#27)
Browse files Browse the repository at this point in the history
* gh action trial

* adjusted if

* adjusted if

* if

* if

* added checks if image exist before build/publishing

* add conditional message

* adjusted step if

* added to github env

* gh env

* update skip build

* fails release if image exists
  • Loading branch information
oliver-z-luo authored Nov 27, 2023
1 parent 2dcd4fc commit 07f536d
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,27 @@ jobs:
image_scan_result_cos_api_token: ${{ secrets.CONTAINER_IMAGE_SCAN_RESULT_COS_API_KEY }}
fail_if_overdue: ${{ inputs.scan_fail_if_overdue }}

- name: Check image exist on ICR
id: check-image
run: |
IMAGE="${{ inputs.image }}:${{ github.ref_name }}"
if docker manifest inspect "$IMAGE" &> /dev/null ; then
echo IMAGE_EXISTS=true >> "$GITHUB_ENV"
echo "Image found in ICR: ${IMAGE}"
else
echo IMAGE_EXISTS=false >> "$GITHUB_ENV"
echo "Image not found in ICR: ${IMAGE}"
fi
- name: Fail if image already exists
run: |
if [ "$IMAGE_EXISTS" == "true" ]; then
echo "Image already exists. Failing the release."
exit 1
fi
env:
IMAGE_EXISTS: ${{ env.IMAGE_EXISTS }}

- name: Build and push
id: build-push
uses: docker/build-push-action@v5
Expand All @@ -216,6 +237,7 @@ jobs:
build-args: |-
SN_GITHUB_NPM_TOKEN=${{ secrets.NPM_TOKEN }}
SN_GITHUB_NPM_REGISTRY=https://npm.pkg.github.com
if: env.IMAGE_EXISTS == 'false'

- uses: sigstore/cosign-installer@main
if: ${{ inputs.push }}
Expand Down

0 comments on commit 07f536d

Please sign in to comment.