Repository navigation
185 lines (161 loc) · 6.12 KB
/
Copy pathpython_release.yaml
File metadata and controls
185 lines (161 loc) · 6.12 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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
name: PyPI Publish
on:
workflow_dispatch:
jobs:
# A stable release tag must match the version in pyproject.toml and leave no unreleased
# changelog fragments. See python/changelog.d/README.md. Pre-release tags skip these checks.
preflight:
if: github.event_name == 'workflow_dispatch' && startsWith(github.ref, 'refs/tags')
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- uses: actions/checkout@v4
- name: Check release tag
run: |
tag_version="${GITHUB_REF_NAME#python/v}"
if [[ ! "$tag_version" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "Pre-release tag $GITHUB_REF_NAME. Skipping checks."
exit 0
fi
version=$(python3 python/scripts/release_version.py --current)
if [[ "$version" != "$tag_version" ]]; then
echo "Error: tag $GITHUB_REF_NAME does not match version $version in pyproject.toml"
exit 1
fi
if ! python3 python/scripts/release_version.py --leftover; then
echo "Error: the fragments above are not in the changelog for $GITHUB_REF_NAME"
exit 1
fi
python-ci:
if: github.event_name == 'workflow_dispatch' && startsWith(github.ref, 'refs/tags')
needs: preflight
permissions:
contents: read
pull-requests: read
uses: ./.github/workflows/python_ci.yaml
secrets: inherit
build-offline-archives:
if: github.event_name == 'workflow_dispatch' && startsWith(github.ref, 'refs/tags')
needs: python-ci
# python_build.yaml nests python_ci.yaml, which needs pull-requests: read even when skipped.
permissions:
contents: read
pull-requests: read
uses: ./.github/workflows/python_build.yaml
secrets: inherit
publish-to-pypi:
name: Upload release to PyPI
needs: [ python-ci, build-offline-archives ]
runs-on: ubuntu-latest
environment:
name: pypi
url: https://pypi.org/p/sift_py
permissions:
id-token: write
steps:
- name: Download distributions
uses: actions/download-artifact@v4
with:
name: sift-stack-py-dist
path: python/dist/
- name: Publish package distributions to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
packages-dir: python/dist/
create-github-release:
name: Create GitHub Release
needs: [ build-offline-archives ]
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Download distributions
uses: actions/download-artifact@v4
with:
name: sift-stack-py-dist
path: python/dist/
- name: Download all platform archives
uses: actions/download-artifact@v4
with:
pattern: sift-py-dist-*-py3-*
path: platform_archives
merge-multiple: false
- name: Parse version
id: version
uses: ./.github/actions/python-version-info
with:
version: ${{ github.ref_name }}
- name: Create Release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
TAG_NAME: ${{ github.ref_name }}
FULL_VERSION: ${{ steps.version.outputs.full_version }}
IS_PRERELEASE: ${{ steps.version.outputs.is_prerelease }}
run: |
if [[ "$IS_PRERELEASE" == "true" ]]; then
# Pre-release: mark as pre-release and do not promote to latest.
RELEASE_FLAGS=(--prerelease --latest=false)
else
# Stable release: mark as the latest release.
RELEASE_FLAGS=(--latest)
fi
# Create release notes. Start with this version's section of the changelog, if any.
awk -v header="## [${FULL_VERSION}]" '
index($0, header) == 1 { found = 1; next }
found && /^## \[/ { exit }
found { print }
' python/CHANGELOG.md > release_notes.md
cat >> release_notes.md << 'EOL'
See the [changelog](https://sift-stack.github.io/sift/python/latest/changelog/) for all releases.
Offline archives are available for download for multiple platforms. Offline archives include wheels for all dependencies including build extras, e.g. openssl, development, and build.
Use `pip install sift-stack-py --find-links={path/to/archive} --no-index` to install.
EOL
# Create the release
gh release create "$TAG_NAME" \
--title "sift-stack-py $TAG_NAME" \
--notes-file release_notes.md \
"${RELEASE_FLAGS[@]}"
# Upload Python package distributions
for dist in python/dist/*; do
echo "Uploading distribution: $dist"
gh release upload "$TAG_NAME" "$dist" --clobber
done
# Upload platform archives (both .zip and .tar.gz)
for archive in platform_archives/*/sift-py-dist-*-py3-*.{zip,tar.gz}; do
echo "Uploading archive: $archive"
gh release upload "$TAG_NAME" "$archive" --clobber
done
deploy-docs:
name: Deploy Documentation
needs: publish-to-pypi
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 1
- name: Parse version
id: version
uses: ./.github/actions/python-version-info
with:
version: ${{ github.ref_name }}
- name: Deploy full version (hidden)
uses: ./.github/actions/python-mike-deploy
with:
version: ${{ steps.version.outputs.full_version }}
hidden: 'true'
# Stable releases also get the abbreviated major.minor version with the
# 'latest' alias, visible in the dropdown. Pre-releases stop at the hidden
# full-version deploy above.
- name: Deploy abbreviated version with latest alias
if: steps.version.outputs.is_prerelease == 'false'
uses: ./.github/actions/python-mike-deploy
with:
version: ${{ steps.version.outputs.major_minor }}
aliases: latest
hidden: 'false'