Skip to content

Commit f188e6e

Browse files
author
chenliangzihao
committed
ci: 重构CI工作流并添加dev分支的canary发布
- 将原有的发布逻辑拆分为三个独立的工作流文件 - 添加dev分支的canary发布功能,版本号为0.0.0-beta-[gitHash] - 为PR添加带pr编号和hash的特殊版本发布 - 简化ci.yml文件,移除重复的发布逻辑 - 更新文档说明新的发布流程
1 parent 66f543f commit f188e6e

4 files changed

Lines changed: 181 additions & 126 deletions

File tree

.github/workflows/ci.yml

Lines changed: 2 additions & 126 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
name: CI
22

33
on:
4-
# Trigger on push to master branch
54
push:
65
branches:
76
- master
8-
# Trigger on pull requests to master branch
7+
- dev
98
pull_request:
109
branches:
1110
- master
@@ -17,7 +16,6 @@ permissions:
1716
pull-requests: write
1817

1918
jobs:
20-
# Basic CI checks for all pushes and PRs
2119
ci:
2220
runs-on: ubuntu-latest
2321
steps:
@@ -36,9 +34,7 @@ jobs:
3634
run: pnpm install --frozen-lockfile
3735

3836
- name: Lint and Format Check
39-
run: |
40-
# Check formatting with Prettier
41-
npx prettier --check "src/**/*.{ts,js,json}"
37+
run: npx prettier --check "src/**/*.{ts,js,json}"
4238

4339
- name: Type Check
4440
run: npx tsc --noEmit
@@ -48,123 +44,3 @@ jobs:
4844

4945
- name: Build
5046
run: pnpm build
51-
52-
# Create releases on push/merge to master
53-
create-release-on-push:
54-
needs: ci
55-
if: github.event_name == 'push'
56-
runs-on: ubuntu-latest
57-
58-
steps:
59-
- name: Checkout code
60-
uses: actions/checkout@v4
61-
with:
62-
fetch-depth: 0
63-
64-
- name: Setup Node.js
65-
uses: actions/setup-node@v4
66-
with:
67-
node-version: "20.x"
68-
69-
- name: Install pnpm
70-
run: npm install -g pnpm
71-
72-
- name: Install dependencies
73-
run: pnpm install --frozen-lockfile
74-
75-
- name: Run tests
76-
run: pnpm test
77-
78-
- name: Configure Git
79-
run: |
80-
git config user.name "github-actions"
81-
git config user.email "github-actions@github.com"
82-
83-
- name: Bump patch version
84-
run: pnpm version patch --no-git-tag-version
85-
86-
- name: Get new version from package.json
87-
id: package-version
88-
run: echo "version=$(node -p "require('./package.json').version")" >> $GITHUB_OUTPUT
89-
90-
- name: Commit and push version update
91-
run: |
92-
git add package.json pnpm-lock.yaml
93-
git commit -m "Bump version to v${{ steps.package-version.outputs.version }} [skip ci]"
94-
git push
95-
96-
- name: Build
97-
run: pnpm build
98-
99-
- name: Setup Node.js with registry
100-
uses: actions/setup-node@v4
101-
with:
102-
node-version: "20.x"
103-
registry-url: "https://registry.npmjs.org"
104-
105-
- name: Publish to npm
106-
run: pnpm publish --access public
107-
env:
108-
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
109-
110-
- name: Create GitHub Release
111-
uses: softprops/action-gh-release@v1
112-
with:
113-
tag_name: v${{ steps.package-version.outputs.version }}
114-
name: Release v${{ steps.package-version.outputs.version }}
115-
draft: false
116-
generate_release_notes: true
117-
body: |
118-
## 📦 NPM Package
119-
https://www.npmjs.com/package/@astro-notion/loader/v/${{ steps.package-version.outputs.version }}
120-
121-
```
122-
npm install @astro-notion/loader@${{ steps.package-version.outputs.version }}
123-
```
124-
125-
or
126-
127-
```
128-
pnpm add @astro-notion/loader@${{ steps.package-version.outputs.version }}
129-
```
130-
token: ${{ secrets.GITHUB_TOKEN }}
131-
132-
# Create test releases with hash tag on pull requests
133-
create-test-release-on-pr:
134-
needs: ci
135-
if: github.event_name == 'pull_request'
136-
runs-on: ubuntu-latest
137-
steps:
138-
- name: Checkout code
139-
uses: actions/checkout@v4
140-
141-
- name: Setup Node.js
142-
uses: actions/setup-node@v4
143-
with:
144-
node-version: "20.x"
145-
registry-url: "https://registry.npmjs.org"
146-
147-
- name: Install pnpm
148-
run: npm install -g pnpm
149-
150-
- name: Install dependencies
151-
run: pnpm install --frozen-lockfile
152-
153-
- name: Build
154-
run: pnpm build
155-
156-
- name: Get short SHA
157-
id: short-sha
158-
run: echo "sha=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
159-
160-
- name: Get package version
161-
id: package-version
162-
run: echo "version=$(node -p "require('./package.json').version")" >> $GITHUB_OUTPUT
163-
164-
- name: Create test version with hash
165-
run: pnpm version "${{ steps.package-version.outputs.version }}-pr${{ github.event.pull_request.number }}-${{ steps.short-sha.outputs.sha }}" --no-git-tag-version
166-
167-
- name: Publish to npm with tag
168-
run: pnpm publish --tag pr-${{ github.event.pull_request.number }} --access public --no-git-checks
169-
env:
170-
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
name: Release Canary Dev
2+
3+
on:
4+
push:
5+
branches:
6+
- dev
7+
8+
permissions:
9+
contents: write
10+
packages: write
11+
12+
jobs:
13+
release:
14+
runs-on: ubuntu-latest
15+
steps:
16+
- name: Checkout code
17+
uses: actions/checkout@v4
18+
19+
- name: Setup Node.js
20+
uses: actions/setup-node@v4
21+
with:
22+
node-version: "20.x"
23+
registry-url: "https://registry.npmjs.org"
24+
25+
- name: Install pnpm
26+
run: npm install -g pnpm
27+
28+
- name: Install dependencies
29+
run: pnpm install --frozen-lockfile
30+
31+
- name: Build
32+
run: pnpm build
33+
34+
- name: Get short SHA
35+
id: short-sha
36+
run: echo "sha=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
37+
38+
- name: Set canary version
39+
run: pnpm version "0.0.0-beta-${{ steps.short-sha.outputs.sha }}" --no-git-tag-version
40+
41+
- name: Publish to npm with canary tag
42+
run: pnpm publish --tag canary --access public --no-git-checks
43+
env:
44+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
name: Release Master
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
8+
permissions:
9+
contents: write
10+
packages: write
11+
12+
jobs:
13+
release:
14+
runs-on: ubuntu-latest
15+
steps:
16+
- name: Checkout code
17+
uses: actions/checkout@v4
18+
with:
19+
fetch-depth: 0
20+
21+
- name: Setup Node.js
22+
uses: actions/setup-node@v4
23+
with:
24+
node-version: "20.x"
25+
26+
- name: Install pnpm
27+
run: npm install -g pnpm
28+
29+
- name: Install dependencies
30+
run: pnpm install --frozen-lockfile
31+
32+
- name: Run tests
33+
run: pnpm test
34+
35+
- name: Configure Git
36+
run: |
37+
git config user.name "github-actions"
38+
git config user.email "github-actions@github.com"
39+
40+
- name: Bump patch version
41+
run: pnpm version patch --no-git-tag-version
42+
43+
- name: Get new version from package.json
44+
id: package-version
45+
run: echo "version=$(node -p "require('./package.json').version")" >> $GITHUB_OUTPUT
46+
47+
- name: Commit and push version update
48+
run: |
49+
git add package.json pnpm-lock.yaml
50+
git commit -m "Bump version to v${{ steps.package-version.outputs.version }} [skip ci]"
51+
git push
52+
53+
- name: Build
54+
run: pnpm build
55+
56+
- name: Setup Node.js with registry
57+
uses: actions/setup-node@v4
58+
with:
59+
node-version: "20.x"
60+
registry-url: "https://registry.npmjs.org"
61+
62+
- name: Publish to npm
63+
run: pnpm publish --access public
64+
env:
65+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
66+
67+
- name: Create GitHub Release
68+
uses: softprops/action-gh-release@v1
69+
with:
70+
tag_name: v${{ steps.package-version.outputs.version }}
71+
name: Release v${{ steps.package-version.outputs.version }}
72+
draft: false
73+
generate_release_notes: true
74+
body: |
75+
## 📦 NPM Package
76+
https://www.npmjs.com/package/@astro-notion/loader/v/${{ steps.package-version.outputs.version }}
77+
78+
```
79+
npm install @astro-notion/loader@${{ steps.package-version.outputs.version }}
80+
```
81+
82+
or
83+
84+
```
85+
pnpm add @astro-notion/loader@${{ steps.package-version.outputs.version }}
86+
```
87+
token: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/release-pr.yml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
name: Release PR
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- master
7+
8+
permissions:
9+
contents: write
10+
packages: write
11+
12+
jobs:
13+
release:
14+
runs-on: ubuntu-latest
15+
steps:
16+
- name: Checkout code
17+
uses: actions/checkout@v4
18+
19+
- name: Setup Node.js
20+
uses: actions/setup-node@v4
21+
with:
22+
node-version: "20.x"
23+
registry-url: "https://registry.npmjs.org"
24+
25+
- name: Install pnpm
26+
run: npm install -g pnpm
27+
28+
- name: Install dependencies
29+
run: pnpm install --frozen-lockfile
30+
31+
- name: Build
32+
run: pnpm build
33+
34+
- name: Get short SHA
35+
id: short-sha
36+
run: echo "sha=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
37+
38+
- name: Get package version
39+
id: package-version
40+
run: echo "version=$(node -p "require('./package.json').version")" >> $GITHUB_OUTPUT
41+
42+
- name: Create test version with hash
43+
run: pnpm version "${{ steps.package-version.outputs.version }}-pr${{ github.event.pull_request.number }}-${{ steps.short-sha.outputs.sha }}" --no-git-tag-version
44+
45+
- name: Publish to npm with tag
46+
run: pnpm publish --tag pr-${{ github.event.pull_request.number }} --access public --no-git-checks
47+
env:
48+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

0 commit comments

Comments
 (0)