Skip to content

Commit bf34e2f

Browse files
Push release build to registry and create draft release. (#146)
Creates a draft github release on a release branch and pushes the docker image to github container registry on a release tag. Co-authored-by: Pamme Crandall <p.crandall@f5.com>
1 parent 159db84 commit bf34e2f

File tree

3 files changed

+178
-5
lines changed

3 files changed

+178
-5
lines changed

.github/release.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
changelog:
2+
exclude:
3+
labels:
4+
- skip-changelog
5+
categories:
6+
- title: 🚀 Features
7+
labels:
8+
- enhancement
9+
- title: 💣 Breaking Changes
10+
labels:
11+
- change
12+
- title: 🐛 Bug Fixes
13+
labels:
14+
- bug
15+
- title: 📝 Documentation
16+
labels:
17+
- documentation
18+
- title: 🧪 Tests
19+
labels:
20+
- tests
21+
- title: 🔨 Maintenance
22+
labels:
23+
- chore
24+
- title: ⬆️ Dependencies
25+
labels:
26+
- dependencies

.github/workflows/ci.yml

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@ name: Continuous Integration
33
on:
44
push:
55
branches:
6-
- 'main'
6+
- main
7+
- release-*
78
tags:
8-
- 'v[0-9]+.[0-9]+.[0-9]+'
9+
- 'v[0-9]+.[0-9]+.[0-9]+*'
910
paths-ignore:
1011
- '**.md'
1112
pull_request:
@@ -119,16 +120,37 @@ jobs:
119120
key: nginx-kubernetes-gateway-${{ github.run_id }}-${{ github.run_number }}
120121
- name: Docker Buildx
121122
uses: docker/setup-buildx-action@v2
123+
- name: Login to GitHub Container Registry
124+
uses: docker/login-action@v2
125+
if: ${{ startsWith(github.ref, 'refs/tags') }}
126+
with:
127+
registry: ghcr.io
128+
username: ${{ github.repository_owner }}
129+
password: ${{ secrets.GITHUB_TOKEN }}
130+
- name: Docker meta
131+
id: meta
132+
uses: docker/metadata-action@v4
133+
with:
134+
images: |
135+
name=ghcr.io/nginxinc/nginx-kubernetes-gateway
136+
tags: |
137+
type=semver,pattern={{version}}
138+
type=edge
139+
type=ref,event=pr
140+
type=ref,event=branch,enable=${{ startsWith(github.ref, 'refs/heads/release') }}
141+
flavor: |
142+
latest=true
122143
- name: Build Image Debian
123144
uses: docker/build-push-action@v3
124145
with:
125146
file: build/Dockerfile
126147
context: '.'
127148
target: local
128-
load: true
149+
tags: ${{ steps.meta.outputs.tags }}
150+
load: ${{ !startsWith(github.ref, 'refs/tags') }}
151+
push: ${{ startsWith(github.ref, 'refs/tags') }}
129152
cache-from: type=gha
130153
cache-to: type=gha,mode=max
131-
tags: nginx/nginx-kubernetes-gateway:${{ needs.vars.outputs.sha }}
132154
build-args: |
133155
VERSION=${{ needs.vars.outputs.version }}
134156
GIT_COMMIT=${{ needs.vars.outputs.sha }}
@@ -137,7 +159,7 @@ jobs:
137159
uses: aquasecurity/trivy-action@0.2.3
138160
continue-on-error: true
139161
with:
140-
image-ref: nginx/nginx-kubernetes-gateway:${{ needs.vars.outputs.sha }}
162+
image-ref: ghcr.io/nginxinc/nginx-kubernetes-gateway:${{ steps.meta.outputs.version }}
141163
format: 'template'
142164
template: '@/contrib/sarif.tpl'
143165
output: 'trivy-results-nginx-kubernetes-gateway.sarif'

.github/workflows/release.yaml

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
name: Create Draft Release
2+
3+
on:
4+
push:
5+
branches:
6+
- release-*
7+
workflow_dispatch:
8+
inputs:
9+
tagFrom:
10+
description: The tag to create the release from.
11+
required: true
12+
type: string
13+
tagTo:
14+
description: The tag to create the release to.
15+
required: true
16+
type: string
17+
branch:
18+
description: The branch where the release will be created.
19+
required: true
20+
type: string
21+
22+
jobs:
23+
24+
binary:
25+
name: Create Draft Release
26+
runs-on: ubuntu-20.04
27+
steps:
28+
- uses: actions/setup-node@v3
29+
- run: npm install semver
30+
- uses: actions/github-script@v6
31+
continue-on-error: true
32+
with:
33+
script: |
34+
const semver = require('semver');
35+
const ref = context.ref.split("/")[2]
36+
37+
const releases = (await github.rest.repos.listReleases({
38+
owner: context.payload.repository.owner.login,
39+
repo: context.payload.repository.name,
40+
per_page: 100,
41+
})).data
42+
43+
let latest_release
44+
const latest_release_current_branch = releases.find(release => !release.draft && release.tag_name.startsWith("v" + ref.split("-")[1]))
45+
46+
if (latest_release_current_branch === undefined){
47+
latest_release = (await github.rest.repos.getLatestRelease({
48+
owner: context.payload.repository.owner.login,
49+
repo: context.payload.repository.name,
50+
})).data.tag_name
51+
} else {
52+
latest_release = latest_release_current_branch.tag_name
53+
}
54+
55+
let tagFrom, tagTo, branch
56+
if (context.eventName === 'workflow_dispatch'){
57+
console.log(`Dispatch run with inputs: ${JSON.stringify(context.payload.inputs)}`)
58+
;({ tagFrom, tagTo, branch } = context.payload.inputs)
59+
} else {
60+
;({ tagFrom, tagTo, branch } = {
61+
tagFrom: latest_release,
62+
tagTo: 'next',
63+
branch: ref,
64+
})
65+
console.log(`Push run with: { tagFrom: ${tagFrom}, tagTo: ${tagTo}, branch: ${branch} }`)
66+
}
67+
console.log(`The latest release was ${tagFrom}`)
68+
69+
let version = tagTo.replace('v', '')
70+
if (version === 'next'){
71+
const temp_notes = (await github.rest.repos.generateReleaseNotes({
72+
owner: context.payload.repository.owner.login,
73+
repo: context.payload.repository.name,
74+
tag_name: tagTo,
75+
previous_tag_name: tagFrom,
76+
target_commitish: branch,
77+
})).data.body
78+
79+
let level
80+
temp_notes.includes("### 🚀 Features") ? level = 'minor' : level = 'patch'
81+
temp_notes.includes("### 💣 Breaking Changes") ? level = 'major' : level = level
82+
version = semver.inc(tagFrom, level)
83+
console.log(`The level of the release is ${level}`)
84+
}
85+
const draft = releases.find((r) => r.draft && r.tag_name === "v"+version)
86+
const draft_found = !(draft === undefined)
87+
88+
console.log(`The next version is v${version}`)
89+
90+
const release_notes = (await github.rest.repos.generateReleaseNotes({
91+
owner: context.payload.repository.owner.login,
92+
repo: context.payload.repository.name,
93+
tag_name: 'v' + version,
94+
previous_tag_name: tagFrom,
95+
target_commitish: branch,
96+
}))
97+
98+
let release
99+
if (draft_found){
100+
console.log("Draft found")
101+
release = (await github.rest.repos.updateRelease({
102+
owner: context.payload.repository.owner.login,
103+
repo: context.payload.repository.name,
104+
release_id: draft.id,
105+
tag_name: 'v' + version,
106+
target_commitish: branch,
107+
name: 'v' + version,
108+
body: release_notes.data.body,
109+
draft: true,
110+
}))
111+
} else {
112+
console.log("Draft not found")
113+
release = (await github.rest.repos.createRelease({
114+
owner: context.payload.repository.owner.login,
115+
repo: context.payload.repository.name,
116+
tag_name: 'v' + version,
117+
target_commitish: ref,
118+
name: 'v' + version,
119+
body: release_notes.data.body,
120+
draft: true,
121+
}))
122+
}
123+
124+
console.log(`Release created: ${release.data.html_url}`)
125+
console.log(`Release notes: ${release_notes.data.body}`)

0 commit comments

Comments
 (0)