-
Notifications
You must be signed in to change notification settings - Fork 74
230 lines (215 loc) · 9.14 KB
/
release-branch.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
name: Release Branch
on:
workflow_dispatch:
inputs:
publishPackages:
description: 'Publish packages to up-ap.nginx.com'
required: true
type: boolean
default: false
createPullRequest:
description: 'Create pull request back into main'
required: true
type: boolean
default: false
uploadJWT:
description: 'Temporary JWT to publish packages to up-ap.nginx.com'
required: true
type: string
default: ''
workflow_call:
permissions:
contents: read
jobs:
update-draft:
permissions:
contents: write
pull-requests: write
name: Update Release
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # v4.1.4
with:
fetch-depth: 0
- uses: actions/setup-go@0c52d547c9bc32b1aa3301fd7a9cb496313a4491 # v5.0.0
with:
go-version-file: 'go.mod'
- uses: actions/setup-node@60edb5dd545a775178f52524783378180af0d1f8 # v4.0.2
- run: npm install [email protected]
- name: Create Draft Release
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
id: release
with:
script: |
const semver = require('semver');
const ref = context.ref.split("/")[2]
const version_number = ref.split("-")[1]
const version = "v"+version_number
console.log(`The release version is ${version}`)
const releases = (await github.rest.repos.listReleases({
owner: context.payload.repository.owner.login,
repo: context.payload.repository.name,
per_page: 100,
})).data
const latest_release = (await github.rest.repos.getLatestRelease({
owner: context.payload.repository.owner.login,
repo: context.payload.repository.name,
})).data.tag_name
console.log(`The latest release was ${latest_release}`)
if (latest_release === version) {
core.setFailed(`A published release already exists for ${latest_release}`)
} else {
const draft = releases.find((r) => r.draft && r.tag_name === version)
const draft_found = !(draft === undefined)
let release
if (draft_found){
console.log("Draft release already exists. Deleting current draft release and recreating it")
release = (await github.rest.repos.deleteRelease({
owner: context.payload.repository.owner.login,
repo: context.payload.repository.name,
release_id: draft.id,
}))
}
const release_notes = (await github.rest.repos.generateReleaseNotes({
owner: context.payload.repository.owner.login,
repo: context.payload.repository.name,
tag_name: version,
previous_tag_name: latest_release,
target_commitish: ref,
}))
const footer = `
## Resources
- Documentation -- https://github.com/nginx/agent#readme
`
release = (await github.rest.repos.createRelease({
owner: context.payload.repository.owner.login,
repo: context.payload.repository.name,
tag_name: version,
target_commitish: ref,
name: version,
body: release_notes.data.body + footer,
draft: true,
}))
console.log(`Release created: ${release.data.html_url}`)
console.log(`Release ID: ${release.data.id}`)
console.log(`Release notes: ${release_notes.data.body}`)
console.log(`Release Upload URL: ${release.data.upload_url}`)
return {
version: version_number,
release_id: release.data.id,
release_upload_url: release.data.upload_url,
}
}
- name: Set Environment Variables
run: |
echo "${{steps.release.outputs.result}}"
echo "VERSION=$(echo '${{steps.release.outputs.result}}' | jq -r '.version')" >> $GITHUB_ENV
echo "RELEASE_ID=$(echo '${{steps.release.outputs.result}}' | jq -r '.release_id')" >> $GITHUB_ENV
echo "RELEASE_UPLOAD_URL=$(echo '${{steps.release.outputs.result}}' | jq -r '.release_upload_url')" >> $GITHUB_ENV
- name: Setup build environment
run: |
sudo apt-get update
sudo apt-get install -y gpgv1 monkeysphere
go install github.com/goreleaser/nfpm/v2/cmd/[email protected]
- name: Generate Changelog
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
git clone https://github.com/spencerugbo/agent-changelog.git
cd ./agent-changelog/source
pip install -r requirements.txt
python agent2.py
- name: Push Changelog
run: |
mv agent-changelog/source/changelog.md ./site/content/
git config --global user.name 'github-actions'
git config --global user.email '41898282+github-actions[bot]@users.noreply.github.com'
git add ./site/content/changelog.md
git commit -m "Add generated changelog"
git push origin HEAD:${{ github.ref_name }}
- name: Tag release
run: |
git tag -a "v${{env.VERSION}}" -m "CI Autogenerated"
git tag -a "sdk/v${{env.VERSION}}" -m "CI Autogenerated"
- name: Push Tags
if: ${{ inputs.publishPackages == true }}
run: |
git push origin "v${{env.VERSION}}"
git push origin "sdk/v${{env.VERSION}}"
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@d70bba72b1f3fd22344832f00baa16ece964efeb # v3.3.0
- name: Build Docker Image
uses: docker/build-push-action@2cdde995de11925a030ce8070c3d77a52ffcf1c0 # v5.3.0
with:
file: scripts/packages/packager/Dockerfile
tags: build-signed-packager:1.0.0
context: '.'
push: false
load: true
no-cache: true
build-args: |
package_type=signed-package
- name: Build Packages
env:
INDIGO_GPG_AGENT: ${{ secrets.INDIGO_GPG_AGENT }}
NFPM_SIGNING_KEY_FILE: .key.asc
run: |
echo "$INDIGO_GPG_AGENT" | base64 --decode > .key.asc
make clean package
- name: Azure Login
uses: azure/login@6b2456866fc08b011acb422a92a4aa20e2c4de32 # v2.1.0
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}
- name: Azure Upload Release Packages
uses: azure/CLI@965c8d7571d2231a54e321ddd07f7b10317f34d9 # v2.0.0
with:
inlineScript: |
for i in ./build/azure/packages/nginx-agent*; do
az storage blob upload --auth-mode=login -f "$i" -c ${{ secrets.AZURE_CONTAINER_NAME }} \
--account-name ${{ secrets.AZURE_ACCOUNT_NAME }} --overwrite -n nginx-agent/${GITHUB_REF##*/}/${i##*/}
done
- name: Azure Logout
run: |
az logout
if: always()
- name: Upload Release Assets
# clobber overwrites existing assets of the same name
run: |
gh release upload --clobber v${{env.VERSION}} \
$(find ./build/github/packages -type f \( -name "*.deb" -o -name "*.rpm" -o -name "*.pkg" -o -name "*.apk" \))
- name: Publish Release Packages
if: ${{ inputs.publishPackages == true }}
env:
TOKEN: ${{ inputs.uploadJWT }}
UPLOAD_URL: ${{ secrets.UPLOAD_URL }}
run: |
make release
- name: Publish Github Release
if: ${{ inputs.publishPackages == true }}
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
with:
script: |
const {RELEASE_ID} = process.env
const release = (await github.rest.repos.updateRelease({
owner: context.payload.repository.owner.login,
repo: context.payload.repository.name,
release_id: `${RELEASE_ID}`,
draft: false,
}))
console.log(`Release published: ${release.data.html_url}`)
- name: Create Pull Request
if: ${{ inputs.publishPackages == true && inputs.createPullRequest == true }}
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
with:
script: |
const { repo, owner } = context.repo;
const result = await github.rest.pulls.create({
title: 'Merge ${{ github.ref_name }} back into main',
owner,
repo,
head: '${{ github.ref_name }}',
base: 'main',
body: [
'This PR is auto-generated by the release branch workflow.'
].join('\n')
});