-
Notifications
You must be signed in to change notification settings - Fork 0
237 lines (215 loc) · 7.47 KB
/
release.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
231
232
233
234
235
236
237
# REF: https://packaging.python.org/en/latest/guides/publishing-package-distribution-releases-using-github-actions-ci-cd-workflows/#the-whole-ci-cd-workflow
name: publish release
on:
# run this workflow when manually triggered
workflow_dispatch:
inputs:
part:
description: "Semver part to bump (major, minor, patch)"
type: choice
required: true
default: "patch"
options: ["major", "minor", "patch"]
dry-run:
description: "Dry run"
type: boolean
required: true
default: true
skip-tests:
description: "Skip tests"
type: boolean
required: true
default: false
jobs:
test:
name: Run tests
runs-on: ubuntu-latest
steps:
- name: Get repo
uses: actions/checkout@v4
- name: Run tests
if: ${{ github.event.inputs.skip-tests == 'false' }}
uses: ./.github/workflows/dev.yml
- name: Skip tests
if: ${{ github.event.inputs.skip-tests == 'true' }}
run: echo "Skipping tests"
bump:
name: Bump version
runs-on: ubuntu-latest
needs: test
outputs:
VERSION: ${{ steps.get-version.outputs.VERSION }}
SHORT_VERSION: ${{ steps.get-version.outputs.SHORT_VERSION }}
MAJOR_VERSION: ${{ steps.get-version.outputs.MAJOR_VERSION }}
MINOR_VERSION: ${{ steps.get-version.outputs.MINOR_VERSION }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Get tags
run: git fetch --tags origin
- name: Configure git for github-actions[bot]
run: |
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"
- name: Install Python
uses: actions/setup-python@v5
with:
python-version: "3.11"
- name: Install Poetry
uses: abatilo/actions-poetry@v2
- name: Install commitizen
run: pip install commitizen
- name: Bump version with commitizen
run: |
cz bump --increment ${{ github.event.inputs.part }}
- name: Commit and push with tags
if: ${{ github.event.inputs.dry-run == 'false' }}
run: git push --follow-tags
- name: Get version
id: get-version
run: |
version="$(poetry version -s)"
echo "VERSION=$version" >> $GITHUB_OUTPUT
major_version="$(cut -d '.' -f 1 <<< $version)"
echo "MAJOR_VERSION=$major_version" >> $GITHUB_OUTPUT
minor_version="$(cut -d '.' -f 2 <<< $version)"
echo "MINOR_VERSION=$minor_version" >> $GITHUB_OUTPUT
short_version="$major_version.$minor_version"
echo "SHORT_VERSION=$short_version" >> $GITHUB_OUTPUT
- name: Show short version
run: echo ${{ steps.get-version.outputs.SHORT_VERSION }}
build:
name: Build distribution
runs-on: ubuntu-latest
needs: bump
steps:
- name: Show version
run: echo ${{ needs.bump.outputs.VERSION }}
- uses: actions/checkout@v4
with:
# want this to be the version that was just bumped
ref: main
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.11"
- uses: abatilo/actions-poetry@v2
- name: Check version
run: poetry version -s
- name: Build wheels and source tarball
run: poetry build
- name: Store the distribution packages
uses: actions/upload-artifact@v3
with:
name: python-package-distributions
path: dist/
publish-to-pypi:
name: Publish to PyPI
needs: build
runs-on: ubuntu-latest
environment:
name: pypi
url: https://pypi.org/p/networkframe
permissions:
id-token: write # IMPORTANT: mandatory for trusted publishing
steps:
- name: Download all the dists
uses: actions/download-artifact@v3
with:
name: python-package-distributions
path: dist/
- name: Publish distribution to PyPI
if: ${{ github.event.inputs.dry-run == 'false' }}
uses: pypa/gh-action-pypi-publish@release/v1
github-release:
name: Release to GitHub
needs:
- publish-to-pypi
- bump
runs-on: ubuntu-latest
permissions:
contents: write # IMPORTANT: mandatory for making GitHub Releases
id-token: write # IMPORTANT: mandatory for sigstore
steps:
- name: Download all the dists
uses: actions/download-artifact@v3
with:
name: python-package-distributions
path: dist/
- name: Sign the dists with Sigstore
uses: sigstore/gh-action-sigstore-python@v1.2.3
with:
inputs: >-
./dist/*.tar.gz
./dist/*.whl
- name: Find ref
run: echo ${{ github.ref }}
- name: Find proper version
run: echo ${{ needs.bump.outputs.VERSION }}
- name: Create GitHub Release
if: ${{ github.event.inputs.dry-run == 'false' }}
env:
GITHUB_TOKEN: ${{ github.token }}
run: >-
gh release create
'v${{ needs.bump.outputs.VERSION }}'
--repo '${{ github.repository }}'
--notes ""
- name: Upload artifact signatures to GitHub Release
if: ${{ github.event.inputs.dry-run == 'false' }}
env:
GITHUB_TOKEN: ${{ github.token }}
# Upload to GitHub Release using the `gh` CLI.
# `dist/` contains the built packages, and the
# sigstore-produced signatures and certificates.
run: >-
gh release upload
'v${{ needs.bump.outputs.VERSION }}' dist/**
--repo '${{ github.repository }}'
docs:
name: Release new docs version
needs:
- publish-to-pypi
- bump
runs-on: ubuntu-latest
steps:
- name: Get repo
uses: actions/checkout@v4
with:
ref: main
fetch-depth: 0 # for building docs with page updated info
- name: Get gh-pages branch
run: git fetch origin gh-pages --depth=1
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: "3.11"
- name: Install Poetry
uses: abatilo/actions-poetry@v2
- name: Setup a local virtual environment # for caching purposes
run: |
poetry config virtualenvs.create true --local
poetry config virtualenvs.in-project true --local
- name: Cache for virtual environment
uses: actions/cache@v3
with:
path: ./.venv
key: venv-3.11-${{ hashFiles('poetry.lock') }}
- name: Install dependencies
run: poetry install --with dev
- name: Configure git for github-actions[bot]
run: |
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"
- name: Get version
run: echo "new_version=$(poetry version -s)" >> $GITHUB_ENV
- name: Build and push versioned docs with mike
if: ${{ github.event.inputs.dry-run == 'false' }}
run: |
poetry run mike deploy --push --update-aliases ${{ needs.bump.outputs.SHORT_VERSION }} stable
poetry run mike set-default stable --push
- name: Test build versioned docs with mike
if: ${{ github.event.inputs.dry-run == 'true' }}
run: |
poetry run mike deploy --update-aliases ${{ needs.bump.outputs.SHORT_VERSION }} stable
poetry run mike set-default stable