-
Notifications
You must be signed in to change notification settings - Fork 0
86 lines (73 loc) · 2.81 KB
/
Copy pathrelease.yml
File metadata and controls
86 lines (73 loc) · 2.81 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
name: Release
on:
push:
branches: [master]
paths:
- "src/quanteval/__init__.py"
- "pyproject.toml"
workflow_dispatch:
inputs:
dry_run:
description: 'If "true", publish to TestPyPI (requires TEST_PYPI_TOKEN).'
required: false
default: "false"
permissions:
contents: write
packages: write
jobs:
release:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Check if both version files were changed
id: check_versions
run: |
if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
echo "changed=true" >> $GITHUB_OUTPUT
else
# Compare with the previous commit to check if both files changed
git diff --name-only HEAD~1 | grep -E "src/quanteval/__init__.py|pyproject.toml" > /tmp/changes.txt
INIT_CHANGED=$(grep "src/quanteval/__init__.py" /tmp/changes.txt || echo "")
PYPROJECT_CHANGED=$(grep "pyproject.toml" /tmp/changes.txt || echo "")
if [[ -n "$INIT_CHANGED" && -n "$PYPROJECT_CHANGED" ]]; then
echo "changed=true" >> $GITHUB_OUTPUT
else
echo "changed=false" >> $GITHUB_OUTPUT
echo "⚠️ Release skipped: Both 'src/quanteval/__init__.py' and 'pyproject.toml' must be modified in the same commit."
fi
fi
- name: Cancel if versions were not both changed
if: steps.check_versions.outputs.changed == 'false' && github.event_name != 'workflow_dispatch'
run: |
echo "::error::Release cancelled: Both version files must be updated together"
exit 1
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.13"
cache: pip
- name: Install build dependencies
run: |
python -m pip install --upgrade pip
python -m pip install -e ".[dev]"
- name: Build release artifacts
run: python -m build
- name: Validate artifacts
run: twine check dist/*
- name: Publish to TestPyPI (dry-run)
if: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.dry_run == '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: ${{ !(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 }}