-
Notifications
You must be signed in to change notification settings - Fork 0
285 lines (263 loc) · 8.77 KB
/
createNewRelease.yaml
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
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
name: Create New Release
on:
workflow_dispatch:
push:
branches:
- main
# Run all tests before making a release
jobs:
# Only make a release if commit contains [RELEASE]
check-commit-message:
runs-on: ubuntu-latest
outputs:
contains_release: ${{ steps.commit_check.outputs.contains_release }}
steps:
- name: Check out code
uses: actions/checkout@v4
- name: Check commit message for [RELEASE]
id: commit_check
run: |
if [[ "${{ github.event.head_commit.message }}" == *"[RELEASE]"* ]]; then
echo "contains_release=true" >> $GITHUB_OUTPUT
else
echo "contains_release=false" >> $GITHUB_OUTPUT
fi
list-containers:
needs: check-commit-message
if: ${{ needs.check-commit-message.outputs.contains_release == 'true' }}
uses: ./.github/workflows/listContainers.yaml
test-for-release:
needs:
- check-commit-message
- list-containers
if: ${{ needs.check-commit-message.outputs.contains_release == 'true' }}
strategy:
matrix:
container: ${{fromJson(needs.list-containers.outputs.all-containers)}}
uses: ./.github/workflows/run-container-workflow.yaml
with:
container: ${{ matrix.container }}
secrets: inherit
tag-release:
name: Update phdi init version number
needs: test-for-release
permissions:
contents: write
outputs:
version: ${{ steps.get_version.outputs.version }}
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
with:
fetch-depth: "0"
ref: "main"
- name: Install poetry and dependencies
run: |
pip install poetry
# update the version number in the phdi/__init.py__ file
- name: Get PHDI Version
id: get_version
run: |
VERSION_WITH_PHDI=$(poetry version)
echo "version=${VERSION_WITH_PHDI:5}" >> $GITHUB_OUTPUT
# Create new release tag
- name: Set up Git user
run: |
git config --local user.email "[email protected]"
git config --local user.name "GitHub Action"
- name: Tag Release
uses: EndBug/latest-tag@latest
with:
ref: ${{ steps.get_version.outputs.version }}
# Generate release notes
- name: Generate release notes
id: release_notes
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
latest_release_date=$(gh api "/repos/$GITHUB_REPOSITORY/releases?per_page=1" | jq ".[0].created_at")
prs=$(gh pr list --base main --state closed --json title,number,url,closedAt -q ".[] | select(.closedAt > $latest_release_date) | select(.title | contains(\"RELEASE\") | not)")
echo "# Release Notes" > release-notes.md
echo "" >> release-notes.md
echo "" >> release-notes.md
while IFS= read -r pr; do
pr_title=$(echo "$pr" | jq -r ".title")
pr_number=$(echo "$pr" | jq -r ".number")
pr_url=$(echo "$pr" | jq -r ".url")
line_text="- $pr_title ([#$pr_number]($pr_url))"
echo $line_text >> release-notes.md
done < <(printf '%s' "$prs")
# Create new release based upon the latest created tag
- name: Create Release
id: create_release
uses: actions/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ steps.get_version.outputs.version }}
release_name: ${{ steps.get_version.outputs.version }}
body_path: release-notes.md
release-to-pypi:
name: Build and publish PHDI to PyPI
needs: tag-release
runs-on: ubuntu-latest
permissions:
id-token: write
steps:
- uses: actions/checkout@v4
with:
fetch-depth: "0"
ref: ${{ needs.tag-release.outputs.version }}
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.x"
- name: Install pypa/build
run: >-
python -m
pip install
build
--user
- name: Build a binary wheel and a source tarball
run: >-
python -m
build
--sdist
--wheel
--outdir dist/
.
- name: Publish distribution 📦 to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
password: ${{ secrets.PYPI_API_TOKEN }}
# Rebuild all containers for the new release
build-containers-for-release:
needs:
- tag-release
- release-to-pypi
permissions:
contents: read
packages: write
id-token: write
uses: ./.github/workflows/buildReleaseContainers.yaml
with:
container-tag: ${{ needs.tag-release.outputs.version }}
# Create updated PHDI docs for the latest release
generate-and-update-phdi-docs:
needs:
- tag-release
- build-containers-for-release
permissions:
contents: write
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: "0"
ref: ${{ needs.tag-release.outputs.version }}
- name: Install poetry and dependencies
run: |
pip install poetry
poetry install
- name: Set environment variable for pdoc
run: echo "PDOC_ALLOW_EXEC=1" >> $GITHUB_ENV
- name: Clear Poetry Cache
run: |
poetry cache clear pypi --all
poetry cache clear virtualenvs --all
- name: Generate docs and move to docs branch
run: |
poetry run pdoc ./phdi -o ./docs/${{ needs.tag-release.outputs.version }}/sdk
- uses: actions/upload-artifact@v3
with:
name: phdi-docs
path: ./docs/${{ needs.tag-release.outputs.version }}/sdk
# Create updated container docs for the latest release
generate-and-update-container-docs:
needs:
- tag-release
- list-containers
- generate-and-update-phdi-docs
permissions:
contents: write
runs-on: ubuntu-latest
services:
test-db:
image: postgres:13-alpine3.16
env:
POSTGRES_PASSWORD: pw
POSTGRES_DB: testdb
POSTGRES_USER: postgres
# Set health checks to wait until postgres has started
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
--name testdb
ports:
- 5432:5432
strategy:
matrix:
container: ${{fromJson(needs.list-containers.outputs.python-containers)}}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: "0"
ref: ${{ needs.tag-release.outputs.version }}
- name: Update Container Documentation
env:
MPI_DBNAME: testdb
MPI_PASSWORD: pw
MPI_DB_TYPE: postgres
MPI_HOST: localhost
MPI_USER: postgres
MPI_PORT: 5432
MPI_PATIENT_TABLE: patient
MPI_PERSON_TABLE: person
run: |
npm i -g redoc-cli
CONTAINER=${{ matrix.container }}
cd $GITHUB_WORKSPACE/containers/$CONTAINER
cp $GITHUB_WORKSPACE/utils/make_openapi_json.py .
pip install -r requirements.txt
python make_openapi_json.py
redoc-cli build -o $GITHUB_WORKSPACE/docs/${{ needs.tag-release.outputs.version }}/containers/$CONTAINER.html openapi.json
- uses: actions/upload-artifact@v3
with:
name: container-docs
path: ./docs/${{ needs.tag-release.outputs.version }}/containers
commit-docs:
needs:
- tag-release
- generate-and-update-phdi-docs
- generate-and-update-container-docs
permissions:
contents: write
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
ref: docs
- name: Download phdi docs from artifacts
uses: actions/[email protected]
with:
name: phdi-docs
path: ./docs/${{ needs.tag-release.outputs.version }}/sdk
- name: Download container docs from artifacts
uses: actions/[email protected]
with:
name: container-docs
path: ./docs/${{ needs.tag-release.outputs.version }}/containers
- name: Copy to latest folder
run: |
rm -rf ./docs/latest
mkdir -p ./docs/latest/sdk
mkdir -p ./docs/latest/containers
cp -r ./docs/${{ needs.tag-release.outputs.version }}/sdk/* ./docs/latest/sdk
cp -r ./docs/${{ needs.tag-release.outputs.version }}/containers/* ./docs/latest/containers
- name: Commit New Documentation
uses: EndBug/add-and-commit@v9
with:
add: docs
message: Automated update of docs for ${{ needs.tag-release.outputs.version }} release.