Skip to content

Commit

Permalink
feat: Release images on git tag (#23)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>

* pr feedback

---------

Co-authored-by: Jason Rasmussen <[email protected]>
  • Loading branch information
martabal and jrasm91 authored Dec 12, 2023
1 parent 998b5d1 commit 705d32b
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 18 deletions.
20 changes: 2 additions & 18 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down Expand Up @@ -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/[email protected]
Expand Down
35 changes: 35 additions & 0 deletions .github/workflows/tag.yml
Original file line number Diff line number Diff line change
@@ -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 '[email protected]'
if git tag -l $tag; then
echo "Tag $tag already exists."
exit 1
else
git tag $tag
git push origin $tag
fi

0 comments on commit 705d32b

Please sign in to comment.