Skip to content

Commit

Permalink
Use docker buildx imagetools to check tag_fallback (#18)
Browse files Browse the repository at this point in the history
* Use docker buildx imagetools to check tag_fallback

* Rework build triggers

* Improve retag test
  • Loading branch information
DerekRoberts authored May 19, 2023
1 parent a9f54eb commit 0ba3a30
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
1 change: 0 additions & 1 deletion .github/workflows/pr-open.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
22 changes: 14 additions & 8 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 0ba3a30

Please sign in to comment.