Skip to content

Commit bae43bc

Browse files
authored
Improve Release Workflow (#1173)
1 parent 3c38a4c commit bae43bc

File tree

1 file changed

+20
-10
lines changed

1 file changed

+20
-10
lines changed

.github/workflows/release.yml

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
name: Release NGINX Prometheus Exporter
2+
run-name: ${{ inputs.dry_run && '[DRY RUN] ' || '' }}Release NGINX Prometheus Exporter ${{ inputs.version }} from ${{ inputs.branch }} by @${{ github.actor }}
23

34
on:
45
workflow_dispatch:
@@ -11,6 +12,11 @@ on:
1112
required: false
1213
default: false
1314
type: boolean
15+
branch:
16+
description: 'Branch to release from (not normally needed)'
17+
required: false
18+
default: 'main'
19+
type: string
1420
goreleaser_args:
1521
description: 'Additional GoReleaser args'
1622
required: false
@@ -41,6 +47,8 @@ jobs:
4147
steps:
4248
- name: Checkout Repository
4349
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
50+
with:
51+
ref: ${{ inputs.branch }}
4452

4553
- name: Set up Go
4654
uses: actions/setup-go@44694675825211faa026b3c33043df3e48a5fa00 # v6.0.0
@@ -49,7 +57,7 @@ jobs:
4957

5058
- name: Get version
5159
id: vars
52-
run: echo "tag=${{ github.event.inputs.version }}" >> $GITHUB_OUTPUT
60+
run: echo "tag=${{ inputs.version }}" >> $GITHUB_OUTPUT
5361

5462
tag:
5563
if: ${{ !contains(inputs.skip_jobs, 'tag') }}
@@ -62,18 +70,19 @@ jobs:
6270
- name: Checkout Repository
6371
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
6472
with:
73+
ref: ${{ inputs.branch }}
6574
fetch-depth: 0
6675

6776
- name: Create new release Tag
6877
run: |
69-
git config --global user.email "kubernetes@nginx.com"
70-
git config --global user.name "NGINX Kubernetes Team"
78+
git config --global user.email "${{ github.actor_id }}+${{ github.actor }}@users.noreply.github.com"
79+
git config --global user.name "${{ github.actor }}"
7180
tag="v${{ needs.variables.outputs.tag }}"
7281
if ! git rev-parse --verify refs/tags/${tag} 2>/dev/null; then
7382
echo "Adding tag ${tag}."
7483
git tag -a ${tag} -m "Version ${tag#v*}"
7584
echo "Pushing tag ${tag} to main branch"
76-
if ! ${{ inputs.dry_run }}; then
85+
if ${{ !inputs.dry_run }}; then
7786
git push origin "${tag}"
7887
else
7988
echo "DRY RUN not making any changes"
@@ -99,7 +108,7 @@ jobs:
99108
GOPROXY: ${{ secrets.ARTIFACTORY_ENDPOINT }}
100109
outputs:
101110
binaries: ${{ steps.prom_binaries.outputs.json }}
102-
needs: [variables]
111+
needs: [variables, tag]
103112
services:
104113
registry:
105114
image: registry:3
@@ -109,6 +118,7 @@ jobs:
109118
- name: Checkout Repository
110119
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
111120
with:
121+
ref: ${{ inputs.branch }}
112122
fetch-depth: 0
113123

114124
- name: Setup Golang Environment
@@ -187,7 +197,7 @@ jobs:
187197
with:
188198
minor-label: "enhancement"
189199
major-label: "change"
190-
publish: ${{ !github.event.inputs.dry_run }}
200+
publish: ${{ !inputs.dry_run }}
191201
collapse-after: 30
192202
notes-footer: |
193203
## Upgrade
@@ -216,7 +226,7 @@ jobs:
216226
uses: goreleaser/goreleaser-action@e435ccd777264be153ace6237001ef4d979d3a7a # v6.4.0
217227
with:
218228
version: v2.12.5 # renovate: datasource=github-tags depName=goreleaser/goreleaser
219-
args: ${{ github.event.inputs.dry_run && 'build --snapshot' || 'release' }} --clean ${{ github.event.inputs.goreleaser_args }}
229+
args: ${{ inputs.dry_run && 'build --snapshot' || 'release' }} --clean ${{ inputs.goreleaser_args }}
220230
env:
221231
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
222232
NGINX_GITHUB_TOKEN: ${{ secrets.NGINX_PAT }}
@@ -248,7 +258,7 @@ jobs:
248258
tags: ${{ steps.meta.outputs.tags }}
249259
labels: ${{ steps.meta.outputs.labels }}
250260
annotations: ${{ steps.meta.outputs.annotations }}
251-
push: ${{ !github.event.inputs.dry_run }}
261+
push: ${{ !inputs.dry_run }}
252262
cache-from: type=gha,scope=exporter
253263
cache-to: type=gha,scope=exporter,mode=max
254264
no-cache: true
@@ -263,14 +273,14 @@ jobs:
263273
image: localhost:5000/nginx/nginx-prometheus-exporter:${{ steps.meta.outputs.version }}
264274
only-fixed: true
265275
add-cpes-if-none: true
266-
if: ${{ !github.event.inputs.dry_run }}
276+
if: ${{ !inputs.dry_run }}
267277

268278
- name: Upload scan result to GitHub Security tab
269279
uses: github/codeql-action/upload-sarif@64d10c13136e1c5bce3e5fbde8d4906eeaafc885 # v3.30.6
270280
continue-on-error: true
271281
with:
272282
sarif_file: ${{ steps.scan.outputs.sarif }}
273-
if: ${{ !github.event.inputs.dry_run }}
283+
if: ${{ !inputs.dry_run }}
274284

275285
- name: Clean up NETRC
276286
run: |

0 commit comments

Comments
 (0)