-
Notifications
You must be signed in to change notification settings - Fork 285
131 lines (111 loc) · 3.82 KB
/
prepare-release.yml
File metadata and controls
131 lines (111 loc) · 3.82 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
name: Prepare release
on:
workflow_dispatch:
inputs:
version_type:
description: "Version bump type (patch, minor, major)"
required: false
default: "patch"
prerelease:
description: "Publish as prerelease? (leave empty for stable, or enter tag like 'next')"
required: false
default: ""
jobs:
preflight:
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- name: Checkout
uses: actions/checkout@v6
- name: Setup Bun
uses: oven-sh/setup-bun@v2
with:
bun-version: 1.3.0
- name: Setup Node
uses: actions/setup-node@v6
with:
node-version: "22"
- name: Install dependencies
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: bun install --frozen-lockfile
- name: Lint & Type Check
run: bun run check
- name: Build bundle
run: bun run build
- name: Update-chain preflight smoke
run: bun run test:update-chain:manual
prepare:
needs: preflight
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
steps:
- name: Checkout
uses: actions/checkout@v6
with:
token: ${{ secrets.GITHUB_TOKEN }}
- name: Configure Git
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
- name: Bump version
id: version
run: |
VERSION_TYPE="${{ github.event.inputs.version_type || 'patch' }}"
PRERELEASE_TAG="${{ github.event.inputs.prerelease }}"
OLD_VERSION=$(jq -r '.version' package.json)
if [[ "$OLD_VERSION" == *-* ]]; then
OLD_IS_PRERELEASE=true
BASE_VERSION=$(echo "$OLD_VERSION" | sed 's/-.*//')
else
OLD_IS_PRERELEASE=false
BASE_VERSION="$OLD_VERSION"
fi
IFS='.' read -ra VERSION_PARTS <<< "$BASE_VERSION"
MAJOR=${VERSION_PARTS[0]}
MINOR=${VERSION_PARTS[1]}
PATCH=${VERSION_PARTS[2]}
if [ "$VERSION_TYPE" = "major" ]; then
MAJOR=$((MAJOR + 1))
MINOR=0
PATCH=0
elif [ "$VERSION_TYPE" = "minor" ]; then
MINOR=$((MINOR + 1))
PATCH=0
else
if [ "$OLD_IS_PRERELEASE" = "false" ]; then
PATCH=$((PATCH + 1))
fi
fi
NEW_VERSION="${MAJOR}.${MINOR}.${PATCH}"
if [ -n "$PRERELEASE_TAG" ]; then
if [[ "$OLD_VERSION" == "${NEW_VERSION}-${PRERELEASE_TAG}."* ]]; then
PRERELEASE_NUM=$(echo "$OLD_VERSION" | sed "s/${NEW_VERSION}-${PRERELEASE_TAG}\.\([0-9]*\)/\1/")
PRERELEASE_NUM=$((PRERELEASE_NUM + 1))
else
PRERELEASE_NUM=1
fi
NEW_VERSION="${NEW_VERSION}-${PRERELEASE_TAG}.${PRERELEASE_NUM}"
fi
jq --arg version "$NEW_VERSION" '.version = $version' package.json > package.json.tmp
mv package.json.tmp package.json
echo "new_version=$NEW_VERSION" >> $GITHUB_OUTPUT
- name: Commit version bump
run: |
git add package.json
git commit -m "chore: bump version to ${{ steps.version.outputs.new_version }}"
- name: Create version bump PR
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
BRANCH="chore/bump-v${{ steps.version.outputs.new_version }}"
git checkout -b "$BRANCH"
git push origin "$BRANCH"
gh pr create \
--title "chore: bump version to ${{ steps.version.outputs.new_version }}" \
--body "Merge this PR to publish v${{ steps.version.outputs.new_version }}." \
--base main \
--head "$BRANCH"