-
-
Notifications
You must be signed in to change notification settings - Fork 104
142 lines (122 loc) · 4.57 KB
/
Copy pathon-release-main.yml
File metadata and controls
142 lines (122 loc) · 4.57 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
name: release-main
on:
release:
types: [published]
jobs:
set-version:
runs-on: ubuntu-24.04
permissions:
contents: write
steps:
- uses: actions/checkout@v4
- name: Export tag
id: vars
run: echo tag=${GITHUB_REF#refs/*/} >> $GITHUB_OUTPUT
if: ${{ github.event_name == 'release' }}
- name: Update project version
run: |
sed -i "s/^version = \".*\"/version = \"$RELEASE_VERSION\"/" pyproject.toml
env:
RELEASE_VERSION: ${{ steps.vars.outputs.tag }}
if: ${{ github.event_name == 'release' }}
- name: Upload updated pyproject.toml
uses: actions/upload-artifact@v4
with:
name: pyproject-toml
path: pyproject.toml
update-citation:
runs-on: ubuntu-24.04
permissions:
contents: write
pull-requests: write
steps:
# Unlike the pyproject.toml bump above, which only feeds the build via an
# artifact, CITATION.cff has to be committed back: GitHub's "Cite this
# repository" widget and cffconvert both read it from the default branch.
- name: Check out default branch
uses: actions/checkout@v4
with:
ref: ${{ github.event.repository.default_branch }}
- name: Update CITATION.cff to the released version
env:
RELEASE_VERSION: ${{ github.event.release.tag_name }}
RELEASE_PUBLISHED_AT: ${{ github.event.release.published_at }}
run: |
set -euo pipefail
release_date="${RELEASE_PUBLISHED_AT%%T*}"
sed -i "s/^version: \".*\"/version: \"${RELEASE_VERSION}\"/" CITATION.cff
sed -i "s/^date-released: \".*\"/date-released: \"${release_date}\"/" CITATION.cff
grep -E '^(version|date-released):' CITATION.cff
# main is governed by a repository ruleset requiring pull requests, so this
# opens one rather than pushing directly. Direct pushes are rejected with
# GH013 even when the token holds contents: write.
- name: Open a pull request if changed
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
RELEASE_VERSION: ${{ github.event.release.tag_name }}
run: |
set -euo pipefail
if git diff --quiet -- CITATION.cff; then
echo "CITATION.cff already up to date; nothing to do."
exit 0
fi
branch="citation/${RELEASE_VERSION}"
git config user.name 'github-actions[bot]'
git config user.email 'github-actions[bot]@users.noreply.github.com'
git checkout -b "$branch"
git add CITATION.cff
git commit -m "Update CITATION.cff for ${RELEASE_VERSION}"
git push --force-with-lease origin "$branch"
# Reruns of the same release should update the existing PR, not fail.
if gh pr view "$branch" --json number >/dev/null 2>&1; then
echo "PR already open for $branch"
else
gh pr create \
--base "${{ github.event.repository.default_branch }}" \
--head "$branch" \
--title "Update CITATION.cff for ${RELEASE_VERSION}" \
--body "Automated: syncs \`version\` and \`date-released\` in \`CITATION.cff\` with the ${RELEASE_VERSION} release, so the \"Cite this repository\" widget and \`cffconvert\` report the current version."
fi
publish:
runs-on: ubuntu-latest
needs: [set-version]
permissions:
contents: read
packages: write
steps:
- name: Check out
uses: actions/checkout@v4
- name: Set up the environment
uses: ./.github/actions/setup-python-env
- name: Download updated pyproject.toml
uses: actions/download-artifact@v4
with:
name: pyproject-toml
- name: Build package
run: uv build
- name: Publish package
run: uv publish
env:
UV_PUBLISH_TOKEN: ${{ secrets.PYPI_TOKEN }}
deploy-docs:
needs: publish
runs-on: ubuntu-latest
permissions:
contents: write
pages: write
id-token: write
steps:
- name: Check out
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up the environment
uses: ./.github/actions/setup-python-env
- name: Configure Git
run: |
git config --global user.name 'github-actions[bot]'
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
- name: Deploy documentation
run: uv run mkdocs gh-deploy --force
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}