Skip to content

Commit d49d437

Browse files
gshenirwedge
andauthored
Add workflow to release CTGAN on PyPI (#452)
Co-authored-by: Roy Wedge <[email protected]>
1 parent ab11db2 commit d49d437

File tree

8 files changed

+307
-58
lines changed

8 files changed

+307
-58
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+
ctgan/__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 }}

.gitignore

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
.github/.tmp/
2+
tests/readme_test/
3+
14
# Byte-compiled / optimized / DLL files
25
__pycache__/
36
*.py[cod]
@@ -104,5 +107,8 @@ ENV/
104107
# mypy
105108
.mypy_cache/
106109

110+
# other
111+
.DS_Store
112+
107113
# Vim
108-
.*.swp
114+
.*.swp

Makefile

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@ install-test: clean-build clean-pyc ## install the package and test dependencies
7676
install-develop: clean-build clean-pyc ## install the package in editable mode and dependencies for development
7777
pip install -e .[dev]
7878

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

8083
# LINT TARGETS
8184

@@ -87,7 +90,6 @@ lint:
8790
fix-lint:
8891
invoke fix-lint
8992

90-
9193
# TEST TARGETS
9294

9395
.PHONY: test-unit
@@ -112,10 +114,6 @@ test: test-unit test-integration test-readme ## test everything that needs test
112114
.PHONY: test-devel
113115
test-devel: lint ## test everything that needs development dependencies
114116

115-
.PHONY: test-all
116-
test-all: ## run tests on every Python version with tox
117-
tox -r
118-
119117

120118
.PHONY: coverage
121119
coverage: ## check code coverage quickly with the default Python
@@ -147,26 +145,31 @@ publish-test: dist publish-confirm ## package and upload a release on TestPyPI
147145
publish: dist publish-confirm ## package and upload a release
148146
twine upload dist/*
149147

150-
.PHONY: bumpversion-release
151-
bumpversion-release: ## Merge main to stable and bumpversion release
148+
.PHONY: git-merge-main-stable
149+
git-merge-main-stable: ## Merge main into stable
152150
git checkout stable || git checkout -b stable
153151
git merge --no-ff main -m"make release-tag: Merge branch 'main' into stable"
154-
bump-my-version bump release
152+
153+
.PHONY: git-merge-stable-main
154+
git-merge-stable-main: ## Merge stable into main
155+
git checkout main
156+
git merge stable
157+
158+
.PHONY: git-push
159+
git-push: ## Simply push the repository to github
160+
git push
161+
162+
.PHONY: git-push-tags-stable
163+
git-push-tags-stable: ## Push tags and stable to github
155164
git push --tags origin stable
156165

157-
.PHONY: bumpversion-release-test
158-
bumpversion-release-test: ## Merge main to stable and bumpversion release
159-
git checkout stable || git checkout -b stable
160-
git merge --no-ff main -m"make release-tag: Merge branch 'main' into stable"
166+
.PHONY: bumpversion-release
167+
bumpversion-release: ## Bump the version to the next release
161168
bump-my-version bump release --no-tag
162-
@echo git push --tags origin stable
163169

164170
.PHONY: bumpversion-patch
165-
bumpversion-patch: ## Merge stable to main and bumpversion patch
166-
git checkout main
167-
git merge stable
171+
bumpversion-patch: ## Bump the version to the next patch
168172
bump-my-version bump --no-tag patch
169-
git push
170173

171174
.PHONY: bumpversion-candidate
172175
bumpversion-candidate: ## Bump the version to the next candidate
@@ -182,11 +185,13 @@ bumpversion-major: ## Bump the version the next major skipping the release
182185

183186
.PHONY: bumpversion-revert
184187
bumpversion-revert: ## Undo a previous bumpversion-release
188+
git tag --delete $(shell git tag --points-at HEAD)
185189
git checkout main
186190
git branch -D stable
187191

188192
CLEAN_DIR := $(shell git status --short | grep -v ??)
189193
CURRENT_BRANCH := $(shell git rev-parse --abbrev-ref HEAD 2>/dev/null)
194+
CURRENT_VERSION := $(shell grep "^current_version" pyproject.toml | grep -o "dev[0-9]*")
190195
CHANGELOG_LINES := $(shell git diff HEAD..origin/stable HISTORY.md 2>&1 | wc -l)
191196

192197
.PHONY: check-clean
@@ -201,41 +206,36 @@ ifneq ($(CURRENT_BRANCH),main)
201206
$(error Please make the release from main branch\n)
202207
endif
203208

209+
.PHONY: check-candidate
210+
check-candidate: ## Check if a release candidate has been made
211+
ifeq ($(CURRENT_VERSION),dev0)
212+
$(error Please make a release candidate and test it before atempting a release)
213+
endif
214+
204215
.PHONY: check-history
205216
check-history: ## Check if HISTORY.md has been modified
206217
ifeq ($(CHANGELOG_LINES),0)
207218
$(error Please insert the release notes in HISTORY.md before releasing)
208219
endif
209220

210-
.PHONY: git-push
211-
git-push: ## Simply push the repository to github
212-
git push
221+
.PHONY: check-deps
222+
check-deps: # Dependency targets
223+
$(eval allow_list='numpy=|pandas=|tqdm=|torch=|rdt=')
224+
pip freeze | grep -v "CTGAN.git" | grep -E $(allow_list) > $(OUTPUT_FILEPATH)
213225

214226
.PHONY: check-release
215-
check-release: check-clean check-main check-history ## Check if the release can be made
227+
check-release: check-clean check-candidate check-main check-history ## Check if the release can be made
216228
@echo "A new release can be made"
217229

218230
.PHONY: release
219-
release: check-release bumpversion-release publish bumpversion-patch
231+
release: check-release git-merge-main-stable bumpversion-release git-push-tags-stable \
232+
git-merge-stable-main bumpversion-patch git-push
220233

221234
.PHONY: release-test
222-
release-test: check-release bumpversion-release-test publish-test bumpversion-revert
235+
release-test: check-release git-merge-main-stable bumpversion-release bumpversion-revert
223236

224237
.PHONY: release-candidate
225238
release-candidate: check-main publish bumpversion-candidate git-push
226239

227240
.PHONY: release-candidate-test
228-
release-candidate-test: check-clean check-main publish-test
229-
230-
.PHONY: release-minor
231-
release-minor: check-release bumpversion-minor release
232-
233-
.PHONY: release-major
234-
release-major: check-release bumpversion-major release
235-
236-
# Dependency targets
237-
238-
.PHONY: check-deps
239-
check-deps:
240-
$(eval allow_list='numpy=|pandas=|tqdm=|torch=|rdt=')
241-
pip freeze | grep -v "CTGAN.git" | grep -E $(allow_list) > $(OUTPUT_FILEPATH)
241+
release-candidate-test: check-clean check-main publish-test

0 commit comments

Comments
 (0)