Skip to content

Add workflow to release SDMetrics on PyPI #784

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Jul 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ on:
pull_request:
types: [opened, reopened]

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
lint:
runs-on: ubuntu-latest
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/readme.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ on:
pull_request:
types: [opened, reopened]

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
readme:
runs-on: ${{ matrix.os }}
Expand Down
81 changes: 81 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
name: Release
on:
release:
types: [published]
branches:
- main
- stable

workflow_dispatch:
inputs:
candidate:
description: 'Release candidate.'
required: true
type: boolean
default: true
test_pypi:
description: 'Test PyPI.'
type: boolean
default: false
jobs:
release:
runs-on: ubuntu-latest
permissions:
id-token: write
steps:
- uses: actions/checkout@v4
with:
ref: ${{ inputs.candidate && 'main' || 'stable' }}

- name: Set up latest Python
uses: actions/setup-python@v5
with:
python-version-file: 'pyproject.toml'

- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install .[dev]

- name: Create wheel
run: |
make dist

- name: Publish a Python distribution to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
repository-url: ${{ inputs.test_pypi && 'https://test.pypi.org/legacy/' || 'https://upload.pypi.org/legacy/' }}

- name: Bump version to next candidate
if: ${{ inputs.candidate && !inputs.test_pypi }}
run: |
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
bump-my-version bump candidate --no-tag --no-commit

- name: Create pull request
if: ${{ inputs.candidate && !inputs.test_pypi }}
id: cpr
uses: peter-evans/create-pull-request@v4
with:
token: ${{ secrets.GH_ACCESS_TOKEN }}
commit-message: bumpversion-candidate
committer: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
author: ${{ github.actor }} <${{ github.actor_id }}+${{ github.actor }}@users.noreply.github.com>
signoff: false
delete-branch: true
title: Automated Bump Version Candidate
body: "This is an auto-generated PR that bumps the version to the next candidate."
branch: bumpversion-candidate-update
branch-suffix: short-commit-hash
add-paths: |
sdmetrics/__init__.py
pyproject.toml
draft: false
base: main

- name: Enable Pull Request Automerge
if: ${{ steps.cpr.outputs.pull-request-operation == 'created' }}
run: gh pr merge "${{ steps.cpr.outputs.pull-request-number }}" --squash --admin
env:
GH_TOKEN: ${{ secrets.GH_ACCESS_TOKEN }}
67 changes: 34 additions & 33 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ clean-coverage: ## remove coverage artifacts

.PHONY: clean-test
clean-test: ## remove test artifacts
rm -fr .tox/
rm -fr .pytest_cache

.PHONY: clean
Expand All @@ -76,6 +75,9 @@ install-test: clean-build clean-pyc ## install the package and test dependencies
install-develop: clean-build clean-pyc ## install the package in editable mode and dependencies for development
pip install -e .[dev]

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

# LINT TARGETS

Expand Down Expand Up @@ -105,12 +107,8 @@ test-readme: ## run the readme snippets
.PHONY: test
test: test-unit test-integration test-readme ## test everything that needs test dependencies

.PHONY: test-devel
test-devel: lint ## test everything that needs development dependencies

.PHONY: test-all
test-all: ## run tests on every Python version with tox
tox -r
.PHONY: test-repo
test-repo: lint test-unit test-integration test-readme test-performance ## test everything

.PHONY: coverage
coverage: ## check code coverage quickly with the default Python
Expand Down Expand Up @@ -142,26 +140,31 @@ publish-test: dist publish-confirm ## package and upload a release on TestPyPI
publish: dist publish-confirm ## package and upload a release
twine upload dist/*

.PHONY: bumpversion-release
bumpversion-release: ## Merge main to stable and bumpversion release
.PHONY: git-merge-main-stable
git-merge-main-stable: ## Merge main into stable
git checkout stable || git checkout -b stable
git merge --no-ff main -m"make release-tag: Merge branch 'main' into stable"
bump-my-version bump release

.PHONY: git-merge-stable-main
git-merge-stable-main: ## Merge stable into main
git checkout main
git merge stable

.PHONY: git-push
git-push: ## Simply push the repository to github
git push

.PHONY: git-push-tags-stable
git-push-tags-stable: ## Push tags and stable to github
git push --tags origin stable

.PHONY: bumpversion-release-test
bumpversion-release-test: ## Merge main to stable and bumpversion release
git checkout stable || git checkout -b stable
git merge --no-ff main -m"make release-tag: Merge branch 'main' into stable"
.PHONY: bumpversion-release
bumpversion-release: ## Bump the version to the next release
bump-my-version bump release --no-tag
@echo git push --tags origin stable

.PHONY: bumpversion-patch
bumpversion-patch: ## Merge stable to main and bumpversion patch
git checkout main
git merge stable
bumpversion-patch: ## Bump the version to the next patch
bump-my-version bump --no-tag patch
git push

.PHONY: bumpversion-candidate
bumpversion-candidate: ## Bump the version to the next candidate
Expand All @@ -177,11 +180,13 @@ bumpversion-major: ## Bump the version the next major skipping the release

.PHONY: bumpversion-revert
bumpversion-revert: ## Undo a previous bumpversion-release
git tag --delete $(shell git tag --points-at HEAD)
git checkout main
git branch -D stable

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

.PHONY: check-clean
Expand All @@ -196,6 +201,12 @@ ifneq ($(CURRENT_BRANCH),main)
$(error Please make the release from main branch\n)
endif

.PHONY: check-candidate
check-candidate: ## Check if a release candidate has been made
ifeq ($(CURRENT_VERSION),dev0)
$(error Please make a release candidate and test it before atempting a release)
endif

.PHONY: check-history
check-history: ## Check if HISTORY.md has been modified
ifeq ($(CHANGELOG_LINES),0)
Expand All @@ -207,32 +218,22 @@ check-deps: # Dependency targets
$(eval allow_list='numpy=|pandas=|scikit-learn=|scipy=|tqdm=|plotly=|copulas=')
pip freeze | grep -v "SDMetrics.git" | grep -E $(allow_list) | sort > $(OUTPUT_FILEPATH)

.PHONY: git-push
git-push: ## Simply push the repository to github
git push

.PHONY: check-release
check-release: check-clean check-main check-history ## Check if the release can be made
check-release: check-clean check-candidate check-main check-history ## Check if the release can be made
@echo "A new release can be made"

.PHONY: release
release: check-release bumpversion-release publish bumpversion-patch
release: check-release git-merge-main-stable bumpversion-release git-push-tags-stable \
git-merge-stable-main bumpversion-patch git-push

.PHONY: release-test
release-test: check-release bumpversion-release-test publish-test bumpversion-revert
release-test: check-release git-merge-main-stable bumpversion-release bumpversion-revert

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

.PHONY: release-candidate-test
release-candidate-test: check-clean check-main publish-test

.PHONY: release-minor
release-minor: check-release bumpversion-minor release

.PHONY: release-major
release-major: check-release bumpversion-major release

# Packaging Targets
.PHONY: upgradepip
upgradepip:
Expand Down
Loading
Loading