-
Notifications
You must be signed in to change notification settings - Fork 15
157 lines (150 loc) · 4.78 KB
/
release.yml
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
145
146
147
148
149
150
151
152
153
154
155
156
157
name: Release
on:
push:
pull_request:
jobs:
build:
name: Build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
- name: Install build
run: pip install build
- name: Build distribution
run: python -m build .
- name: File list
run: tar tf dist/*.tar.gz && unzip -l dist/*.whl
- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: dist
path: dist/
test:
name: Run tests
needs: build
strategy:
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12", "3.13.0-rc.1"]
os: [ubuntu-latest, macos-13, macos-latest, windows-latest]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Download artifacts
uses: actions/download-artifact@v4
- name: Install wheel
shell: bash
run: pip install dist/*.whl
- name: Make it use package from wheel
shell: bash
run: rm flask_shell_ipython.py
- name: Install test requirements
run: pip install -r requirements-test.txt
- name: Test
if: runner.os != 'Windows'
run: pytest --forked
- name: Test (Windows)
if: runner.os == 'Windows'
shell: bash
run: pytest --collect-only -q | grep ^test_ | while read testname; do pytest -q $testname; done
pypi-publish-test:
name: Release on Test PyPI
needs: test
runs-on: ubuntu-latest
environment:
name: Test PyPI
url: "https://test.pypi.org/project/flask-shell-ipython/"
permissions:
id-token: write
steps:
- name: Download artifacts
uses: actions/download-artifact@v4
- name: Publish package distributions to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
repository-url: "https://test.pypi.org/legacy/"
github-release:
name: Release on GitHub
needs: test
if: github.event_name == 'push' && startsWith(github.ref, 'refs/heads/test-v')
runs-on: ubuntu-latest
environment:
name: GitHub
url: "https://github.com/ei-grad/flask-shell-ipython/releases/"
permissions:
attestations: write
contents: write
id-token: write
steps:
- uses: actions/checkout@v4
- name: Extract Version from Tag
run: echo "VERSION_FROM_GIT_REF=${GITHUB_REF#refs/heads/test-v}" >> $GITHUB_ENV
- name: Extract Version from pyproject.toml
run: |
pip install toml
VERSION_FROM_PYPROJECT=$(python << EOF
import toml
print(toml.load('pyproject.toml')['project']['version'])
EOF
)
echo "VERSION_FROM_PYPROJECT=$VERSION_FROM_PYPROJECT" >> $GITHUB_ENV
- name: Ensure version consistency
run: |
if [ "$VERSION_FROM_GIT_REF" != "$VERSION_FROM_PYPROJECT" ]; then
echo "Error: Version from tag ($VERSION_FROM_GIT_REF) does not match version in pyproject.toml ($VERSION_FROM_PYPROJECT)"
exit 1
fi
echo VERSION=$VERSION_FROM_GIT_REF >> $GITHUB_ENV
- name: Extract changelog for release notes
run: |
(
echo "CHANGELOG<<EOF"
awk -v version="$VERSION" '{
if ($0 ~ "^## \\[" version "\\]") inSection = 1;
else if ($0 ~ "^## \\[" && inSection) inSection = 0;
if (inSection) print $0;
}' CHANGELOG.md
echo "EOF"
) >> $GITHUB_ENV
- name: Validate changelog content
run: |
if [ -z "$CHANGELOG" ] ; then
echo "Missing CHANGELOG.md section for release $VERSION"
exit 1
fi
- name: Download artifacts
uses: actions/download-artifact@v4
- name: Attest build provenance
uses: actions/attest-build-provenance@v1
with:
subject-path: dist/*
- name: Create GitHub Release
env:
GITHUB_TOKEN: ${{ github.token }}
run: >-
gh release create "$VERSION"
--draft
--notes "$CHANGELOG"
- name: Upload artifact signatures to GitHub Release
env:
GITHUB_TOKEN: ${{ github.token }}
run: >-
gh release upload "$VERSION" dist/**
pypi-publish:
name: Release on PyPI
needs: github-release
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v')
runs-on: ubuntu-latest
environment:
name: PyPI
url: "https://pypi.org/project/flask-shell-ipython/"
permissions:
id-token: write
steps:
- name: Download artifacts
uses: actions/download-artifact@v4
- name: Publish package distributions to PyPI
uses: pypa/gh-action-pypi-publish@release/v1