From 48bb228d6fc512eebcca1a700bd793b8fe6183b1 Mon Sep 17 00:00:00 2001 From: Aaron Croissette Date: Fri, 29 Mar 2024 21:00:59 -0400 Subject: [PATCH] feat: add calver, update submodule, let build wait for tagging --- .github/template/calver | 2 +- .github/workflows/build.yaml | 49 ++++++++++++++++++++++++++++++++++- .github/workflows/calver.yaml | 21 +++++++++++++++ 3 files changed, 70 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/calver.yaml diff --git a/.github/template/calver b/.github/template/calver index 5e276d2..42f6914 160000 --- a/.github/template/calver +++ b/.github/template/calver @@ -1 +1 @@ -Subproject commit 5e276d2d02c28305d9c60f70882583d5d85a3e0b +Subproject commit 42f6914b0b395ab64d69f415d05621e7b1d9268e diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index e592359..41ad1aa 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -27,6 +27,14 @@ jobs: with: string: ${{ env.TAG }} + - name: Wait for tagging to succeed + uses: lewagon/wait-on-check-action@v1.3.1 + with: + ref: ${{ github.ref }} + check-name: 'Tag revision' + repo-token: ${{ secrets.GITHUB_TOKEN }} + wait-interval: 10 + - name: Checkout Code uses: actions/checkout@v3 with: @@ -63,13 +71,52 @@ jobs: type=ref,event=tag,priority=300 type=raw,priority=150,value=latest,enable={{is_default_branch}} + # Retrieve all repository tags from the GitHub API using undocumented API call to get all tags + # https://github.com/actions/github-script + - name: Get all tags + id: all-tags + uses: actions/github-script@v6 + with: + script: | + return github.rest.repos.listTags({ + owner: context.repo.owner, + repo: context.repo.repo, + per_page: 100 + }) + + # Prepare JSON output for Unix command line + # https://github.com/mad9000/actions-find-and-replace-string + - name: Format jq result + id: formatted-jq + uses: mad9000/actions-find-and-replace-string@2 + with: + source: ${{ steps.all-tags.outputs.result }} + find: "'" + replace: "\\'" + + # Parse Github API output and search for tags only matching the current commit SHA + - name: Search all tags for commit + id: tag-results + run: | + tags=$( echo '${{ steps.formatted-jq.outputs.value }}' | jq -r ".data | .[] | select( .commit.sha == \"${{ github.sha }}\" ) | .name" | tr '\n' ' ' ) + echo "tags=${tags}" >> $GITHUB_OUTPUT + + # Merge the tag lists from docker/metadata-action and GitHub API + - name: Build tag list + id: tag-list + run: | + echo ::set-output name=tags::"$( + echo -n "${{ steps.meta.outputs.tags }}" | tr '\n' ',' + for r in `echo "${{ steps.tag-results.outputs.tags }}" | tr '\n' ' '`; do echo -n ,${{ steps.registry.outputs.lowercase }}${{ steps.image.outputs.lowercase }}:$r | tr '[:upper:]' '[:lower:]'; done + )" + - name: Build Image uses: docker/build-push-action@v4 with: context: . builder: ${{ steps.buildx.outputs.name }} push: true - tags: ${{ steps.meta.outputs.tags }} + tags: ${{ steps.tag-list.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} build-args: | BUILDTIME=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.created'] }} diff --git a/.github/workflows/calver.yaml b/.github/workflows/calver.yaml new file mode 100644 index 0000000..82abdce --- /dev/null +++ b/.github/workflows/calver.yaml @@ -0,0 +1,21 @@ +name: CalVer Tagging +on: + workflow_dispatch: + inputs: + variant: + required: true + description: Variant tag to pass to CalVer + type: string + push: + branches: + - "**" + tags: + - "!**" +concurrency: tag-scripts +jobs: + apply: + runs-on: ubuntu-latest + name: Tag revision + steps: + - name: Version + uses: acrois/calver@trunk