-
Notifications
You must be signed in to change notification settings - Fork 0
99 lines (90 loc) · 3.5 KB
/
Copy pathversion-bump.yml
File metadata and controls
99 lines (90 loc) · 3.5 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
name: Auto Version Bump
on:
pull_request:
types:
- closed
branches:
- main
jobs:
bump-version:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Check if PR was merged
id: check
run: |
if [ "${{ github.event.pull_request.merged }}" = "true" ]; then
echo "merged=true" >> "$GITHUB_OUTPUT"
else
echo "merged=false" >> "$GITHUB_OUTPUT"
fi
- name: Checkout main branch
if: steps.check.outputs.merged == 'true'
uses: actions/checkout@v4
with:
ref: main
token: ${{ secrets.GITHUB_TOKEN }}
- name: Get current version
if: steps.check.outputs.merged == 'true'
id: current_version
run: |
LINE=$(grep "^version:" pubspec.yaml | sed 's/^version:[[:space:]]*//')
# Drop +build, then any -prerelease (e.g. 0.4.11-b → 0.4.11).
CORE=$(echo "$LINE" | sed 's/+.*//; s/-.*//')
if [[ "$LINE" == *'+'* ]]; then
BUILD="${LINE##*+}"
else
BUILD=""
fi
# Guard against non-numeric build leftovers.
if ! [[ "$BUILD" =~ ^[0-9]+$ ]]; then
BUILD=""
fi
echo "current_version=$CORE" >> "$GITHUB_OUTPUT"
echo "current_build=$BUILD" >> "$GITHUB_OUTPUT"
- name: Bump patch version
if: steps.check.outputs.merged == 'true'
id: bump
run: |
CURRENT_VERSION="${{ steps.current_version.outputs.current_version }}"
CURRENT_BUILD="${{ steps.current_version.outputs.current_build }}"
MAJOR=$(echo "$CURRENT_VERSION" | cut -d. -f1)
MINOR=$(echo "$CURRENT_VERSION" | cut -d. -f2)
PATCH=$(echo "$CURRENT_VERSION" | cut -d. -f3)
if ! [[ "$MAJOR$MINOR$PATCH" =~ ^[0-9]+$ ]]; then
echo "Invalid core version: $CURRENT_VERSION" >&2
exit 1
fi
NEW_PATCH=$((PATCH + 1))
NEW_VERSION="$MAJOR.$MINOR.$NEW_PATCH"
if [ -z "$CURRENT_BUILD" ]; then
NEW_BUILD=1
else
NEW_BUILD=$((CURRENT_BUILD + 1))
fi
echo "new_version=$NEW_VERSION" >> "$GITHUB_OUTPUT"
echo "new_build=$NEW_BUILD" >> "$GITHUB_OUTPUT"
- name: Update pubspec.yaml
if: steps.check.outputs.merged == 'true'
run: |
NEW_VERSION="${{ steps.bump.outputs.new_version }}"
NEW_BUILD="${{ steps.bump.outputs.new_build }}"
sed -i "s/^version: .*/version: ${NEW_VERSION}+${NEW_BUILD}/" pubspec.yaml
grep "^version:" pubspec.yaml
- name: Sync AUR PKGBUILD pkgver with pubspec
if: steps.check.outputs.merged == 'true'
run: |
NEW_VERSION="${{ steps.bump.outputs.new_version }}"
sed -i "s/^pkgver=.*/pkgver=${NEW_VERSION}/" packaging/linux/aur/PKGBUILD
sed -i "s/^pkgrel=.*/pkgrel=1/" packaging/linux/aur/PKGBUILD
sed -i "s/^sha256sums=.*/sha256sums=('SKIP' 'SKIP' 'SKIP')/" packaging/linux/aur/PKGBUILD
grep ^pkgver packaging/linux/aur/PKGBUILD
- name: Commit version bump
if: steps.check.outputs.merged == 'true'
run: |
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
git add pubspec.yaml packaging/linux/aur/PKGBUILD
git commit -m "Bump version to ${{ steps.bump.outputs.new_version }}+${{ steps.bump.outputs.new_build }}"
git push origin main