From 63da8b3ae21b4ebe9cc2de2f3682f6b8241038fb Mon Sep 17 00:00:00 2001 From: Ben Mangold <1518509+benmangold@users.noreply.github.com> Date: Sat, 18 Sep 2021 15:53:22 -0400 Subject: [PATCH] Consolidate tag builds and rebuilds to one workflow. (#2) --- .github/workflows/build-tags.yaml | 69 +++++++++++++++++++++++++++++++ .github/workflows/cron.yaml | 58 -------------------------- .github/workflows/tag.yaml | 30 -------------- 3 files changed, 69 insertions(+), 88 deletions(-) create mode 100644 .github/workflows/build-tags.yaml delete mode 100644 .github/workflows/cron.yaml delete mode 100644 .github/workflows/tag.yaml diff --git a/.github/workflows/build-tags.yaml b/.github/workflows/build-tags.yaml new file mode 100644 index 0000000..d9af9b4 --- /dev/null +++ b/.github/workflows/build-tags.yaml @@ -0,0 +1,69 @@ +name: build-tags + +on: + # build when a new tag is created + push: + tags: + - 'v*.*.*' + # rebuild tags on a cron + schedule: + # * is a special character in YAML so you have to quote this string + - cron: '0 * * * *' + +jobs: + + provide-tags: + + runs-on: ubuntu-latest + + steps: + # checkout repo with all tags + - uses: actions/checkout@v2 + with: + fetch-depth: 0 + + # set matrix output to all git tags listed in a JSON-parsable array + - id: set-matrix + run: echo "::set-output name=matrix::$( jq -cRs 'split("\n")[:-1]' <<< $(git tag -l) )" + + outputs: + matrix: ${{ steps.set-matrix.outputs.matrix }} + + rebuild-tags: + + needs: provide-tags + + runs-on: ubuntu-latest + + env: + DOCKER_HUB_ACCOUNT: bmngld + + # run a dynamic matrix of builds, rebuilding and republishing provided tags + strategy: + matrix: + tag: ${{ fromJson(needs.provide-tags.outputs.matrix) }} + + steps: + + - uses: actions/checkout@v2 + with: + ref: ${{ matrix.tag }} + + - run: make ci + env: + SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }} + + - id: set-docker-hub + run: echo "::set-output name=docker-hub::$( echo $DOCKER_HUB_ACCOUNT )" + + - id: set-repo-name + run: echo "::set-output name=repo-name::$( basename `git rev-parse --show-toplevel` )" + + - id: set-docker-tag + run: echo "::set-output name=docker-tag::$( echo ${{ steps.set-docker-hub.outputs.docker-hub }}/${{ steps.set-repo-name.outputs.repo-name }}:${{ matrix.tag }} )" + + - run: "docker tag test ${{ steps.set-docker-tag.outputs.docker-tag }}" + + - run: "echo ${{ secrets.DOCKER_HUB_TOKEN }} | docker login --username ${{ steps.set-docker-hub.outputs.docker-hub }} --password-stdin" + + - run: "docker push ${{ steps.set-docker-tag.outputs.docker-tag }}" diff --git a/.github/workflows/cron.yaml b/.github/workflows/cron.yaml deleted file mode 100644 index 4cfb03f..0000000 --- a/.github/workflows/cron.yaml +++ /dev/null @@ -1,58 +0,0 @@ -name: cron - -on: - schedule: - # * is a special character in YAML so you have to quote this string - - cron: '0 * * * *' - -jobs: - - provide-tags: - - runs-on: ubuntu-latest - - steps: - # checkout repo with all tags - - uses: actions/checkout@v2 - with: - fetch-depth: 0 - - # set matrix output to all git tags listed in a JSON-parsable array - - id: set-matrix - run: echo "::set-output name=matrix::$( jq -cRs 'split("\n")[:-1]' <<< $(git tag -l) )" - - outputs: - matrix: ${{ steps.set-matrix.outputs.matrix }} - - - rebuild-tags: - - needs: provide-tags - - runs-on: ubuntu-latest - - env: - DOCKER_HUB_ACCOUNT: bmngld - - strategy: - matrix: - tag: ${{fromJson(needs.provide-tags.outputs.matrix)}} - - steps: - - - uses: actions/checkout@v2 - with: - ref: ${{ matrix.tag }} - - - id: set-reponame - run: echo "::set-output name=reponame::$( basename `git rev-parse --show-toplevel` )" - - - run: make ci - env: - SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }} - - - run: docker tag test $DOCKER_HUB_ACCOUNT/${{ steps.set-reponame.outputs.reponame }}:${{ matrix.tag }} - - - run: echo ${{ secrets.DOCKER_HUB_TOKEN }} | docker login --username $DOCKER_HUB_ACCOUNT --password-stdin - - - run: docker push $DOCKER_HUB_ACCOUNT/${{ steps.set-reponame.outputs.reponame }}:${{ matrix.tag }} diff --git a/.github/workflows/tag.yaml b/.github/workflows/tag.yaml deleted file mode 100644 index 7c370ea..0000000 --- a/.github/workflows/tag.yaml +++ /dev/null @@ -1,30 +0,0 @@ -name: tag - -on: - push: - tags: - - 'v*.*.*' - -jobs: - tag-release: - runs-on: ubuntu-latest - - env: - DOCKER_HUB_ACCOUNT: bmngld - - steps: - - uses: actions/checkout@v2 - - - name: Set current tag as var - id: vars - run: echo ::set-output name=tag::${GITHUB_REF#refs/*/} - - - run: make ci - env: - SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }} - - - run: docker tag test $DOCKER_HUB_ACCOUNT/${{ github.event.repository.name }}:${{ steps.vars.outputs.tag }} - - - run: echo ${{ secrets.DOCKER_HUB_TOKEN }} | docker login --username $DOCKER_HUB_ACCOUNT --password-stdin - - - run: docker push $DOCKER_HUB_ACCOUNT/${{ github.event.repository.name }}:${{ steps.vars.outputs.tag }}