Skip to content

Commit 4248639

Browse files
authored
feat(release): update release flow (#112)
1 parent 7adf92c commit 4248639

File tree

6 files changed

+153
-17
lines changed

6 files changed

+153
-17
lines changed

.github/workflows/ci.yml

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: build
22
on:
33
push:
44
branches:
5-
- 'main'
5+
- "main"
66
pull_request:
77

88
jobs:
@@ -11,24 +11,25 @@ jobs:
1111
strategy:
1212
fail-fast: false
1313
matrix:
14-
python: [3.6, 3.7, 3.8, 3.9, '3.10']
14+
python: [3.6, 3.7, 3.8, 3.9, "3.10"]
1515
django:
16-
- 'django>=4.0.0, <4.1'
17-
- 'django>=3.2.0, <3.3'
18-
- 'django>=3.1.0, <3.2'
19-
- 'django>=3.0.0, <3.1'
20-
- 'django>=2.2.0, <3.0'
21-
- 'django>=2.1.0, <2.2.0'
22-
- 'django>=2.0.0, <2.1.0'
16+
- "django>=4.0.0, <4.1"
17+
- "django>=3.2.0, <3.3"
18+
- "django>=3.1.0, <3.2"
19+
- "django>=3.0.0, <3.1"
20+
- "django>=2.2.0, <3.0"
21+
- "django>=2.1.0, <2.2.0"
22+
- "django>=2.0.0, <2.1.0"
2323
exclude:
2424
- python: 3.6
25-
django: 'django>=4.0.0, <4.1'
25+
django: "django>=4.0.0, <4.1"
2626
- python: 3.7
27-
django: 'django>=4.0.0, <4.1'
27+
django: "django>=4.0.0, <4.1"
2828
- python: "3.10"
29-
django: 'django>=2.0.0, <2.1.0'
29+
django: "django>=2.0.0, <2.1.0"
3030
steps:
3131
- uses: actions/checkout@v3
32+
3233
- uses: actions/setup-python@v3
3334
with:
3435
python-version: ${{ matrix.python }}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
name: Create release PR
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
version:
7+
description: "The new version number. Example: 1.40.1"
8+
required: true
9+
10+
jobs:
11+
init_release:
12+
name: 🚀 Create release PR
13+
runs-on: ubuntu-latest
14+
steps:
15+
- uses: actions/checkout@v3
16+
with:
17+
fetch-depth: 0 # gives the changelog generator access to all previous commits
18+
19+
- name: Update CHANGELOG.md, setup.py and push release branch
20+
env:
21+
VERSION: ${{ github.event.inputs.version }}
22+
run: |
23+
npx --yes [email protected] --release-as "$VERSION" --skip.tag --skip.commit
24+
git config --global user.name 'github-actions'
25+
git config --global user.email '[email protected]'
26+
git checkout -q -b "release-$VERSION"
27+
git commit -am "chore(release): $VERSION"
28+
git push -q -u origin "release-$VERSION"
29+
30+
- name: Get changelog diff
31+
uses: actions/github-script@v6
32+
with:
33+
script: |
34+
const get_change_log_diff = require('./scripts/get_changelog_diff.js')
35+
core.exportVariable('CHANGELOG', get_change_log_diff())
36+
37+
- name: Open pull request
38+
env:
39+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
40+
run: |
41+
gh pr create \
42+
-t "chore(release): ${{ github.event.inputs.version }}" \
43+
-b "# :rocket: ${{ github.event.inputs.version }}
44+
Make sure to use squash & merge when merging!
45+
Once this is merged, another job will kick off automatically and publish the package.
46+
# :memo: Changelog
47+
${{ env.CHANGELOG }}"

.github/workflows/release.yml

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
name: Release
2+
3+
on:
4+
pull_request:
5+
types: [closed]
6+
branches:
7+
- master
8+
- main
9+
10+
jobs:
11+
Release:
12+
name: 🚀 Release
13+
if: github.event.pull_request.merged && startsWith(github.head_ref, 'release-')
14+
runs-on: ubuntu-latest
15+
steps:
16+
- uses: actions/checkout@v3
17+
with:
18+
fetch-depth: 0
19+
20+
- uses: actions/github-script@v6
21+
with:
22+
script: |
23+
const get_change_log_diff = require('./scripts/get_changelog_diff.js')
24+
core.exportVariable('CHANGELOG', get_change_log_diff())
25+
26+
// Getting the release version from the PR source branch
27+
// Source branch looks like this: release-1.0.0
28+
const version = context.payload.pull_request.head.ref.split('-')[1]
29+
core.exportVariable('VERSION', version)
30+
31+
- uses: actions/setup-python@v3
32+
with:
33+
python-version: "3.10"
34+
35+
- name: Publish to PyPi
36+
env:
37+
TWINE_USERNAME: "__token__"
38+
TWINE_PASSWORD: "${{ secrets.PYPI_TOKEN }}"
39+
run: |
40+
pip install -q twine==3.7.1 wheel==0.37.1
41+
python setup.py sdist bdist_wheel
42+
twine upload --non-interactive dist/*
43+
44+
- name: Create release on GitHub
45+
uses: ncipollo/release-action@v1
46+
with:
47+
body: ${{ env.CHANGELOG }}
48+
tag: ${{ env.VERSION }}
49+
token: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/reviewdog.yml

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,16 @@ jobs:
1010
reviewdog:
1111
runs-on: ubuntu-latest
1212
steps:
13-
- uses: actions/checkout@v2
13+
- uses: actions/checkout@v3
1414

1515
- uses: reviewdog/action-setup@v1
1616
with:
1717
reviewdog_version: latest
1818

19-
- uses: actions/setup-python@v2
19+
- uses: actions/setup-python@v3
2020
with:
2121
python-version: "3.10"
2222

23-
- name: Add pip bin to PATH
24-
run: echo "/home/runner/.local/bin" >> $GITHUB_PATH
25-
2623
- name: Install deps
2724
run: pip install ".[ci]"
2825

.versionrc.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
const setupPyUpdater = {
2+
VERSION_REGEX: /version = "(.+)"/,
3+
4+
readVersion: function (contents) {
5+
const version = this.VERSION_REGEX.exec(contents)[1];
6+
return version;
7+
},
8+
9+
writeVersion: function (contents, version) {
10+
return contents.replace(this.VERSION_REGEX.exec(contents)[0], `version = "${version}"`);
11+
}
12+
}
13+
14+
module.exports = {
15+
bumpFiles: [{ filename: './setup.py', updater: setupPyUpdater }],
16+
}

scripts/get_changelog_diff.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
Here we're trying to parse the latest changes from CHANGELOG.md file.
3+
The changelog looks like this:
4+
5+
## 0.0.3
6+
- Something #3
7+
## 0.0.2
8+
- Something #2
9+
## 0.0.1
10+
- Something #1
11+
12+
In this case we're trying to extract "- Something #3" since that's the latest change.
13+
*/
14+
module.exports = () => {
15+
const fs = require('fs');
16+
17+
changelog = fs.readFileSync('CHANGELOG.md', 'utf8');
18+
releases = changelog.match(/## [?[0-9](.+)/g);
19+
20+
current_release = changelog.indexOf(releases[0]);
21+
previous_release = changelog.indexOf(releases[1]);
22+
23+
latest_changes = changelog.substr(current_release, previous_release - current_release);
24+
25+
return latest_changes;
26+
};

0 commit comments

Comments
 (0)