1
- name : Docker
2
-
3
- # This workflow uses actions that are not certified by GitHub.
4
- # They are provided by a third-party and are governed by
5
- # separate terms of service, privacy policy, and support
6
- # documentation.
1
+ name : Docker Publish and Versioning
7
2
8
3
on :
9
- schedule :
10
- - cron : ' 27 21 * * *'
11
4
push :
12
- branches : [ "master" ]
13
- # Publish semver tags as releases.
14
- tags : [ 'v*.*.*' ]
5
+ branches :
6
+ - " master"
7
+ tags :
8
+ - ' v*.*.*'
15
9
pull_request :
16
- branches : [ "master" ]
10
+ branches :
11
+ - " master"
12
+ workflow_dispatch :
17
13
18
14
env :
19
- # Use docker.io for Docker Hub if empty
15
+ # Docker Hub registry URL (use docker.io for Docker Hub)
20
16
REGISTRY : docker.io
21
- # github.repository as <account>/<repo>
22
17
IMAGE_NAME : ${{ github.repository }}
23
18
24
-
25
19
jobs :
26
20
build :
27
-
28
21
runs-on : ubuntu-latest
29
22
permissions :
30
23
contents : read
31
24
packages : write
32
- # This is used to complete the identity challenge
33
- # with sigstore/fulcio when running outside of PRs.
34
25
id-token : write
35
-
36
26
steps :
37
27
- name : Checkout repository
38
28
uses : actions/checkout@v4
39
29
40
- # Install the cosign tool except on PR
41
- # https://github.com/sigstore/cosign-installer
30
+ - name : Set up Git versioning
31
+ id : version
32
+ run : |
33
+ # Set version based on commit message prefix (fix, feat, chore or improvement)
34
+ latest_tag=$(git describe --tags --abbrev=0 2>/dev/null || echo "v0.0.0")
35
+ commit_message=$(git log -1 --pretty=%B)
36
+ version_prefix=${latest_tag#v}
37
+ major=$(echo $version_prefix | cut -d'.' -f1)
38
+ minor=$(echo $version_prefix | cut -d'.' -f2)
39
+ patch=$(echo $version_prefix | cut -d'.' -f3)
40
+
41
+ if [[ "$commit_message" =~ ^feat\(.*\) ]]; then
42
+ # Bump major version, reset minor and patch
43
+ major=$((major + 1))
44
+ minor=0
45
+ patch=0
46
+ elif [[ "$commit_message" =~ ^fix\(.*\) ]]; then
47
+ # Bump patch version
48
+ patch=$((patch + 1))
49
+ elif [[ "$commit_message" =~ ^chore\(.*\) || "$commit_message" =~ ^improvement\(.*\) ]]; then
50
+ # Bump minor version, reset patch
51
+ minor=$((minor + 1))
52
+ patch=0
53
+ fi
54
+
55
+ new_version="v$major.$minor.$patch"
56
+ echo "new_version=$new_version" >> $GITHUB_ENV
57
+ echo "New Version: $new_version"
58
+
59
+ # Install cosign tool, only run if it's not a pull request
42
60
- name : Install cosign
43
61
if : github.event_name != 'pull_request'
44
- uses : sigstore/cosign-installer@59acb6260d9c0ba8f4a2f9d9b48431a222b68e20 # v3.5.0
62
+
45
63
with :
46
64
cosign-release : ' v2.2.4'
47
65
48
- # Set up BuildKit Docker container builder to be able to build
49
- # multi-platform images and export cache
50
- # https://github.com/docker/setup-buildx-action
66
+ # Set up Docker Buildx for multi-platform builds
51
67
- name : Set up Docker Buildx
52
- uses : docker/setup-buildx-action@f95db51fddba0c2d1ec667646a06c2ce06100226 # v3.0.0
68
+
53
69
54
- # Login against a Docker registry except on PR
55
- # https://github.com/docker/login-action
70
+ # Login to Docker Hub if not a pull request
56
71
- name : Login to Docker Hub
57
72
if : github.event_name != 'pull_request'
58
73
uses : docker/login-action@v3
@@ -61,18 +76,18 @@ jobs:
61
76
password : ${{ secrets.DOCKERHUB_TOKEN }}
62
77
63
78
# Extract metadata (tags, labels) for Docker
64
- # https://github.com/docker/metadata-action
65
79
- name : Extract Docker metadata
66
80
id : meta
67
- uses : docker/metadata-action@96383f45573cb7f253c731d3b3ab81c87ef81934 # v5.0.0
81
+
68
82
with :
69
83
images : ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
84
+ tags : |
85
+ ${{ env.new_version }}
70
86
71
- # Build and push Docker image with Buildx (don't push on PR)
72
- # https://github.com/docker/build-push-action
87
+ # Build and push Docker image, skip pushing on PRs
73
88
- name : Build and push Docker image
74
89
id : build-and-push
75
- uses : docker/build-push-action@0565240e2d4ab88bba5387d719585280857ece09 # v5.0.0
90
+
76
91
with :
77
92
context : .
78
93
push : ${{ github.event_name != 'pull_request' }}
@@ -81,17 +96,10 @@ jobs:
81
96
cache-from : type=gha
82
97
cache-to : type=gha,mode=max
83
98
84
- # Sign the resulting Docker image digest except on PRs.
85
- # This will only write to the public Rekor transparency log when the Docker
86
- # repository is public to avoid leaking data. If you would like to publish
87
- # transparency data even for private images, pass --force to cosign below.
88
- # https://github.com/sigstore/cosign
99
+ # Sign the resulting Docker image digest except on PRs
89
100
- name : Sign the published Docker image
90
101
if : ${{ github.event_name != 'pull_request' }}
91
102
env :
92
- # https://docs.github.com/en/actions/security-guides/security-hardening-for-github-actions#using-an-intermediate-environment-variable
93
103
TAGS : ${{ steps.meta.outputs.tags }}
94
104
DIGEST : ${{ steps.build-and-push.outputs.digest }}
95
- # This step uses the identity token to provision an ephemeral certificate
96
- # against the sigstore community Fulcio instance.
97
105
run : echo "${TAGS}" | xargs -I {} cosign sign --yes {}@${DIGEST}
0 commit comments