-
Notifications
You must be signed in to change notification settings - Fork 1
144 lines (124 loc) · 4.4 KB
/
release.yml
File metadata and controls
144 lines (124 loc) · 4.4 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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
name: Release
on:
workflow_dispatch:
inputs:
version:
description: 'Version to release (e.g. 0.1.0)'
required: true
permissions:
contents: write
packages: write
concurrency:
group: release
cancel-in-progress: false
jobs:
build-and-testpypi:
name: Build package and publish to TestPyPI
runs-on: ubuntu-latest
environment:
name: testpypi-release
outputs:
version: ${{ steps.validate-version.outputs.version }}
steps:
- name: Check out repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Python 3.11
uses: actions/setup-python@v5
with:
python-version: '3.11'
- name: Validate version input
id: validate-version
run: |
VERSION_INPUT="${{ inputs.version }}"
VERSION_FILE=$(python -c "import pathlib, re, sys; text = pathlib.Path('setup.py').read_text(); match = re.search(r\"version\\s*=\\s*[\\\"\\']([^\\\"\\']+)[\\\"\\']\", text); sys.stdout.write(match.group(1) if match else sys.exit('Could not find version in setup.py'))")
echo "Detected version: $VERSION_FILE"
if [ "$VERSION_INPUT" != "$VERSION_FILE" ]; then
echo "::error::Input version '$VERSION_INPUT' does not match setup.py version '$VERSION_FILE'"
exit 1
fi
echo "version=$VERSION_FILE" >> "$GITHUB_OUTPUT"
- name: Install build dependencies
run: |
python -m pip install --upgrade pip
pip install build twine wheel
- name: Clean previous build artifacts
run: |
rm -rf build dist pnpl.egg-info
- name: Build distribution artifacts
run: |
python -m build
twine check dist/*
- name: Publish to TestPyPI
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.TEST_PYPI_API_TOKEN }}
run: |
python -m twine upload --repository-url https://test.pypi.org/legacy/ --non-interactive dist/*
- name: Smoke test install from TestPyPI
env:
PACKAGE_VERSION: ${{ steps.validate-version.outputs.version }}
run: |
python -m venv /tmp/testpypi-venv
source /tmp/testpypi-venv/bin/activate
pip install --upgrade pip
pip install --index-url https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple "pnpl==$PACKAGE_VERSION"
- name: Upload built artifacts
uses: actions/upload-artifact@v4
with:
name: pnpl-dist-${{ steps.validate-version.outputs.version }}
path: dist/*
if-no-files-found: error
publish-production:
name: Tag release, publish to PyPI, and create GitHub release
needs: build-and-testpypi
runs-on: ubuntu-latest
environment:
name: pypi-release
steps:
- name: Check out repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Configure Git
run: |
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
- name: Create and push tag
env:
VERSION: ${{ needs.build-and-testpypi.outputs.version }}
run: |
if git rev-parse "v$VERSION" >/dev/null 2>&1; then
echo "::error::Tag v$VERSION already exists"
exit 1
fi
git tag "v$VERSION" "$GITHUB_SHA"
git push origin "v$VERSION"
- name: Download built artifacts
uses: actions/download-artifact@v4
with:
name: pnpl-dist-${{ needs.build-and-testpypi.outputs.version }}
path: dist
- name: Set up Python 3.11
uses: actions/setup-python@v5
with:
python-version: '3.11'
- name: Install upload dependencies
run: |
python -m pip install --upgrade pip
pip install twine
- name: Publish to PyPI
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }}
run: |
python -m twine upload --non-interactive dist/*
- name: Create GitHub release
uses: ncipollo/release-action@v1
with:
tag: v${{ needs.build-and-testpypi.outputs.version }}
name: v${{ needs.build-and-testpypi.outputs.version }}
artifacts: "dist/*"
generateReleaseNotes: true
draft: false