-
Notifications
You must be signed in to change notification settings - Fork 0
109 lines (96 loc) · 3.58 KB
/
Copy pathrelease.yml
File metadata and controls
109 lines (96 loc) · 3.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
name: Release
# Trigger when version files are modified or via manual dispatch
on:
push:
# Only trigger when the two files that declare the package version are changed
paths:
- 'pyproject.toml'
- 'src/quanteval/__init__.py'
workflow_dispatch:
inputs:
dry_run:
description: 'If "true", publish to TestPyPI (requires TEST_PYPI_TOKEN).'
required: false
default: 'false'
permissions:
contents: write
packages: write
# allow creating tags/releases
id-token: write
jobs:
release:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.13'
cache: pip
- name: Check version bump in pyproject.toml and __init__.py
id: check
env:
GITHUB_BEFORE: ${{ github.event.before }}
GITHUB_AFTER: ${{ github.sha }}
run: |
set -euo pipefail
python .github/scripts/check_version_bump.py
- name: Stop if not a release commit
if: ${{ steps.check.outputs.should_release == 'false' }}
run: |
echo "No version bump detected or versions do not match; skipping release."
exit 0
- name: Create tag for release
if: ${{ steps.check.outputs.should_release == 'true' }}
env:
VERSION: ${{ steps.check.outputs.version }}
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
TAG=v${VERSION}
# avoid error if tag already exists
if git rev-parse "$TAG" >/dev/null 2>&1; then
echo "Tag $TAG already exists, skipping tag creation."
else
git tag -a "$TAG" -m "Release $TAG"
git push origin "$TAG"
fi
- name: Install build dependencies
if: ${{ steps.check.outputs.should_release == 'true' }}
run: |
python -m pip install --upgrade pip
python -m pip install -e ".[dev]"
- name: Build release artifacts
if: ${{ steps.check.outputs.should_release == 'true' }}
run: python -m build
- name: Validate artifacts
if: ${{ steps.check.outputs.should_release == 'true' }}
run: twine check dist/*
- name: Publish to TestPyPI (dry-run)
if: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.dry_run == 'true' && steps.check.outputs.should_release == 'true' }}
run: |
python -m pip install --upgrade pip
python -m pip install twine
twine upload --repository-url https://test.pypi.org/legacy/ dist/* -u __token__ -p ${{ secrets.TEST_PYPI_TOKEN }} --skip-existing --verbose
- name: Publish to PyPI
if: ${{ steps.check.outputs.should_release == 'true' && !(github.event_name == 'workflow_dispatch' && github.event.inputs.dry_run == 'true') }}
uses: pypa/gh-action-pypi-publish@v1.5.0
with:
skip-existing: true
verbose: true
user: __token__
password: ${{ secrets.PYPI_TOKEN }}
- name: Create GitHub release
if: ${{ steps.check.outputs.should_release == 'true' }}
uses: softprops/action-gh-release@v2
env:
GITHUB_TOKEN: ${{ secrets.RELEASE_TOKEN }}
with:
tag_name: v${{ steps.check.outputs.version }}
name: Release v${{ steps.check.outputs.version }}
generate_release_notes: true
files: |
dist/*