Skip to content

Commit 7cd64ad

Browse files
gshenirwedge
andauthored
Add workflow to release SDGym on PyPI (#421)
Co-authored-by: Roy Wedge <[email protected]>
1 parent a945aa8 commit 7cd64ad

File tree

7 files changed

+239
-29
lines changed

7 files changed

+239
-29
lines changed

.github/workflows/lint.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ on:
55
pull_request:
66
types: [opened, reopened]
77

8+
concurrency:
9+
group: ${{ github.workflow }}-${{ github.ref }}
10+
cancel-in-progress: true
11+
812
jobs:
913
lint:
1014
runs-on: ubuntu-latest

.github/workflows/readme.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ on:
55
pull_request:
66
types: [opened, reopened]
77

8+
concurrency:
9+
group: ${{ github.workflow }}-${{ github.ref }}
10+
cancel-in-progress: true
11+
812
jobs:
913
readme:
1014
runs-on: ${{ matrix.os }}

.github/workflows/release.yml

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
name: Release
2+
on:
3+
release:
4+
types: [published]
5+
branches:
6+
- main
7+
- stable
8+
9+
workflow_dispatch:
10+
inputs:
11+
candidate:
12+
description: 'Release candidate.'
13+
required: true
14+
type: boolean
15+
default: true
16+
test_pypi:
17+
description: 'Test PyPI.'
18+
type: boolean
19+
default: false
20+
jobs:
21+
release:
22+
runs-on: ubuntu-latest
23+
permissions:
24+
id-token: write
25+
steps:
26+
- uses: actions/checkout@v4
27+
with:
28+
ref: ${{ inputs.candidate && 'main' || 'stable' }}
29+
30+
- name: Set up latest Python
31+
uses: actions/setup-python@v5
32+
with:
33+
python-version-file: 'pyproject.toml'
34+
35+
- name: Install dependencies
36+
run: |
37+
python -m pip install --upgrade pip
38+
python -m pip install .[dev]
39+
40+
- name: Create wheel
41+
run: |
42+
make dist
43+
44+
- name: Publish a Python distribution to PyPI
45+
uses: pypa/gh-action-pypi-publish@release/v1
46+
with:
47+
repository-url: ${{ inputs.test_pypi && 'https://test.pypi.org/legacy/' || 'https://upload.pypi.org/legacy/' }}
48+
49+
- name: Bump version to next candidate
50+
if: ${{ inputs.candidate && !inputs.test_pypi }}
51+
run: |
52+
git config user.name "github-actions[bot]"
53+
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
54+
bump-my-version bump candidate --no-tag --no-commit
55+
56+
- name: Create pull request
57+
if: ${{ inputs.candidate && !inputs.test_pypi }}
58+
id: cpr
59+
uses: peter-evans/create-pull-request@v4
60+
with:
61+
token: ${{ secrets.GH_ACCESS_TOKEN }}
62+
commit-message: bumpversion-candidate
63+
committer: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
64+
author: ${{ github.actor }} <${{ github.actor_id }}+${{ github.actor }}@users.noreply.github.com>
65+
signoff: false
66+
delete-branch: true
67+
title: Automated Bump Version Candidate
68+
body: "This is an auto-generated PR that bumps the version to the next candidate."
69+
branch: bumpversion-candidate-update
70+
branch-suffix: short-commit-hash
71+
add-paths: |
72+
sdgym/__init__.py
73+
pyproject.toml
74+
draft: false
75+
base: main
76+
77+
- name: Enable Pull Request Automerge
78+
if: ${{ steps.cpr.outputs.pull-request-operation == 'created' }}
79+
run: gh pr merge "${{ steps.cpr.outputs.pull-request-number }}" --squash --admin
80+
env:
81+
GH_TOKEN: ${{ secrets.GH_ACCESS_TOKEN }}

Makefile

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ clean-coverage: ## remove coverage artifacts
5555

5656
.PHONY: clean-test
5757
clean-test: ## remove test artifacts
58-
rm -fr .tox/
5958
rm -fr .pytest_cache
6059

6160
.PHONY: clean
@@ -76,6 +75,10 @@ install-test: clean-build clean-compile clean-pyc compile ## install the package
7675
install-develop: clean-build clean-pyc clean-pyc ## install the package in editable mode and dependencies for development
7776
pip install -e .[dev]
7877

78+
.PHONY: install-readme
79+
install-readme: clean-build clean-pyc ## install the package in editable mode and readme dependencies for developement
80+
pip install -e .[readme]
81+
7982
# LINT TARGETS
8083

8184
.PHONY: lint
@@ -104,10 +107,6 @@ test: test-unit test-readme ## test everything that needs test dependencies
104107
.PHONY: test-devel
105108
test-devel: lint ## test everything that needs development dependencies
106109

107-
.PHONY: test-all
108-
test-all: ## test using tox
109-
tox -r
110-
111110
.PHONY: coverage
112111
coverage: ## check code coverage quickly with the default Python
113112
coverage run --source sdgym -m pytest
@@ -158,7 +157,7 @@ git-push-tags-stable: ## Push tags and stable to github
158157

159158
.PHONY: bumpversion-release
160159
bumpversion-release: ## Bump the version to the next release
161-
bump-my-version bump release
160+
bump-my-version bump release --no-tag
162161

163162
.PHONY: bumpversion-patch
164163
bumpversion-patch: ## Bump the version to the next patch
@@ -223,7 +222,7 @@ check-release: check-clean check-candidate check-main check-history ## Check if
223222

224223
.PHONY: release
225224
release: check-release git-merge-main-stable bumpversion-release git-push-tags-stable \
226-
publish git-merge-stable-main bumpversion-patch git-push
225+
git-merge-stable-main bumpversion-patch git-push
227226

228227
.PHONY: release-test
229228
release-test: check-release git-merge-main-stable bumpversion-release bumpversion-revert
@@ -232,4 +231,4 @@ release-test: check-release git-merge-main-stable bumpversion-release bumpversio
232231
release-candidate: check-main publish bumpversion-candidate git-push
233232

234233
.PHONY: release-candidate-test
235-
release-candidate-test: check-clean check-main publish-test
234+
release-candidate-test: check-clean check-main publish-test

RELEASE.md

Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
# Release workflow
2+
3+
The process of releasing a new version involves several steps:
4+
5+
1. [Install SDGym from source](#install-sdgym-from-source)
6+
7+
2. [Linting and tests](#linting-and-tests)
8+
9+
3. [Make a release candidate](#make-a-release-candidate)
10+
11+
4. [Milestone](#milestone)
12+
13+
5. [Update HISTORY](#update-history)
14+
15+
6. [Check the release](#check-the-release)
16+
17+
7. [Update stable branch and bump version](#update-stable-branch-and-bump-version)
18+
19+
8. [Create the Release on GitHub](#create-the-release-on-github)
20+
21+
9. [Close milestone and create new milestone](#close-milestone-and-create-new-milestone)
22+
23+
## Install SDGym from source
24+
25+
Clone the project and install the development requirements before starting the release process. Alternatively, with your virtualenv activated:
26+
27+
```bash
28+
git clone https://github.com/sdv-dev/SDGym.git
29+
cd SDGym
30+
git checkout main
31+
make install-develop
32+
```
33+
34+
## Linting and tests
35+
36+
Execute the tests and linting. The tests must end with no errors:
37+
38+
```bash
39+
make test && make lint
40+
```
41+
42+
And you will see something like this:
43+
44+
```
45+
Coverage XML written to file ./integration_cov.xml
46+
============ 242 passed, 166 warnings, 134 subtests passed in 9.88s ============
47+
....
48+
invoke lint
49+
No broken requirements found.
50+
All checks passed!
51+
80 files already formatted
52+
```
53+
54+
The execution has finished with no errors, 0 test skipped and 166 warnings.
55+
56+
## Make a release candidate
57+
58+
1. On the SDGym GitHub page, navigate to the [Actions][actions] tab.
59+
2. Select the `Release` action.
60+
3. Run it on the main branch. Make sure `Release candidate` is checked and `Test PyPI` is not.
61+
4. Check on [PyPI][sdgym-pypi] to assure the release candidate was successfully uploaded.
62+
- You should see X.Y.ZdevN PRE-RELEASE
63+
64+
[actions]: https://github.com/sdv-dev/SDGym/actions
65+
[sdgym-pypi]: https://pypi.org/project/SDGym/#history
66+
67+
## Milestone
68+
69+
It's important to check that the GitHub and milestone issues are up to date with the release.
70+
71+
You neet to check that:
72+
73+
- The milestone for the current release exists.
74+
- All the issues closed since the latest release are associated to the milestone. If they are not, associate them.
75+
- All the issues associated to the milestone are closed. If there are open issues but the milestone needs to
76+
be released anyway, move them to the next milestone.
77+
- All the issues in the milestone are assigned to at least one person.
78+
- All the pull requests closed since the latest release are associated to an issue. If necessary, create issues
79+
and assign them to the milestone. Also assign the person who opened the issue to them.
80+
81+
## Update HISTORY
82+
Run the [Release Prep](https://github.com/sdv-dev/SDGym/actions/workflows/prepare_release.yml) workflow. This workflow will create a pull request with updates to HISTORY.md
83+
84+
Make sure HISTORY.md is updated with the issues of the milestone:
85+
86+
```
87+
# History
88+
89+
## X.Y.Z (YYYY-MM-DD)
90+
91+
### New Features
92+
93+
* <ISSUE TITLE> - [Issue #<issue>](https://github.com/sdv-dev/SDGym/issues/<issue>) by @resolver
94+
95+
### General Improvements
96+
97+
* <ISSUE TITLE> - [Issue #<issue>](https://github.com/sdv-dev/SDGym/issues/<issue>) by @resolver
98+
99+
### Bug Fixed
100+
101+
* <ISSUE TITLE> - [Issue #<issue>](https://github.com/sdv-dev/SDGym/issues/<issue>) by @resolver
102+
```
103+
104+
The issue list per milestone can be found [here][milestones].
105+
106+
[milestones]: https://github.com/sdv-dev/SDGym/milestones
107+
108+
Put the pull request up for review and get 2 approvals to merge into `main`.
109+
110+
## Check the release
111+
Once HISTORY.md has been updated on `main`, check if the release can be made:
112+
113+
```bash
114+
make check-release
115+
```
116+
117+
## Update stable branch and bump version
118+
The `stable` branch needs to be updated with the changes from `main` and the version needs to be bumped.
119+
Depending on the type of release, run one of the following:
120+
121+
* `make release`: This will release a patch, which is the most common type of release. Use this when the changes are bugfixes or enhancements that do not modify the existing user API. Changes that modify the user API to add new features but that do not modify the usage of the previous features can also be released as a patch.
122+
* `make release-minor`: This will release the next minor version. Use this if the changes modify the existing user API in any way, even if it is backwards compatible. Minor backwards incompatible changes can also be released as minor versions while the library is still in beta state. After the major version 1 has been released, minor version can only be used to add backwards compatible API changes.
123+
* `make release-major`: This will release the next major version. Use this to if the changes modify the user API in a backwards incompatible way after the major version 1 has been released.
124+
125+
Running one of these will **push commits directly** to `main`.
126+
At the end, you should see the 3 commits on `main` (from oldest to newest):
127+
- `make release-tag: Merge branch 'main' into stable`
128+
- `Bump version: X.Y.Z.devN → X.Y.Z`
129+
- `Bump version: X.Y.Z -> X.Y.A.dev0`
130+
131+
## Create the Release on GitHub
132+
133+
After the update to HISTORY.md is merged into `main` and the version is bumped, it is time to [create the release GitHub](https://github.com/sdv-dev/SDGym/releases/new).
134+
- Create a new tag with the version number with a v prefix (e.g. v0.3.1)
135+
- The target should be the `stable` branch
136+
- Release title is the same as the tag (e.g. v0.3.1)
137+
- This is not a pre-release (`Set as a pre-release` should be unchecked)
138+
139+
Click `Publish release`, which will kickoff the release workflow and automatically upload the package to [public PyPI](https://pypi.org/project/sdgym/).
140+
141+
## Close milestone and create new milestone
142+
143+
Finaly, **close the milestone** and, if it does not exist, **create the next milestone**.

pyproject.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,6 @@ dev = [
102102

103103
# Advanced testing
104104
'coverage>=4.5.12,<8',
105-
'tox>=2.9.1,<5',
106105
'importlib-metadata>=3.6',
107106

108107
# Invoke

tox.ini

Lines changed: 0 additions & 20 deletions
This file was deleted.

0 commit comments

Comments
 (0)