forked from adamlaska/datatracker
-
Notifications
You must be signed in to change notification settings - Fork 0
259 lines (228 loc) · 8.35 KB
/
build.yml
File metadata and controls
259 lines (228 loc) · 8.35 KB
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
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
name: Build and Release
on:
push:
tags:
- '*'
workflow_dispatch:
inputs:
publish:
description: 'Create Production Release'
required: true
type: boolean
skiptests:
description: 'Skip Tests'
required: true
type: boolean
dryrun:
description: 'Dry Run'
required: true
type: boolean
summary:
description: 'Summary'
required: false
type: string
default: ''
jobs:
# -----------------------------------------------------------------
# PREPARE
# -----------------------------------------------------------------
prepare:
name: Prepare Release
runs-on: ubuntu-latest
outputs:
should_deploy: ${{ steps.buildvars.outputs.should_deploy }}
pkg_version: ${{ steps.buildvars.outputs.pkg_version }}
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Dry Run Notify
if: ${{ github.event.inputs.dryrun == 'true' }}
run: |
echo "::notice::This is a DRY RUN of a production release. No release will be created."
- name: Get Next Version
if: ${{ github.event.inputs.publish == 'true' || github.event.inputs.dryrun == 'true' }}
id: semver
uses: ietf-tools/semver-action@v1
with:
token: ${{ github.token }}
branch: main
- name: Set Next Version Env Var
if: ${{ github.event.inputs.publish == 'true' || github.event.inputs.dryrun == 'true' }}
run: |
echo "NEXT_VERSION=$nextStrict" >> $GITHUB_ENV
- name: Create Draft Release
uses: ncipollo/release-action@v1
if: ${{ github.event.inputs.publish == 'true' && github.event.inputs.dryrun == 'false' }}
with:
prerelease: true
draft: false
commit: ${{ github.sha }}
tag: ${{ env.NEXT_VERSION }}
name: ${{ env.NEXT_VERSION }}
body: '*pending*'
token: ${{ secrets.GITHUB_TOKEN }}
- name: Set Build Variables
id: buildvars
run: |
if [[ $NEXT_VERSION ]]; then
echo "Using AUTO SEMVER mode: $NEXT_VERSION"
echo "::set-output name=should_deploy::true"
echo "::set-output name=pkg_version::$NEXT_VERSION"
echo "::notice::Release $NEXT_VERSION created using branch $GITHUB_REF_NAME"
elif [[ "$GITHUB_REF" =~ ^refs/tags/* ]]; then
echo "Using TAG mode: $GITHUB_REF_NAME"
echo "::set-output name=should_deploy::true"
echo "::set-output name=pkg_version::$GITHUB_REF_NAME"
echo "::notice::Release $GITHUB_REF_NAME created using tag $GITHUB_REF_NAME"
else
echo "Using TEST mode: 8.0.0-dev.$GITHUB_RUN_NUMBER"
echo "::set-output name=should_deploy::false"
echo "::set-output name=pkg_version::8.0.0-dev.$GITHUB_RUN_NUMBER"
echo "::notice::Non-production build 8.0.0-dev.$GITHUB_RUN_NUMBER created using branch $GITHUB_REF_NAME"
fi
# -----------------------------------------------------------------
# TESTS
# -----------------------------------------------------------------
tests:
name: Run Tests
if: ${{ github.event.inputs.skiptests == 'false' }}
needs: [prepare]
runs-on: ubuntu-latest
container: ghcr.io/ietf-tools/datatracker-test-base:latest
services:
db:
image: ghcr.io/ietf-tools/datatracker-db:latest
volumes:
- mariadb-data:/var/lib/mysql
env:
MYSQL_ROOT_PASSWORD: ietf
MYSQL_DATABASE: ietf_utf8
MYSQL_USER: django
MYSQL_PASSWORD: RkTkDPFnKpko
steps:
- uses: actions/checkout@v3
- name: Prepare for tests
run: |
chmod +x ./dev/tests/prepare.sh
sh ./dev/tests/prepare.sh
- name: Ensure DB is ready
run: |
/usr/local/bin/wait-for db:3306 -- echo "DB ready"
- name: Run all tests
run: |
echo "Running checks..."
./ietf/manage.py check
echo "Running tests..."
./ietf/manage.py test --settings=settings_sqlitetest
coverage xml
- name: Upload Coverage Results to Codecov
uses: codecov/codecov-action@v2.1.0
with:
files: coverage.xml
- name: Convert Coverage Results
if: ${{ always() }}
run: |
mv latest-coverage.json coverage.json
- name: Upload Coverage Results as Build Artifact
uses: actions/upload-artifact@v3.0.0
if: ${{ always() }}
with:
name: coverage
path: coverage.json
# -----------------------------------------------------------------
# RELEASE
# -----------------------------------------------------------------
release:
name: Make Release
if: ${{ always() }}
needs: [tests, prepare]
runs-on: ubuntu-latest
env:
SHOULD_DEPLOY: ${{needs.prepare.outputs.should_deploy}}
PKG_VERSION: ${{needs.prepare.outputs.pkg_version}}
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Setup Node.js
uses: actions/setup-node@v3.0.0
with:
node-version: 16.x
- name: Setup Python
uses: actions/setup-python@v2
with:
python-version: '3.x'
- name: Download a Coverage Results
if: ${{ github.event.inputs.skiptests == 'false' }}
uses: actions/download-artifact@v3.0.0
with:
name: coverage
- name: Make Release Build
env:
DEBIAN_FRONTEND: noninteractive
run: |
echo "PKG_VERSION: $PKG_VERSION"
echo "GITHUB_SHA: $GITHUB_SHA"
echo "GITHUB_REF_NAME: $GITHUB_REF_NAME"
echo "Running build script..."
chmod +x ./dev/deploy/build.sh
sh ./dev/deploy/build.sh
echo "Setting version $PKG_VERSION..."
sed -i -r -e "s|^__version__ += '.*'$|__version__ = '$PKG_VERSION'|" ietf/__init__.py
sed -i -r -e "s|^__release_hash__ += '.*'$|__release_hash__ = '$GITHUB_SHA'|" ietf/__init__.py
sed -i -r -e "s|^__release_branch__ += '.*'$|__release_branch__ = '$GITHUB_REF_NAME'|" ietf/__init__.py
- name: Set Production Flags
if: ${{ env.SHOULD_DEPLOY == 'true' }}
run: |
echo "Setting production flags in settings.py..."
sed -i -r -e 's/^DEBUG *= *.*$/DEBUG = False/' -e "s/^SERVER_MODE *= *.*\$/SERVER_MODE = 'production'/" ietf/settings.py
- name: Make Release Tarball
env:
DEBIAN_FRONTEND: noninteractive
run: |
echo "Build release tarball..."
mkdir -p /home/runner/work/release
tar -czf /home/runner/work/release/release.tar.gz -X dev/deploy/exclude-patterns.txt .
- name: Update CHANGELOG
id: changelog
uses: Requarks/changelog-action@v1
if: ${{ env.SHOULD_DEPLOY == 'true' && github.event.inputs.dryrun == 'false' }}
with:
token: ${{ github.token }}
tag: ${{ env.PKG_VERSION }}
writeToFile: false
- name: Prepare Coverage Action
if: ${{ github.event.inputs.skiptests == 'false' }}
working-directory: ./dev/coverage-action
run: npm install
- name: Process Coverage Stats + Chart
id: covprocess
uses: ./dev/coverage-action/
if: ${{ github.event.inputs.skiptests == 'false' }}
with:
token: ${{ github.token }}
tokenCommon: ${{ secrets.GH_COMMON_TOKEN }}
repoCommon: common
version: ${{needs.prepare.outputs.pkg_version}}
changelog: ${{ steps.changelog.outputs.changes }}
summary: ${{ github.event.inputs.summary }}
coverageResultsPath: coverage.json
histCoveragePath: historical-coverage.json
- name: Create Release
uses: ncipollo/release-action@v1
if: ${{ env.SHOULD_DEPLOY == 'true' && github.event.inputs.dryrun == 'false' }}
with:
allowUpdates: true
draft: false
tag: ${{ env.PKG_VERSION }}
name: ${{ env.PKG_VERSION }}
body: ${{ steps.covprocess.outputs.changelog }}
artifacts: "/home/runner/work/release/release.tar.gz,coverage.json,historical-coverage.json"
token: ${{ secrets.GITHUB_TOKEN }}
- name: Upload Build Artifacts
uses: actions/upload-artifact@v2.3.1
if: ${{ env.SHOULD_DEPLOY == 'false' || github.event.inputs.dryrun == 'true' }}
with:
name: release
path: /home/runner/work/release/release.tar.gz