Skip to content

Commit ed72723

Browse files
committed
Add tag job & skip logic
1 parent 2ebce6e commit ed72723

File tree

1 file changed

+50
-4
lines changed

1 file changed

+50
-4
lines changed

.github/workflows/release.yml

Lines changed: 50 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,16 @@ on:
1111
required: false
1212
default: false
1313
type: boolean
14+
goreleaser_args:
15+
description: 'Additional GoReleaser args'
16+
required: false
17+
default: ''
18+
type: string
19+
skip_jobs:
20+
description: 'Comma-separated list of jobs to skip (e.g. tag,build-docker,generate-assertion-doc)'
21+
required: false
22+
default: ''
23+
type: string
1424

1525
env:
1626
DOCKER_PLATFORMS: "linux/arm/v5,linux/arm/v6,linux/arm/v7,linux/arm64,linux/amd64,linux/ppc64le,linux/s390x,linux/mips64le,linux/386,linux/riscv64"
@@ -41,7 +51,42 @@ jobs:
4151
id: vars
4252
run: echo "tag=${{ github.event.inputs.version }}" >> $GITHUB_OUTPUT
4353

54+
tag:
55+
if: ${{ !contains(inputs.skip_jobs, 'tag') }}
56+
name: Create Tag for release
57+
runs-on: ubuntu-24.04
58+
needs: [variables]
59+
permissions:
60+
contents: write
61+
steps:
62+
- name: Checkout Repository
63+
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
64+
with:
65+
fetch-depth: 0
66+
67+
- name: Create new release Tag
68+
run: |
69+
git config --global user.email "[email protected]"
70+
git config --global user.name "NGINX Kubernetes Team"
71+
tag="v${{ needs.variables.outputs.tag }}"
72+
if ! git rev-parse --verify refs/tags/${tag} 2>/dev/null; then
73+
echo "Adding tag ${tag}."
74+
git tag -a ${tag} -m "Version ${tag#v*}"
75+
echo "Pushing tag ${tag} to main branch"
76+
if ! ${{ inputs.dry_run }}; then
77+
git push origin "${tag}"
78+
else
79+
echo "DRY RUN not making any changes"
80+
git push --dry-run origin "${tag}"
81+
fi
82+
else
83+
echo "Warning: Tag ${tag} already exists. Not making any changes"
84+
fi
85+
env:
86+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
87+
4488
build-docker:
89+
if: ${{ !contains(inputs.skip_jobs, 'build-docker') }}
4590
name: Build Docker Image
4691
runs-on: ubuntu-24.04-amd64
4792
permissions:
@@ -54,6 +99,7 @@ jobs:
5499
GOPROXY: ${{ secrets.ARTIFACTORY_ENDPOINT }}
55100
outputs:
56101
binaries: ${{ steps.prom_binaries.outputs.json }}
102+
needs: [variables]
57103
services:
58104
registry:
59105
image: registry:3
@@ -130,7 +176,7 @@ jobs:
130176
name=quay.io/nginx/nginx-prometheus-exporter,enable=true
131177
name=localhost:5000/nginx/nginx-prometheus-exporter
132178
tags: |
133-
type=raw,value=${{ github.event.inputs.version }}
179+
type=raw,value=${{ needs.variables.outputs.tag }}
134180
labels: |
135181
org.opencontainers.image.vendor=NGINX Inc <[email protected]>
136182
env:
@@ -170,7 +216,7 @@ jobs:
170216
uses: goreleaser/goreleaser-action@e435ccd777264be153ace6237001ef4d979d3a7a # v6.4.0
171217
with:
172218
version: v2.12.5 # renovate: datasource=github-tags depName=goreleaser/goreleaser
173-
args: ${{ github.event.inputs.dry_run && 'build --snapshot' || 'release' }} --clean
219+
args: ${{ github.event.inputs.dry_run && 'build --snapshot' || 'release' }} --clean ${{ github.event.inputs.goreleaser_args }}
174220
env:
175221
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
176222
NGINX_GITHUB_TOKEN: ${{ secrets.NGINX_PAT }}
@@ -225,7 +271,7 @@ jobs:
225271
sarif_file: ${{ steps.scan.outputs.sarif }}
226272

227273
generate-assertion-doc:
228-
if: ${{ github.event_name != 'pull_request' }}
274+
if: ${{ !contains(inputs.skip_jobs, 'generate-assertion-doc') }}
229275
name: Assertion Doc ${{ matrix.prometheus.arch }}
230276
needs: [build-docker, variables]
231277
runs-on: ubuntu-24.04-amd64
@@ -271,7 +317,7 @@ jobs:
271317
- name: List packages in Go binary
272318
id: godeps
273319
env:
274-
GOPROXY: ${{ needs.variables.outputs.go_proxy }}
320+
GOPROXY: ${{ secrets.ARTIFACTORY_ENDPOINT }}
275321
run: |
276322
go version -m ${{ matrix.prometheus.path }} > go_version_out_${{ github.run_id }}_${{ github.run_number }}.txt
277323
echo "go_version_out=$(find -type f -name "go_version_out*.txt" | head -n 1)" >> $GITHUB_OUTPUT

0 commit comments

Comments
 (0)