-
Notifications
You must be signed in to change notification settings - Fork 0
227 lines (188 loc) · 6.64 KB
/
release.yml
File metadata and controls
227 lines (188 loc) · 6.64 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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
name: Release
on:
push:
branches: [main]
workflow_dispatch:
inputs:
pr_number:
description: 'PR number to release'
required: true
type: number
jobs:
check-release-label:
runs-on: ubuntu-latest
outputs:
should-release: ${{ steps.check.outputs.release }}
is-test: ${{ steps.check.outputs.test }}
pr-number: ${{ steps.check.outputs.pr_number }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Check for release labels
id: check
env:
GH_TOKEN: ${{ github.token }}
run: |
# Get PR number from event or commit message
if [ "${{ github.event_name }}" == "workflow_dispatch" ]; then
PR_NUMBER=${{ inputs.pr_number }}
else
# Extract PR number from merge commit message
# Format: "Merge pull request #123 from ..."
COMMIT_MSG=$(git log -1 --pretty=%s)
echo "Commit message: $COMMIT_MSG"
PR_NUMBER=$(echo "$COMMIT_MSG" | grep -oE '#[0-9]+' | head -1 | tr -d '#')
if [ -z "$PR_NUMBER" ]; then
echo "No PR number found in commit message, skipping release"
echo "release=false" >> $GITHUB_OUTPUT
echo "test=false" >> $GITHUB_OUTPUT
exit 0
fi
echo "Found PR number: $PR_NUMBER"
fi
LABELS=$(gh pr view $PR_NUMBER --json labels --jq '.labels[].name')
if echo "$LABELS" | grep -q "^release$"; then
echo "release=true" >> $GITHUB_OUTPUT
echo "test=false" >> $GITHUB_OUTPUT
elif echo "$LABELS" | grep -q "^test-release$"; then
echo "release=true" >> $GITHUB_OUTPUT
echo "test=true" >> $GITHUB_OUTPUT
else
echo "release=false" >> $GITHUB_OUTPUT
echo "test=false" >> $GITHUB_OUTPUT
fi
# Export PR number for later jobs
echo "pr_number=$PR_NUMBER" >> $GITHUB_OUTPUT
build:
needs: check-release-label
if: needs.check-release-label.outputs.should-release == 'true'
runs-on: ubuntu-latest
steps:
- name: Checkout main branch
uses: actions/checkout@v4
with:
ref: main
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version-file: ".python-version"
- name: Install uv
uses: astral-sh/setup-uv@v6
with:
version: "latest"
enable-cache: true
cache-dependency-glob: "uv.lock"
- name: Install Quarto
uses: quarto-dev/quarto-actions/setup@v2
with:
version: release
- name: Install dependencies
run: uv sync --locked --all-extras --dev
- name: Run tests
run: uv run pytest tests -v
- name: Build package
run: uv build
- name: Get version
id: version
run: |
VERSION=$(uv version --short)
echo "version=${VERSION}" >> $GITHUB_OUTPUT
echo "Package version: ${VERSION}"
- name: Upload distributions
uses: actions/upload-artifact@v4
with:
name: release-dists
path: dist/
outputs:
version: ${{ steps.version.outputs.version }}
publish-pypi:
needs: [check-release-label, build]
if: needs.check-release-label.outputs.is-test == 'false'
runs-on: ubuntu-latest
permissions:
id-token: write
environment:
name: pypi
url: https://pypi.org/p/quarto-batch-convert
steps:
- name: Download distributions
uses: actions/download-artifact@v4
with:
name: release-dists
path: dist/
- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
packages-dir: dist/
publish-testpypi:
needs: [check-release-label, build]
if: needs.check-release-label.outputs.is-test == 'true'
runs-on: ubuntu-latest
permissions:
id-token: write
environment:
name: testpypi
url: https://test.pypi.org/p/quarto-batch-convert
steps:
- name: Download distributions
uses: actions/download-artifact@v4
with:
name: release-dists
path: dist/
- name: Publish to TestPyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
repository-url: https://test.pypi.org/legacy/
packages-dir: dist/
create-tag-and-release:
needs: [check-release-label, build, publish-pypi]
if: |
always() &&
needs.check-release-label.outputs.should-release == 'true' &&
(needs.publish-pypi.result == 'success' || needs.publish-testpypi.result == 'success')
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout main branch
uses: actions/checkout@v4
with:
ref: main
- name: Create and push tag
env:
VERSION: ${{ needs.build.outputs.version }}
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git tag -a "v${VERSION}" -m "Release v${VERSION}"
git push origin "v${VERSION}"
- name: Create GitHub Release
env:
GH_TOKEN: ${{ github.token }}
VERSION: ${{ needs.build.outputs.version }}
PR_NUMBER: ${{ needs.check-release-label.outputs.pr-number }}
run: |
RELEASE_TYPE="${{ needs.check-release-label.outputs.is-test == 'true' && 'TestPyPI' || 'PyPI' }}"
PACKAGE_URL="${{ needs.check-release-label.outputs.is-test == 'true' && 'https://test.pypi.org/project/quarto-batch-convert' || 'https://pypi.org/project/quarto-batch-convert' }}"
# Fetch PR details
PR_TITLE=$(gh pr view $PR_NUMBER --json title --jq '.title')
PR_BODY=$(gh pr view $PR_NUMBER --json body --jq '.body')
PR_URL="https://github.com/${{ github.repository }}/pull/$PR_NUMBER"
# Build release notes
RELEASE_NOTES="## ${PR_TITLE}
${PR_BODY}
---
## Installation
\`\`\`bash
pipx install quarto-batch-convert
\`\`\`
## Links
- 📦 Package: [${RELEASE_TYPE}](${PACKAGE_URL})
- 🔗 Pull Request: [#${PR_NUMBER}](${PR_URL})
- 📚 Documentation: [README](https://github.com/${{ github.repository }}/blob/main/README.md)
"
gh release create "v${VERSION}" \
--title "v${VERSION}" \
--notes "$RELEASE_NOTES" \
--draft=false \
--prerelease=${{ needs.check-release-label.outputs.is-test == 'true' }}