-
Notifications
You must be signed in to change notification settings - Fork 0
97 lines (85 loc) · 3.21 KB
/
Copy pathpublish-python.yml
File metadata and controls
97 lines (85 loc) · 3.21 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
name: Publish Python SDK (Reusable)
on:
workflow_call:
jobs:
release:
runs-on: ubuntu-latest
permissions:
contents: write
id-token: write
defaults:
run:
working-directory: python
steps:
- uses: actions/checkout@v7
with:
fetch-depth: 0
# Credentials are the default GITHUB_TOKEN; the version-bump step pushes with them.
persist-credentials: true
- name: Set up Python
uses: actions/setup-python@v7
with:
python-version: "3.12"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install build
pip install ".[test]"
- name: Run tests
run: python -m pytest
- name: Determine next release version
id: release_version
uses: ietf-tools/semver-action@v1.11.0
with:
token: ${{ secrets.GITHUB_TOKEN }}
prefix: python/
patchAll: true
noVersionBumpBehavior: patch
maxTagsToFetch: 100
- name: Bump version in pyproject.toml
if: steps.release_version.outputs.next != ''
run: |
VERSION="${{ steps.release_version.outputs.next }}"
VERSION="${VERSION#python/v}"
sed -i "s/^version = \".*\"/version = \"$VERSION\"/" pyproject.toml
- name: Commit version bump
if: steps.release_version.outputs.next != ''
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add pyproject.toml
git commit -m "chore(release): python ${{ steps.release_version.outputs.next }} [skip ci]"
# Sibling language jobs push to main in parallel, so rebase and retry
# instead of failing the release on a lost ref-lock race.
for attempt in 1 2 3 4 5; do
if git push origin HEAD:main; then exit 0; fi
echo "push attempt $attempt failed; rebasing onto origin/main"
sleep $(( (RANDOM % 5) + 2 ))
git pull --rebase origin main
done
exit 1
- name: Build package
if: steps.release_version.outputs.next != ''
run: python -m build
# Publish before tagging so a registry failure does not leave behind a
# GitHub release for a version that was never published.
- name: Publish to PyPI
if: steps.release_version.outputs.next != ''
uses: pypa/gh-action-pypi-publish@release/v1
with:
password: ${{ secrets.PYPI_TOKEN }}
packages-dir: python/dist/
- name: Create GitHub Release
if: steps.release_version.outputs.next != ''
uses: actions/github-script@v9
with:
script: |
const { data: release } = await github.rest.repos.createRelease({
owner: context.repo.owner,
repo: context.repo.repo,
tag_name: '${{ steps.release_version.outputs.next }}',
target_commitish: 'main',
name: 'Python ${{ steps.release_version.outputs.next }}',
generate_release_notes: true
});
console.log(`Created release ${release.id} at ${release.html_url}`);