-
Notifications
You must be signed in to change notification settings - Fork 0
111 lines (96 loc) · 3.52 KB
/
release-cli.yml
File metadata and controls
111 lines (96 loc) · 3.52 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
name: Release CLI
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
on:
push:
branches:
- main
workflow_dispatch:
permissions:
contents: write
jobs:
release-cli:
runs-on: ubuntu-24.04
outputs:
publish: ${{ steps.check.outputs.publish }}
version: ${{ steps.check.outputs.version }}
steps:
- uses: actions/checkout@v4
with:
token: ${{ secrets.GH_PAT }}
- name: Check if should publish
id: check
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
version=$(jq -r '.version' cli/package.json)
name=$(jq -r '.name' cli/package.json)
npm_version=$(npm view "$name" version 2>/dev/null || echo "")
# 检查 GitHub Release 是否已存在
gh_release_exists="false"
if gh release view "v${version}" &> /dev/null; then
gh_release_exists="true"
fi
# 只有当 npm 版本不同且 GitHub Release 不存在时才发布
if [[ "$version" != "$npm_version" && "$gh_release_exists" == "false" ]]; then
echo "Version $version not published to npm or GitHub, will publish"
echo "publish=true" >> "$GITHUB_OUTPUT"
echo "version=$version" >> "$GITHUB_OUTPUT"
else
if [[ "$version" == "$npm_version" ]]; then
echo "Version $version already published to npm, skipping"
fi
if [[ "$gh_release_exists" == "true" ]]; then
echo "GitHub Release v${version} already exists, skipping"
fi
echo "publish=false" >> "$GITHUB_OUTPUT"
fi
- name: Setup pnpm
if: steps.check.outputs.publish == 'true'
uses: pnpm/action-setup@v4
- name: Setup Node
if: steps.check.outputs.publish == 'true'
uses: actions/setup-node@v4
with:
node-version: 25
registry-url: https://registry.npmjs.org/
cache: 'pnpm'
- name: Get pnpm store directory
if: steps.check.outputs.publish == 'true'
id: pnpm-cache
run: echo "STORE_PATH=$(pnpm store path)" >> $GITHUB_OUTPUT
- uses: actions/cache@v4
if: steps.check.outputs.publish == 'true'
name: Setup pnpm store cache
with:
path: ${{ steps.pnpm-cache.outputs.STORE_PATH }}
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-pnpm-store-
- name: Install & Build
if: steps.check.outputs.publish == 'true'
run: |
pnpm install --frozen-lockfile
pnpm exec turbo run build --filter=@truenine/memory-sync-cli...
- name: Publish to npm
if: steps.check.outputs.publish == 'true'
working-directory: ./cli
run: pnpm publish --access public --no-git-checks
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Create and push Git tag
if: steps.check.outputs.publish == 'true'
run: |
version=${{ steps.check.outputs.version }}
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git tag "v${version}"
git push origin "v${version}"
release-gui:
needs: release-cli
if: needs.release-cli.outputs.publish == 'true'
uses: ./.github/workflows/release-gui.yml
with:
version: ${{ needs.release-cli.outputs.version }}
secrets: inherit