Skip to content

Commit 9124910

Browse files
committed
ci: Add Buddy Pipeline
1 parent 12604f9 commit 9124910

File tree

1 file changed

+137
-0
lines changed

1 file changed

+137
-0
lines changed

.github/workflows/buddy.yml

Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
# Copyright 2015 Shuai Zhang
2+
# SPDX-License-Identifier: LGPL-3.0-or-later WITH LGPL-3.0-linking-exception
3+
4+
name: Buddy Release
5+
6+
on:
7+
workflow_dispatch:
8+
inputs:
9+
release_ref:
10+
description: 'Branch to release from'
11+
required: true
12+
default: main
13+
14+
permissions:
15+
contents: write
16+
packages: write
17+
18+
env:
19+
NODE_VERSION: 24.x
20+
21+
jobs:
22+
release:
23+
name: Package & Publish
24+
runs-on: ubuntu-latest
25+
env:
26+
RELEASE_REF: ${{ inputs.release_ref }}
27+
steps:
28+
- name: Checkout
29+
uses: actions/checkout@v5
30+
with:
31+
fetch-depth: 0
32+
ref: ${{ env.RELEASE_REF }}
33+
34+
- name: Configure Git author
35+
run: |
36+
git config user.name "github-actions[bot]"
37+
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
38+
39+
- name: Set up PNPM
40+
uses: pnpm/action-setup@v4
41+
with:
42+
version: 10.22.0
43+
run_install: false
44+
45+
- name: Set up Node.js
46+
uses: actions/setup-node@v6
47+
with:
48+
node-version: ${{ env.NODE_VERSION }}
49+
cache: pnpm
50+
cache-dependency-path: pnpm-lock.yaml
51+
52+
- name: Install dependencies
53+
run: pnpm install --frozen-lockfile
54+
55+
- name: Lint
56+
run: pnpm lint
57+
58+
- name: Typecheck
59+
run: pnpm typecheck
60+
61+
- name: Test
62+
run: pnpm test
63+
64+
- name: Build
65+
run: pnpm build
66+
67+
- name: Compute release metadata
68+
id: versions
69+
run: |
70+
set -euo pipefail
71+
CURRENT_VERSION="$(node -p \"require('./package.json').version\")"
72+
if [[ ! "$CURRENT_VERSION" =~ ^([0-9]+\.[0-9]+\.[0-9]+-dev\.)([0-9]+)$ ]]; then
73+
echo "Package version '$CURRENT_VERSION' must match '*-dev.N'." >&2
74+
exit 1
75+
fi
76+
77+
PREFIX="${BASH_REMATCH[1]}"
78+
COUNTER="${BASH_REMATCH[2]}"
79+
NEXT_VERSION="${PREFIX}$((COUNTER + 1))"
80+
TAG_NAME="v${CURRENT_VERSION}"
81+
82+
echo "current=$CURRENT_VERSION" >> "$GITHUB_OUTPUT"
83+
echo "next=$NEXT_VERSION" >> "$GITHUB_OUTPUT"
84+
echo "tag=$TAG_NAME" >> "$GITHUB_OUTPUT"
85+
86+
- name: Create local release tag
87+
env:
88+
TAG_NAME: ${{ steps.versions.outputs.tag }}
89+
run: |
90+
set -euo pipefail
91+
git fetch --tags
92+
if git show-ref --quiet "refs/tags/${TAG_NAME}"; then
93+
echo "Tag ${TAG_NAME} already exists." >&2
94+
exit 1
95+
fi
96+
git tag -a "${TAG_NAME}" -m "Release ${TAG_NAME}"
97+
98+
- name: Publish to GitHub Packages
99+
env:
100+
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
101+
run: |
102+
set -euo pipefail
103+
pnpm publish --registry https://npm.pkg.github.com --access public --no-git-checks
104+
105+
- name: Push release tag
106+
env:
107+
TAG_NAME: ${{ steps.versions.outputs.tag }}
108+
run: git push origin "${TAG_NAME}"
109+
110+
- name: Bump development version
111+
env:
112+
NEXT_VERSION: ${{ steps.versions.outputs.next }}
113+
run: |
114+
set -euo pipefail
115+
node <<'EOF'
116+
const fs = require('node:fs');
117+
const path = require('node:path');
118+
const pkgPath = path.join(process.cwd(), 'package.json');
119+
const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf8'));
120+
pkg.version = process.env.NEXT_VERSION;
121+
fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, 2) + '\n');
122+
EOF
123+
124+
- name: Commit version bump
125+
env:
126+
NEXT_VERSION: ${{ steps.versions.outputs.next }}
127+
run: |
128+
set -euo pipefail
129+
if git diff --quiet package.json; then
130+
echo "No version bump detected; skipping commit." >&2
131+
exit 0
132+
fi
133+
git add package.json
134+
git commit -m "chore: Bump Version to ${NEXT_VERSION}"
135+
136+
- name: Push version bump
137+
run: git push origin "HEAD:${RELEASE_REF}"

0 commit comments

Comments
 (0)