66 - ' v*'
77
88jobs :
9- validate :
9+ release :
1010 runs-on : ubuntu-latest
1111 steps :
12- - uses : actions/checkout@v3
12+ - name : Checkout code
13+ uses : actions/checkout@v4
1314 with :
1415 fetch-depth : 0
15-
16- - name : Validate version format
17- id : version_check
18- run : |
19- TAG_VERSION=${GITHUB_REF#refs/tags/v}
20- if ! [[ $TAG_VERSION =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
21- echo "錯誤:版本號格式不正確。必須符合 semver 格式 (例如:1.0.0)"
22- exit 1
23- fi
24- CURRENT_VERSION=$(node -p "require('./package.json').version")
25- if [ "$(printf '%s\n' "$TAG_VERSION" "$CURRENT_VERSION" | sort -V | head -n1)" = "$TAG_VERSION" ]; then
26- echo "錯誤:新版本號 ($TAG_VERSION) 必須大於當前版本 ($CURRENT_VERSION)"
27- exit 1
28- fi
29- echo "version=$TAG_VERSION" >> $GITHUB_OUTPUT
3016
3117 - name : Setup Node.js
32- uses : actions/setup-node@v3
18+ uses : actions/setup-node@v4
3319 with :
34- node-version : ' 18'
35-
20+ node-version : ' 20'
21+ registry-url : ' https://registry.npmjs.org'
22+
3623 - name : Install dependencies
3724 run : npm ci
38-
25+
3926 - name : Run tests
4027 run : npm test
41-
42- - name : Run linting
43- run : npm run lint
4428
45- release :
46- needs : validate
47- runs-on : ubuntu-latest
48- permissions :
49- contents : write
50- outputs :
51- version : ${{ steps.get_version.outputs.version }}
52- sha : ${{ steps.sha.outputs.sha }}
53- steps :
54- - uses : actions/checkout@v3
55- with :
56- fetch-depth : 0
57-
58- - name : Setup Node.js
59- uses : actions/setup-node@v3
60- with :
61- node-version : ' 18'
62- registry-url : ' https://registry.npmjs.org'
63-
6429 - name : Get version from tag
6530 id : get_version
66- run : |
67- VERSION=${GITHUB_REF#refs/tags/v}
68- echo "version=$VERSION" >> $GITHUB_OUTPUT
69-
70- - name : Install dependencies
71- run : npm ci
72-
73- - name : Create GitHub Release
74- id : create_release
75- uses : actions/create-release@v1
76- env :
77- GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
78- with :
79- tag_name : ${{ github.ref }}
80- release_name : Release ${{ github.ref }}
81- draft : false
82- prerelease : false
83-
84- - name : Publish to npm
85- id : npm_publish
86- run : |
87- npm publish || {
88- echo "NPM 發布失敗,開始回滾..."
89- git tag -d v${{ steps.get_version.outputs.version }}
90- git push origin :refs/tags/v${{ steps.get_version.outputs.version }}
91- exit 1
92- }
31+ run : echo "VERSION=${GITHUB_REF#refs/tags/v}" >> $GITHUB_ENV
32+
33+ - name : Update package version
34+ run : npm version $VERSION --no-git-tag-version
35+
36+ - name : Build package
37+ run : npm run build
38+
39+ - name : Publish to NPM
40+ run : npm publish
9341 env :
9442 NODE_AUTH_TOKEN : ${{ secrets.NPM_TOKEN }}
95-
96- - name : Calculate tarball SHA
43+
44+ - name : Calculate SHA
9745 id : sha
9846 run : |
99- SHA=$(curl -sL https://github.com/crayon3shawn/mcp-cli-manager/archive/refs/tags/v${{ steps.get_version.outputs.version }}.tar.gz | shasum -a 256 | cut -d ' ' -f 1)
100- echo "sha=$SHA" >> $GITHUB_OUTPUT
47+ TARBALL_URL="https://registry.npmjs.org/@chengche/mcp-cli-manager/-/mcp-cli-manager-${VERSION}.tgz"
48+ curl -L $TARBALL_URL -o package.tgz
49+ echo "SHA=$(shasum -a 256 package.tgz | cut -d ' ' -f 1)" >> $GITHUB_ENV
10150
102- update-homebrew :
103- needs : release
104- runs-on : ubuntu-latest
105- steps :
10651 - name : Checkout tap repository
107- uses : actions/checkout@v3
52+ uses : actions/checkout@v4
10853 with :
10954 repository : crayon3shawn/homebrew-tap
11055 token : ${{ secrets.TAP_PAT }}
111-
112- - name : Update Homebrew formula
113- id : update_formula
56+ path : homebrew-tap
57+
58+ - name : Update Homebrew Formula
11459 run : |
115- VERSION=${{ needs.release.outputs.version }}
116- SHA=${{ needs.release.outputs.sha }}
117-
118- mkdir -p Formula
60+ VERSION=${{ env.VERSION }}
61+ SHA=${{ env.SHA }}
11962
120- # 更新 formula
121- cat > Formula/mcp-cli-manager.rb << EOF
63+ mkdir -p homebrew-tap/Formula
64+ cat > homebrew-tap/ Formula/mcp-cli-manager.rb << EOL
12265 class McpCliManager < Formula
123- desc "CLI tool for managing MCP projects"
66+ desc "A CLI tool for managing MCP projects"
12467 homepage "https://github.com/crayon3shawn/mcp-cli-manager"
125- url "https://github.com/crayon3shawn /mcp-cli-manager/archive/refs/tags/v ${VERSION}.tar.gz "
68+ url "https://registry.npmjs.org/@chengche /mcp-cli-manager/-/mcp-cli-manager- ${VERSION}.tgz "
12669 sha256 "${SHA}"
12770 license "MIT"
128-
71+
12972 depends_on "node"
130-
73+
13174 def install
13275 system "npm", "install", *Language::Node.std_npm_install_args(libexec)
13376 bin.install_symlink Dir["#{libexec}/bin/*"]
13477 end
135-
78+
13679 test do
137- assert_match "mcp-cli-manager", shell_output("#{bin}/mcp-cli-manager --version")
80+ assert_match "mcp-cli-manager", shell_output("#{bin}/mcp --version")
13881 end
13982 end
140- EOF
141-
83+ EOL
84+
14285 - name : Commit and push formula changes
14386 run : |
87+ cd homebrew-tap
14488 git config user.name "GitHub Action"
14589 git config user.email "action@github.com"
14690 git add Formula/mcp-cli-manager.rb
147- git commit -m "chore: update formula to v${{ needs.release.outputs.version }}"
148- git push
149-
150- notify :
151- needs : [release, update-homebrew]
152- runs-on : ubuntu-latest
153- if : always()
154- steps :
155- - name : Check workflow status
156- if : needs.release.result == 'failure' || needs.update-homebrew.result == 'failure'
157- run : |
158- echo "發布流程失敗!請檢查日誌並手動處理未完成的回滾操作。"
159- exit 1
91+ git commit -m "chore: update formula to v${{ env.VERSION }}"
92+ git push
0 commit comments