-
Notifications
You must be signed in to change notification settings - Fork 1
79 lines (68 loc) · 2.54 KB
/
release-prepare.yml
File metadata and controls
79 lines (68 loc) · 2.54 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
name: Prepare Release
on:
workflow_dispatch:
inputs:
version:
description: "Version bump: patch, minor, major, or explicit (e.g. 1.2.3)"
required: true
type: string
jobs:
prepare:
name: Create Release PR
runs-on: ubuntu-latest
if: github.repository_owner == 'LeagueToolkit'
permissions:
contents: write
pull-requests: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Resolve version
id: version
shell: bash
run: |
INPUT="${{ inputs.version }}"
CURRENT=$(node -p "require('./package.json').version")
IFS='.' read -r MAJ MIN PAT <<< "$CURRENT"
case "$INPUT" in
patch) VERSION="$MAJ.$MIN.$((PAT + 1))" ;;
minor) VERSION="$MAJ.$((MIN + 1)).0" ;;
major) VERSION="$((MAJ + 1)).0.0" ;;
*)
if [[ ! "$INPUT" =~ ^[0-9]+\.[0-9]+\.[0-9]+(-[a-zA-Z0-9.]+)?$ ]]; then
echo "::error::Invalid version: $INPUT (expected patch, minor, major, or semver like 1.2.3)"
exit 1
fi
VERSION="$INPUT"
;;
esac
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
echo "::notice::Preparing release v$VERSION (current: $CURRENT)"
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
- name: Bump versions and create PR
shell: bash
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
VERSION="${{ steps.version.outputs.version }}"
BRANCH="release/v$VERSION"
node -e "
const fs = require('fs');
const pkg = JSON.parse(fs.readFileSync('package.json', 'utf8'));
pkg.version = '$VERSION';
fs.writeFileSync('package.json', JSON.stringify(pkg, null, 2) + '\n');
"
sed -i "0,/^version = \".*\"/s//version = \"$VERSION\"/" src-tauri/Cargo.toml
cargo generate-lockfile
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git checkout -b "$BRANCH"
git add package.json src-tauri/Cargo.toml Cargo.lock
git commit -m "chore: release v$VERSION"
git push origin "$BRANCH"
gh pr create \
--title "chore: release v$VERSION" \
--body "Bumps version to **v$VERSION** in \`package.json\` and \`Cargo.toml\`." \
--base main \
--head "$BRANCH"