Skip to content

Commit 0df9811

Browse files
committed
ci: restrict CI trigger to semantic version tags
- remove non-semantic version tag pattern from GitHub Actions workflow - ensure builds only trigger on valid semantic versioning tags like v1.2.3 Signed-off-by: mingcheng <[email protected]>
1 parent 41a033c commit 0df9811

File tree

1 file changed

+31
-31
lines changed

1 file changed

+31
-31
lines changed

.github/workflows/ghcr.yml

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@ on:
44
push:
55
branches:
66
- main
7-
- develop
87
tags:
9-
- "v*.*.*" # Semantic versioning tags (v1.0.0, v1.2.3, etc.)
8+
- "v*.*.*" # Match version tags like v1.2.3
109
pull_request:
1110
branches:
1211
- main
@@ -46,6 +45,11 @@ jobs:
4645
username: ${{ github.actor }}
4746
password: ${{ secrets.GITHUB_TOKEN }}
4847

48+
- uses: benjlevesque/[email protected]
49+
id: short-sha
50+
with:
51+
length: 7
52+
4953
- name: Extract metadata (tags, labels) for Docker
5054
id: meta
5155
uses: docker/metadata-action@v5
@@ -64,6 +68,7 @@ jobs:
6468
type=sha,format=short
6569
# Tag latest only on main branch
6670
type=raw,value=latest,enable={{is_default_branch}}
71+
type=raw,value={{steps.short-sha.outputs.sha}},enable={{is_default_branch}}
6772
labels: |
6873
org.opencontainers.image.title=aigitcommit
6974
org.opencontainers.image.description=AI-powered Git commit message generator
@@ -76,7 +81,9 @@ jobs:
7681
context: .
7782
platforms: linux/amd64,linux/arm64
7883
push: ${{ github.event_name != 'pull_request' }}
79-
tags: ${{ steps.meta.outputs.tags }}
84+
tags: |
85+
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest
86+
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.short-sha.outputs.sha }}
8087
labels: ${{ steps.meta.outputs.labels }}
8188
cache-from: type=gha
8289
cache-to: type=gha,mode=max
@@ -85,33 +92,26 @@ jobs:
8592
VCS_REF=${{ github.sha }}
8693
VERSION=${{ steps.meta.outputs.version }}
8794
88-
- name: Generate artifact attestation
89-
if: github.event_name != 'pull_request'
90-
uses: actions/attest-build-provenance@v2
91-
with:
92-
subject-name: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
93-
subject-digest: ${{ steps.push.outputs.digest }}
94-
push-to-registry: true
95+
# - name: Generate artifact attestation
96+
# if: github.event_name != 'pull_request'
97+
# uses: actions/attest-build-provenance@v3
98+
# with:
99+
# subject-name: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
100+
# subject-digest: ${{ steps.push.outputs.digest }}
101+
# push-to-registry: false
95102

96-
- name: Generate SBOM
97-
if: github.event_name != 'pull_request'
98-
uses: anchore/sbom-action@v0
99-
with:
100-
image: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}@${{ steps.push.outputs.digest }}
101-
format: spdx-json
102-
output-file: sbom.spdx.json
103-
104-
- name: Upload SBOM as artifact
105-
if: github.event_name != 'pull_request'
106-
uses: actions/upload-artifact@v4
107-
with:
108-
name: sbom-${{ github.sha }}
109-
path: sbom.spdx.json
110-
retention-days: 90
103+
# - name: Generate SBOM
104+
# if: github.event_name != 'pull_request'
105+
# uses: anchore/[email protected]
106+
# with:
107+
# image: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}@${{ steps.push.outputs.digest }}
108+
# format: spdx-json
109+
# output-file: sbom.spdx.json
111110

112-
- name: Image digest
113-
if: github.event_name != 'pull_request'
114-
run: |
115-
echo "Image pushed successfully!"
116-
echo "Digest: ${{ steps.push.outputs.digest }}"
117-
echo "Tags: ${{ steps.meta.outputs.tags }}"
111+
# - name: Upload SBOM as artifact
112+
# if: github.event_name != 'pull_request'
113+
# uses: actions/upload-artifact@v4
114+
# with:
115+
# name: ${{ steps.short-sha.outputs.sha }}-sbom
116+
# path: sbom.spdx.json
117+
# retention-days: 90

0 commit comments

Comments
 (0)