-
Notifications
You must be signed in to change notification settings - Fork 1
223 lines (192 loc) · 7.12 KB
/
release_github.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
name: Draft GitHub Release
on:
workflow_dispatch:
inputs:
version_level:
description: Semantic version level increase
required: true
type: choice
default: patch
options:
- patch
- minor
- major
permissions:
contents: write
packages: read
statuses: read
checks: read
pull-requests: write
actions: read
repository-projects: read
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GH_PAGER: cat
jobs:
checks:
name: Check requirements
runs-on: ubuntu-latest
steps:
- name: Fail if main branch was selected
if: ${{ github.ref_name == 'main' }}
run: |
echo "Cannot release from main branch, please select valid release branch."
exit 1
- name: Check GitHub token validity
run: |
echo "Validating GitHub Token"
status_code=$(curl -o /dev/null -s -w "%{http_code}" -H "Authorization: token ${{ secrets.GH_PAT }}" https://api.github.com/user)
if [ "$status_code" -ne 200 ]; then
echo "Error: GitHub token is invalid or expired. Please update your token in secrets."
echo "Instructions can be found at: https://github.com/EIT-ALIVE/eitprocessing/blob/main/README.dev.md#updating-the-token"
exit 1
else
echo "GitHub token is valid."
fi
- name: Checkout repository
uses: actions/checkout@v4
- name: Check if PR exists
run: gh pr view ${{ github.ref_name }}
- name: Check if PR base is main
run: gh pr view ${{ github.ref_name }} --json baseRefName -q 'if .baseRefName == "main" then "PR base is main" else error("PR base is not main") end'
- name: Check if PR is mergeable
run: gh pr view ${{ github.ref_name }} --json mergeable -q 'if .mergeable == "MERGEABLE" then "PR is mergeable" else error("PR is not mergeable") end'
- name: Check whether PR checks pass(ed)
# note that this assumed there are checks to be passed; this fails if there are no checks, which is no
# relevant to this repo
run: |
gh pr checks ${{ github.ref_name }} --watch --fail-fast
gh pr checks ${{ github.ref_name }} --json state -q 'if . | length == 0 then "No checks found." elif map(.state == "SUCCESS") | all then "All checks passed" else error("Not all checks passed") end'
test_python_releases:
needs: checks
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: ["ubuntu-latest"]
python-version: ["3.10", "3.11", "3.12", "3.13"]
name: Build for ${{ matrix.python-version }}, ${{ matrix.os }}
env:
EIT_PROCESSING_TEST_DATA: ${{ github.workspace }}/../eitprocessing_data/
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Install eitprocessing
uses: ./.github/actions/install_eitprocessing
with:
dependencies: testing
extract-data: true
python-version: ${{ matrix.python-version }}
token: ${{ secrets.GITHUB_TOKEN }}
data-directory: ${{ env.EIT_PROCESSING_TEST_DATA }}
- name: Run pytest
run: pytest -v
- name: Install additional dependencies for building
run: python3 -m pip install --upgrade ".[publishing]"
- name: Build eitprocessing
run: python3 -m build
merge_and_bump:
name: Merge the changes into main and bump the version
needs: test_python_releases
runs-on: ubuntu-latest
outputs:
new-version: ${{ steps.bump.outputs.current-version }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
ref: main
fetch-depth: 0
token: ${{ secrets.GH_PAT }}
- name: Configure git
run: |
git config user.email "${GITHUB_ACTOR_ID}+${GITHUB_ACTOR}@users.noreply.github.com"
git config user.name "GitHub Actions"
git config -l
- name: Merge branch into main
run: |
git switch main
git branch -f ${{ github.ref_name }} origin/${{ github.ref_name }}
git merge ${{ github.ref_name }} --no-ff --no-edit
- name: Install Python
uses: actions/[email protected]
with:
python-version: "3.12"
- name: Install bump-my-version
shell: bash
run: |
python3 -m pip install pyproject-deplister
pyproject-deplister --extra dev --path pyproject.toml | grep bump-my-version | sed 's/ //g' | xargs -I{} python3 -m pip install "{}"
- name: Pass Inputs to Shell
id: bump
shell: bash
run: |
echo "previous-version=$(bump-my-version show current_version)" >> $GITHUB_OUTPUT
bump-my-version bump ${{ inputs.version_level }} --commit --tag
([[ $? -gt 0 ]] && echo "bumped=false" || echo "bumped=true") >> $GITHUB_OUTPUT
echo "current-version=$(bump-my-version show current_version)" >> $GITHUB_OUTPUT
- name: Fail if bumping failes
if: steps.bump.outputs.bumped == 'false'
run: |
echo "Bumping failed."
git reset --hard HEAD^
exit 1
- name: Check new version number
if: steps.bump.outputs.bumped == 'true'
run: |
echo "Version was bumped from ${{ steps.bump.outputs.previous-version }} to ${{ steps.bump.outputs.current-version }}!"
- name: Merge main into develop
run: |
git checkout develop
git merge main --no-ff --no-edit || { echo "Can't merge changes to develop. Manually merge PR and create GitHub release."; exit 1; }
- name: Push changes to develop
uses: ad-m/github-push-action@master
with:
github_token: ${{ secrets.GH_PAT }}
branch: develop
force_with_lease: true
- name: Checkout main
run: |
git checkout main
- name: Push changes to main
uses: ad-m/github-push-action@master
with:
github_token: ${{ secrets.GH_PAT }}
branch: main
force_with_lease: true
github_release:
name: Create a draft GitHub release
needs: merge_and_bump
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
ref: main
- name: Create GitHub Release
id: create_release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gh release create v${{ needs.merge_and_bump.outputs.new-version }} \
--title="Release v${{ needs.merge_and_bump.outputs.new-version }}" \
--generate-notes \
--draft
remove_branch:
name: Remove PR branch
needs: github_release
if: ${{ github.ref_name != 'develop' }}
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
ref: develop
fetch-depth: 0
- name: Remove PR branch
uses: dawidd6/action-delete-branch@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
branches: ${{ github.ref_name }}