Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use docker buildx imagetools to check tag_fallback #18

Merged
merged 3 commits into from
May 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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