Skip to content

Commit c5bc03e

Browse files
Dídac Colldidix21
authored andcommitted
GH-88: Automate release candidate
- Create a new action for creating a new release candidate. - It will update the latest draft version on files: setup.py, pyproject.toml, .github_changelog_generator, doc/source/conf.py. - Generate tar and zip distribution. - Upload to the release draft. - Add new action for updating target_commitish to "ref/head/master". - Commit changes on master and push them.
1 parent a4f2085 commit c5bc03e

File tree

3 files changed

+118
-0
lines changed

3 files changed

+118
-0
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: "Update target commitish"
2+
description: Update target commitish from a provided release
3+
inputs:
4+
github_token:
5+
description: Provide github token
6+
required: true
7+
release_id:
8+
description: Provide a valid release id
9+
required: true
10+
target_commitish:
11+
description: Provide the new target commitish
12+
required: true
13+
tag_name:
14+
description: Provide the tag name
15+
required: true
16+
17+
runs:
18+
using: "composite" # This is mandatory if we want to share the action between workflows.
19+
steps:
20+
- name: 'Update target commitish ${{ inputs.target_commitish }}'
21+
shell: bash
22+
run: |
23+
gh api repos/$REPOSITORY/releases/$RELEASE_ID \
24+
--method PATCH \
25+
-H "Accept: application/vnd.github+json" \
26+
-f target_commitish="$TARGET_COMMITISH" \
27+
-f tag_name="$TAG_NAME"
28+
env:
29+
GH_TOKEN: ${{ inputs.github_token }}
30+
REPOSITORY: ${{ github.repository }}
31+
RELEASE_ID: ${{ inputs.release_id }}
32+
TARGET_COMMITISH: ${{ inputs.target_commitish }}
33+
TAG_NAME: ${{ inputs.tag_name }}
34+
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
name: Prepare release
2+
3+
on:
4+
workflow_dispatch:
5+
6+
jobs:
7+
prepare-release:
8+
runs-on: ubuntu-latest
9+
steps:
10+
- uses: actions/checkout@v3
11+
- name: Set up Python 3.10
12+
uses: actions/setup-python@v4
13+
with:
14+
python-version: '3.10'
15+
- name: "Get latest release draft"
16+
uses: cardinalby/git-get-release-action@v1
17+
id: latest_prerelease
18+
env:
19+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
20+
with:
21+
latest: true
22+
draft: true
23+
24+
- name: Install dependencies
25+
run: |
26+
python -m pip install --upgrade pip
27+
pip install twine
28+
pip install coverage
29+
pip install -U pytest
30+
pip install poetry
31+
32+
- name: Run unit tests
33+
run: |
34+
coverage run -m pytest
35+
coverage xml
36+
37+
- name: Bump version on all needed files
38+
run: |
39+
./scripts/update-release.py -v ${{ steps.latest_prerelease.outputs.tag_name }}
40+
41+
- name: "✏️ Generate release changelog"
42+
uses: heinrichreimer/[email protected]
43+
with:
44+
token: ${{ secrets.GITHUB_TOKEN }}
45+
46+
- name: Check commit has been updated
47+
run: |
48+
git diff
49+
50+
- name: Build package
51+
run: python setup.py sdist --formats=gztar,zip
52+
53+
- name: Upload binaries to release
54+
uses: xresloader/upload-to-github-release@v1
55+
env:
56+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
57+
with:
58+
file: ./dist/*
59+
draft: true
60+
release_id: ${{ steps.latest_prerelease.outputs.id }}
61+
62+
- name: 'Bump version to ${{ steps.latest_prerelease.outputs.tag_name }}'
63+
run: |
64+
git config --local user.email "[email protected]"
65+
git config --local user.name "github-actions[bot]"
66+
git commit -m "Bump version to ${{ steps.latest_prerelease.outputs.tag_name }}" -a
67+
68+
- name: Push changes
69+
uses: ad-m/[email protected]
70+
with:
71+
github_token: ${{ secrets.GITHUB_TOKEN }}
72+
branch: ${{ github.ref }}
73+
74+
- name: Update target commitish and publish release
75+
uses: './.github/actions/update-target-commitish'
76+
with:
77+
github_token: ${{ secrets.GITHUB_TOKEN }}
78+
release_id: ${{ steps.latest_prerelease.outputs.id }}
79+
target_commitish: "refs/heads/master"
80+
tag_name: ${{ steps.latest_prerelease.outputs.tag_name }}

scripts/update-release.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@ def main():
6363
else:
6464
assert False, "Unhandled option"
6565

66+
if not version:
67+
usage()
68+
sys.exit(2)
69+
6670
version_number = version[1:] if "v" in version else version
6771
replace_version_on_setup_py(version_number)
6872
replace_version_on_config_py(version_number)

0 commit comments

Comments
 (0)