-
Notifications
You must be signed in to change notification settings - Fork 7
101 lines (87 loc) · 2.97 KB
/
Copy pathrelease.yml
File metadata and controls
101 lines (87 loc) · 2.97 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
name: Release
on:
workflow_dispatch:
inputs:
version:
description: 'New version number (e.g. 6.3.0)'
required: true
type: string
jobs:
validate:
name: Validate version
runs-on: ubuntu-latest
outputs:
version: ${{ steps.check.outputs.version }}
steps:
- uses: actions/checkout@v5
- name: Check version is valid and greater than current
id: check
run: |
NEW="${{ inputs.version }}"
# Must match semver X.Y.Z
if ! echo "$NEW" | grep -qE '^[0-9]+\.[0-9]+\.[0-9]+$'; then
echo "::error::Version '$NEW' is not valid semver (expected X.Y.Z)"
exit 1
fi
CURRENT=$(grep -E '^version\s*=\s*"[0-9]+' pyproject.toml | head -n1 \
| sed -E 's/.*version\s*=\s*"([^"]+)".*/\1/')
echo "Current version: $CURRENT"
echo "Requested version: $NEW"
version_key() {
echo "$1" | awk -F. '{ printf "%05d%05d%05d", $1, $2, $3 }'
}
if [ "$(version_key "$NEW")" -le "$(version_key "$CURRENT")" ]; then
echo "::error::New version ($NEW) must be greater than current version ($CURRENT)"
exit 1
fi
echo "version=$NEW" >> "$GITHUB_OUTPUT"
test:
name: Test
needs: validate
uses: ./.github/workflows/test.yml
with:
fail-fast: true
release:
name: Bump, tag and create draft release
needs: test
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Generate GitHub App token
id: app-token
uses: actions/create-github-app-token@v1
with:
app-id: ${{ secrets.GH_APP_ID }}
private-key: ${{ secrets.GH_APP_PRIVATE_KEY }}
- uses: actions/checkout@v5
with:
token: ${{ steps.app-token.outputs.token }}
ref: master
- name: Bump version in pyproject.toml
run: |
NEW="${{ needs.validate.outputs.version }}"
awk -v newver="$NEW" '
BEGIN{inproj=0;done=0}
/^\[project\]/{inproj=1}
inproj && !done && /version\s*=/{sub(/version\s*=\s*"[^"]+"/, "version = \"" newver "\""); done=1}
{print}
' pyproject.toml > pyproject.toml.tmp && mv pyproject.toml.tmp pyproject.toml
- name: Commit, tag and push
run: |
NEW="${{ needs.validate.outputs.version }}"
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 "Bump ynca version to $NEW"
git tag -a "v$NEW" -m "Version $NEW"
git push --follow-tags
- name: Create draft release
env:
GH_TOKEN: ${{ steps.app-token.outputs.token }}
run: |
NEW="${{ needs.validate.outputs.version }}"
gh release create "v$NEW" \
--draft \
--generate-notes \
--title "v$NEW"