Skip to content

Commit 50fa6cf

Browse files
committed
fix(): new docker action
Signed-off-by: Md Imran <[email protected]>
1 parent 27ea034 commit 50fa6cf

File tree

1 file changed

+49
-41
lines changed

1 file changed

+49
-41
lines changed

.github/workflows/docker-publish.yml

+49-41
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,73 @@
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
72

83
on:
9-
schedule:
10-
- cron: '27 21 * * *'
114
push:
12-
branches: [ "master" ]
13-
# Publish semver tags as releases.
14-
tags: [ 'v*.*.*' ]
5+
branches:
6+
- "master"
7+
tags:
8+
- 'v*.*.*'
159
pull_request:
16-
branches: [ "master" ]
10+
branches:
11+
- "master"
12+
workflow_dispatch:
1713

1814
env:
19-
# Use docker.io for Docker Hub if empty
15+
# Docker Hub registry URL (use docker.io for Docker Hub)
2016
REGISTRY: docker.io
21-
# github.repository as <account>/<repo>
2217
IMAGE_NAME: ${{ github.repository }}
2318

24-
2519
jobs:
2620
build:
27-
2821
runs-on: ubuntu-latest
2922
permissions:
3023
contents: read
3124
packages: write
32-
# This is used to complete the identity challenge
33-
# with sigstore/fulcio when running outside of PRs.
3425
id-token: write
35-
3626
steps:
3727
- name: Checkout repository
3828
uses: actions/checkout@v4
3929

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
4260
- name: Install cosign
4361
if: github.event_name != 'pull_request'
44-
uses: sigstore/cosign-installer@59acb6260d9c0ba8f4a2f9d9b48431a222b68e20 #v3.5.0
62+
uses: sigstore/[email protected]
4563
with:
4664
cosign-release: 'v2.2.4'
4765

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
5167
- name: Set up Docker Buildx
52-
uses: docker/setup-buildx-action@f95db51fddba0c2d1ec667646a06c2ce06100226 # v3.0.0
68+
uses: docker/[email protected]
5369

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
5671
- name: Login to Docker Hub
5772
if: github.event_name != 'pull_request'
5873
uses: docker/login-action@v3
@@ -61,18 +76,18 @@ jobs:
6176
password: ${{ secrets.DOCKERHUB_TOKEN }}
6277

6378
# Extract metadata (tags, labels) for Docker
64-
# https://github.com/docker/metadata-action
6579
- name: Extract Docker metadata
6680
id: meta
67-
uses: docker/metadata-action@96383f45573cb7f253c731d3b3ab81c87ef81934 # v5.0.0
81+
uses: docker/[email protected]
6882
with:
6983
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
84+
tags: |
85+
${{ env.new_version }}
7086
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
7388
- name: Build and push Docker image
7489
id: build-and-push
75-
uses: docker/build-push-action@0565240e2d4ab88bba5387d719585280857ece09 # v5.0.0
90+
uses: docker/[email protected]
7691
with:
7792
context: .
7893
push: ${{ github.event_name != 'pull_request' }}
@@ -81,17 +96,10 @@ jobs:
8196
cache-from: type=gha
8297
cache-to: type=gha,mode=max
8398

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
89100
- name: Sign the published Docker image
90101
if: ${{ github.event_name != 'pull_request' }}
91102
env:
92-
# https://docs.github.com/en/actions/security-guides/security-hardening-for-github-actions#using-an-intermediate-environment-variable
93103
TAGS: ${{ steps.meta.outputs.tags }}
94104
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.
97105
run: echo "${TAGS}" | xargs -I {} cosign sign --yes {}@${DIGEST}

0 commit comments

Comments
 (0)