From 705d32bf7207f48d11ed6524fd491ec955f5db4e Mon Sep 17 00:00:00 2001 From: martin <74269598+martabal@users.noreply.github.com> Date: Tue, 12 Dec 2023 23:20:46 +0100 Subject: [PATCH] feat: Release images on git tag (#23) * feat: git tag * pr feedback * pr feedback * use schedule for docker metadata * remove tag event * pr feedback * fix: workflow name * fix: check if tag exists * pr feedback * pr feedback * pr feedback * feat: fail if git tag exists * update step name Co-authored-by: Jason Rasmussen * pr feedback --------- Co-authored-by: Jason Rasmussen --- .github/workflows/docker.yml | 20 ++------------------ .github/workflows/tag.yml | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 18 deletions(-) create mode 100644 .github/workflows/tag.yml diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 6bac075..2d16739 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -2,17 +2,11 @@ name: Build and Push Docker Images on: push: + tags: + - "*" branches: [main] pull_request: branches: [main] - schedule: - - cron: "0 11 * * 4" - workflow_dispatch: - inputs: - pushDateTag: - description: 'Push datestamp (production) tag' - type: boolean - required: false concurrency: group: ${{ github.workflow }}-${{ github.ref }} @@ -62,16 +56,6 @@ jobs: latest=false images: | name=ghcr.io/${{ github.repository_owner }}/${{ matrix.image }}-${{ matrix.target }} - tags: | - # Tag scheduled runs with date - type=schedule,pattern={{date 'YYYYMMDD'}} - type=raw,value={{date 'YYYYMMDD'}},enable=${{ inputs.pushDateTag || false }} - # Tag with branch name - type=ref,event=branch - # Tag with pr-number - type=ref,event=pr - # Tag with git tag on release - type=ref,event=tag - name: Build and push image uses: docker/build-push-action@v5.1.0 diff --git a/.github/workflows/tag.yml b/.github/workflows/tag.yml new file mode 100644 index 0000000..65506ef --- /dev/null +++ b/.github/workflows/tag.yml @@ -0,0 +1,35 @@ +name: Git tag + +on: + workflow_dispatch: + schedule: + - cron: "0 11 * * 4" + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +jobs: + set_tag: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4 + with: + ref: "main" + fetch-depth: 0 + token: ${{secrets.PAT}} + + - name: Create and push new tag + run: | + tag=$(date +'%Y%m%d') + git config --global user.name 'GitHub Actions' + git config --global user.email 'github-actions@users.noreply.github.com' + + if git tag -l $tag; then + echo "Tag $tag already exists." + exit 1 + else + git tag $tag + git push origin $tag + fi