-
Notifications
You must be signed in to change notification settings - Fork 165
72 lines (62 loc) · 2.4 KB
/
create-release.yml
File metadata and controls
72 lines (62 loc) · 2.4 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
name: Create GitHub Release
on:
workflow_dispatch:
inputs:
branch:
description: 'Branch to release from'
required: true
default: 'beta'
workflow_run:
workflows: ['Test PR']
types: [completed]
branches: ['main', 'beta']
jobs:
create-release:
if: github.event_name == 'workflow_dispatch' || (github.event.workflow_run.conclusion == 'success' && github.event.workflow_run.event == 'push')
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
with:
ref: ${{ inputs.branch || github.event.workflow_run.head_branch }}
- name: Generate app token
id: app-token
uses: actions/create-github-app-token@v2
with:
app-id: ${{ secrets.RELEASE_APP_ID }}
private-key: ${{ secrets.RELEASE_APP_PRIVATE_KEY }}
- name: Read version
id: version
run: |
VERSION=$(grep '^version' pyproject.toml | sed 's/version = "\(.*\)"/\1/')
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
if [[ "$VERSION" == *"b"* || "$VERSION" == *"rc"* || "$VERSION" == *"a"* ]]; then
echo "prerelease=true" >> "$GITHUB_OUTPUT"
else
echo "prerelease=false" >> "$GITHUB_OUTPUT"
fi
- name: Validate version matches branch
run: |
BRANCH="${{ inputs.branch || github.event.workflow_run.head_branch }}"
VERSION="${{ steps.version.outputs.version }}"
PRERELEASE="${{ steps.version.outputs.prerelease }}"
if [[ "$BRANCH" == "beta" && "$PRERELEASE" == "false" ]]; then
echo "::error::Beta branch must have a prerelease version (e.g. 3.1.0b0), got '$VERSION'"
exit 1
fi
if [[ "$BRANCH" == "main" && "$PRERELEASE" == "true" ]]; then
echo "::error::Main branch must not have a prerelease version, got '$VERSION'"
exit 1
fi
- name: Create release
env:
GH_TOKEN: ${{ steps.app-token.outputs.token }}
run: |
FLAGS=""
if [ "${{ steps.version.outputs.prerelease }}" = "true" ]; then
FLAGS="--prerelease"
fi
gh release create "${{ steps.version.outputs.version }}" \
--target "${{ inputs.branch || github.event.workflow_run.head_branch }}" \
--title "${{ steps.version.outputs.version }}" \
--generate-notes \
$FLAGS