diff --git a/.github/workflows/pr-open.yml b/.github/workflows/pr-open.yml index 1588df1..c424f0f 100644 --- a/.github/workflows/pr-open.yml +++ b/.github/workflows/pr-open.yml @@ -19,7 +19,6 @@ jobs: - uses: ./ with: package: backend - repository: bcgov/nr-quickstart-typescript tag: ${{ github.event.number }} tag_fallback: test token: ${{ secrets.GITHUB_TOKEN }} diff --git a/action.yml b/action.yml index 1a78c6f..f9747a5 100644 --- a/action.yml +++ b/action.yml @@ -78,22 +78,28 @@ runs: run: | # Check for builds - # Build if no tag_fallback, no triggers or using an override repository - if [ ! -z "${{ inputs.repository }}" ]||[ -z "${{ inputs.tag_fallback }}" ]||[ -z "${{ inputs.triggers }}" ]; then - echo "Build triggered based on inputs. Possible reasons:" - echo " a) repository override provided" - echo " b) tag_fallback or triggers not provided" + # Build if an override repository was provided + if [ "${{ inputs.repository }}" != "${{ github.repository }}" ]; then + echo "Build triggered on override repository" + echo "triggered=true" >> $GITHUB_OUTPUT + exit 0 + fi + + # Build if no tag_fallback or no triggers + if [ -z "${{ inputs.tag_fallback }}" ]||[ -z "${{ inputs.triggers }}" ]; then + echo "Build triggered with possible reasons:" + echo " a) tag_fallback provided" + echo " b) triggers not provided" echo "triggered=true" >> $GITHUB_OUTPUT exit 0 fi # Build if tag_fallback is no good (requires a valid container) - TOKEN=$(curl -s https://ghcr.io/token\?scope\="repository:${{ inputs.repository }}/${{ inputs.package }}:pull" | jq -r .token) - URL="https://ghcr.io/v2/${{ inputs.repository }}/${{ inputs.package }}/manifests/${{ inputs.tag_fallback }}" - if [ $(curl -ILso /dev/null -w "%{http_code}" -H "Authorization: Bearer ${TOKEN}" "${URL}") -ne 200 ] + if [ $(docker buildx imagetools inspect ghcr.io/${{ inputs.repository }}/${{ inputs.package }}:${{ inputs.tag_fallback }} > /dev/null) -ne 0 ] then # Output triggered=true for next steps echo "Build triggered. Fallback tag (tag_fallback) not usable." + echo "Manifest checked for: ghcr.io/${{ inputs.repository }}/${{ inputs.package }}:${{ inputs.tag_fallback }}" echo "triggered=true" >> $GITHUB_OUTPUT exit 0 fi