-
Notifications
You must be signed in to change notification settings - Fork 139
227 lines (189 loc) · 6.67 KB
/
build-release.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
# SPDX-License-Identifier: MIT
name: Build (+ Release)
# test build for commit/tag, but only upload release for tags
on:
push:
branches:
- "master"
- 'v[0-9]+.[0-9]+.x' # matches to backport branches, e.g. v3.6.x
tags:
- "v[0-9]+.[0-9]+.[0-9]+"
permissions:
contents: read
jobs:
# Builds sdist and wheel, runs `twine check`, and optionally uploads artifacts.
build:
name: Build package
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up environment
id: setup
uses: ./.github/actions/setup-env
with:
python-version: 3.8
- name: Install dependencies
run: pdm install -dG build
- name: Build package
run: |
pdm run python -m build
ls -la dist/
- name: Twine check
run: pdm run twine check --strict dist/*
- name: Show metadata
run: |
mkdir out/
tar -xf dist/*.tar.gz -C out/
echo -e "<details><summary>Metadata</summary>\n" >> $GITHUB_STEP_SUMMARY
cat out/*/PKG-INFO | sed 's/^/ /' | tee -a $GITHUB_STEP_SUMMARY
echo -e "\n</details>\n" >> $GITHUB_STEP_SUMMARY
- name: Upload artifact
# only upload artifacts when necessary
if: startsWith(github.ref, 'refs/tags/')
uses: actions/upload-artifact@v3
with:
name: dist
path: dist/
if-no-files-found: error
### Anything below this only runs for tags ###
# Ensures that git tag and built version match.
validate-tag:
name: Validate tag
runs-on: ubuntu-latest
if: startsWith(github.ref, 'refs/tags/')
needs:
- build
env:
GIT_TAG: ${{ github.ref_name }}
outputs:
bump_dev: ${{ steps.check-dev.outputs.bump_dev }}
steps:
- name: Download build artifact
uses: actions/download-artifact@v3
with:
name: dist
path: dist/
- name: Compare sdist version to git tag
run: |
mkdir out/
tar -xf dist/*.tar.gz -C out/
SDIST_VERSION="$(grep "^Version:" out/*/PKG-INFO | cut -d' ' -f2-)"
echo "git tag: $GIT_TAG"
echo "sdist version: $SDIST_VERSION"
if [ "$GIT_TAG" != "v$SDIST_VERSION" ]; then
echo "error: git tag does not match sdist version" >&2
exit 1
fi
- name: Determine if dev version PR is needed
id: check-dev
run: |
BUMP_DEV=
# if this is a new major/minor version, create a PR later
if [[ "$GIT_TAG" =~ ^v[0-9]+\.[0-9]+\.0$ ]]; then
BUMP_DEV=1
fi
echo "bump_dev=$BUMP_DEV" | tee -a $GITHUB_OUTPUT
# Creates a draft release on GitHub, and uploads the artifacts there.
release-github:
name: Create GitHub draft release
runs-on: ubuntu-latest
if: startsWith(github.ref, 'refs/tags/')
needs:
- build
- validate-tag
permissions:
contents: write # required for creating releases
steps:
- name: Download build artifact
uses: actions/download-artifact@v3
with:
name: dist
path: dist/
- name: Calculate versions
id: versions
env:
GIT_TAG: ${{ github.ref_name }}
run: |
# v1.2.3 -> v1-2-3 (for changelog)
echo "docs_version=${GIT_TAG//./-}" >> $GITHUB_OUTPUT
- name: Create Release
uses: softprops/action-gh-release@de2c0eb89ae2a093876385947365aca7b0e5f844 # v0.1.15
with:
files: dist/*
draft: true
body: |
TBD.
**Changelog**: https://docs.disnake.dev/en/stable/whats_new.html#${{ steps.versions.outputs.docs_version }}
**Git history**: https://github.com/${{ github.repository }}/compare/vTODO...${{ github.ref_name }}
# Creates a PyPI release (using an environment which requires separate confirmation).
release-pypi:
name: Publish package to pypi.org
environment:
name: release-pypi
url: https://pypi.org/project/disnake/
runs-on: ubuntu-latest
if: startsWith(github.ref, 'refs/tags/')
needs:
- build
- validate-tag
permissions:
id-token: write # this permission is mandatory for trusted publishing
steps:
- name: Download build artifact
uses: actions/download-artifact@v3
with:
name: dist
path: dist/
- name: Upload to pypi
uses: pypa/gh-action-pypi-publish@f5622bde02b04381239da3573277701ceca8f6a0 # v1.8.7
with:
print-hash: true
# Creates a PR to bump to an alpha version for development, if applicable.
create-dev-version-pr:
name: Create dev version bump PR
runs-on: ubuntu-latest
if: startsWith(github.ref, 'refs/tags/') && needs.validate-tag.outputs.bump_dev
needs:
- validate-tag
- release-github
- release-pypi
steps:
# https://docs.github.com/en/apps/creating-github-apps/authenticating-with-a-github-app/making-authenticated-api-requests-with-a-github-app-in-a-github-actions-workflow
- name: Generate app token
id: generate_token
uses: tibdex/github-app-token@b62528385c34dbc9f38e5f4225ac829252d1ea92 # v1.8.0
with:
app_id: ${{ secrets.BOT_APP_ID }}
private_key: ${{ secrets.BOT_PRIVATE_KEY }}
- uses: actions/checkout@v3
with:
token: ${{ steps.generate_token.outputs.token }}
persist-credentials: false
ref: master # the PR action wants a proper base branch
- name: Set git name/email
env:
GIT_USER: ${{ vars.GIT_APP_USER_NAME }}
GIT_EMAIL: ${{ vars.GIT_APP_USER_EMAIL }}
run: |
git config user.name "$GIT_USER"
git config user.email "$GIT_EMAIL"
- name: Update version to dev
id: update-version
run: |
NEW_VERSION="$(python scripts/ci/versiontool.py --set dev)"
git commit -a -m "chore: update version to v$NEW_VERSION"
echo "new_version=$NEW_VERSION" >> $GITHUB_OUTPUT
- name: Create pull request
uses: peter-evans/create-pull-request@153407881ec5c347639a548ade7d8ad1d6740e38 # v5.0.2
with:
token: ${{ steps.generate_token.outputs.token }}
branch: auto/dev-v${{ steps.update-version.outputs.new_version }}
delete-branch: true
base: master
title: "chore: update version to v${{ steps.update-version.outputs.new_version }}"
body: |
Automated dev version PR.
<sub>https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}</sub>
labels: |
skip news
t: meta