Skip to content

Commit 699526a

Browse files
committed
Update release workflows
1 parent 9262f5c commit 699526a

File tree

3 files changed

+86
-10
lines changed

3 files changed

+86
-10
lines changed

.github/workflows/build.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ on:
44
push:
55
branches:
66
- main
7+
tags:
8+
- 'v*'
79
pull_request:
810
branches:
911
- main
@@ -51,3 +53,28 @@ jobs:
5153
- name: Tear down docker containers
5254
run: |
5355
docker rm -f rosbridge
56+
publish-release:
57+
name: build and deploy docs
58+
runs-on: ubuntu-latest
59+
steps:
60+
- uses: actions/checkout@v2
61+
- name: Set up Python 3.8
62+
uses: actions/setup-python@v2
63+
with:
64+
python-version: 3.8
65+
- name: 🔗 Install dependencies
66+
run: |
67+
python -m pip install --upgrade pip
68+
python -m pip install wheel
69+
- name: 💎 Install
70+
run: |
71+
python -m pip install --no-cache-dir -r requirements-dev.txt
72+
- name: 💃 Build release
73+
if: success() && startsWith(github.ref, 'refs/tags')
74+
run: |
75+
python setup.py clean --all sdist bdist_wheel
76+
- name: 📦 Publish release to PyPI
77+
if: success() && startsWith(github.ref, 'refs/tags')
78+
uses: pypa/gh-action-pypi-publish@master
79+
with:
80+
password: ${{ secrets.pypi_password }}

.github/workflows/pr-checks.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
name: verify-pr-checklist
2+
on:
3+
pull_request:
4+
types: [assigned, opened, synchronize, reopened, labeled, unlabeled]
5+
branches:
6+
- main
7+
- master
8+
9+
jobs:
10+
build:
11+
name: Check Actions
12+
runs-on: ubuntu-latest
13+
steps:
14+
- uses: actions/checkout@v1
15+
- name: Changelog check
16+
uses: Zomzog/[email protected]
17+
with:
18+
fileName: CHANGELOG.rst
19+
env:
20+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

tasks.py

Lines changed: 39 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -133,28 +133,57 @@ def test(ctx, checks=True):
133133

134134
ctx.run('pytest --doctest-modules')
135135

136+
137+
@task
138+
def prepare_changelog(ctx):
139+
"""Prepare changelog for next release."""
140+
UNRELEASED_CHANGELOG_TEMPLATE = '\nUnreleased\n----------\n\n**Added**\n\n**Changed**\n\n**Fixed**\n\n**Deprecated**\n\n**Removed**\n'
141+
142+
with chdir(BASE_FOLDER):
143+
# Preparing changelog for next release
144+
with open('CHANGELOG.rst', 'r+') as changelog:
145+
content = changelog.read()
146+
start_index = content.index('----------')
147+
start_index = content.rindex('\n', 0, start_index - 1)
148+
last_version = content[start_index:start_index + 11].strip()
149+
150+
if last_version == 'Unreleased':
151+
log.write('Already up-to-date')
152+
return
153+
154+
changelog.seek(0)
155+
changelog.write(content[0:start_index] + UNRELEASED_CHANGELOG_TEMPLATE + content[start_index:])
156+
157+
ctx.run('git add CHANGELOG.rst && git commit -m "Prepare changelog for next release"')
158+
159+
136160
@task(help={
137161
'release_type': 'Type of release follows semver rules. Must be one of: major, minor, patch.'})
138162
def release(ctx, release_type):
139163
"""Releases the project in one swift command!"""
140164
if release_type not in ('patch', 'minor', 'major'):
141165
raise Exit('The release type parameter is invalid.\nMust be one of: major, minor, patch')
142166

167+
# Run checks
168+
ctx.run('invoke check test')
169+
170+
# Bump version and git tag it
143171
ctx.run('bump2version %s --verbose' % release_type)
144-
ctx.run('invoke docs test')
172+
173+
# Build project
145174
ctx.run('python setup.py clean --all sdist bdist_wheel')
146175

147-
if confirm('You are about to upload the release to pypi.org. Are you sure? [y/N]'):
148-
files = ['dist/*.whl', 'dist/*.gz', 'dist/*.zip']
149-
dist_files = ' '.join([pattern for f in files for pattern in glob.glob(f)])
176+
# Prepare changelog for next release
177+
prepare_changelog(ctx)
150178

151-
if len(dist_files):
152-
ctx.run('twine upload --skip-existing %s' % dist_files)
153-
else:
154-
raise Exit('No files found to release')
155-
else:
156-
raise Exit('Aborted release')
179+
# Clean up local artifacts
180+
clean(ctx)
157181

182+
# Upload to pypi
183+
if confirm('Everything is ready. You are about to push to git which will trigger a release to pypi.org. Are you sure? [y/N]'):
184+
ctx.run('git push --tags && git push')
185+
else:
186+
raise Exit('You need to manually revert the tag/commits created.')
158187

159188

160189
@contextlib.contextmanager

0 commit comments

Comments
 (0)