-
Notifications
You must be signed in to change notification settings - Fork 0
162 lines (147 loc) · 4.89 KB
/
release.yml
File metadata and controls
162 lines (147 loc) · 4.89 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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
name: release
# 开发者推送 `v*` tag 时触发:交叉编译 6 个平台二进制 →
# 生成 checksums.txt → 创建 GitHub Release(release notes 由 GitHub
# 按上一个 tag 的提交自动生成)→ 发布 @mp2rss/cli npm 包装。
on:
push:
tags:
- 'v*'
permissions:
contents: write
id-token: write # for npm provenance / OIDC trusted publishing
jobs:
build:
name: build ${{ matrix.goos }}/${{ matrix.goarch }}
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
include:
- { goos: darwin, goarch: amd64, ext: tar.gz }
- { goos: darwin, goarch: arm64, ext: tar.gz }
- { goos: linux, goarch: amd64, ext: tar.gz }
- { goos: linux, goarch: arm64, ext: tar.gz }
- { goos: windows, goarch: amd64, ext: zip }
- { goos: windows, goarch: arm64, ext: zip }
env:
VERSION: ${{ github.ref_name }}
steps:
- uses: actions/checkout@v6
- name: Set up Go
uses: actions/setup-go@v6
with:
go-version: '1.21'
cache: true
- name: Build
env:
GOOS: ${{ matrix.goos }}
GOARCH: ${{ matrix.goarch }}
CGO_ENABLED: '0'
run: |
set -eu
out="mp2rss"
[ "${{ matrix.goos }}" = "windows" ] && out="mp2rss.exe"
mkdir -p dist
go build \
-trimpath \
-ldflags="-s -w -X github.com/areyoubugcoder/mp2rss-cli/internal/version.Version=${VERSION}" \
-o "dist/${out}" \
.
- name: Package archive
id: pkg
env:
GOOS: ${{ matrix.goos }}
GOARCH: ${{ matrix.goarch }}
run: |
set -eu
asset="mp2rss-cli_${VERSION#v}_${GOOS}_${GOARCH}.${{ matrix.ext }}"
(
cd dist
if [ "${{ matrix.ext }}" = "zip" ]; then
zip "../${asset}" mp2rss.exe
else
tar -czf "../${asset}" mp2rss
fi
)
ls -lh "${asset}"
echo "asset=${asset}" >>"$GITHUB_OUTPUT"
- name: Upload artifact
uses: actions/upload-artifact@v7
with:
name: archive-${{ matrix.goos }}-${{ matrix.goarch }}
path: ${{ steps.pkg.outputs.asset }}
retention-days: 1
release:
name: publish release
needs: build
runs-on: ubuntu-latest
env:
VERSION: ${{ github.ref_name }}
steps:
- name: Download all archives
uses: actions/download-artifact@v8
with:
path: dist
merge-multiple: true
- name: Generate checksums.txt
working-directory: dist
run: |
set -eu
sha256sum mp2rss-cli_*.tar.gz mp2rss-cli_*.zip > checksums.txt
cat checksums.txt
- name: Create release
uses: softprops/action-gh-release@v3
with:
tag_name: ${{ env.VERSION }}
name: ${{ env.VERSION }}
generate_release_notes: true
files: |
dist/mp2rss-cli_*.tar.gz
dist/mp2rss-cli_*.zip
dist/checksums.txt
fail_on_unmatched_files: true
publish-npm:
name: publish @mp2rss/cli to npm
needs: release
runs-on: ubuntu-latest
env:
VERSION: ${{ github.ref_name }}
steps:
- uses: actions/checkout@v6
- uses: actions/setup-node@v6
with:
node-version: '22'
registry-url: 'https://registry.npmjs.org'
- name: Upgrade npm to support OIDC trusted publishing
# 固定 11.5.1:这是 npm OIDC trusted publishing 要求的最低版本,
# 同时绕过 npm@latest 自更新触发的 'Cannot find module promise-retry'
# 已知 bug(影响 Node 22.x 自带 npm@10.x → 11.x latest 自更新路径)。
run: npm install -g npm@11.5.1
- name: Sync npm/package.json version
working-directory: npm
run: |
set -eu
version="${VERSION#v}"
node -e "
const fs = require('fs');
const p = require('./package.json');
p.version = '${version}';
fs.writeFileSync('package.json', JSON.stringify(p, null, 2) + '\n');
"
- name: Publish
working-directory: npm
run: |
set -eu
# pre-release tag (vX.Y.Z-foo) publishes to a derived dist-tag
# instead of latest,避免 RC/beta 抢正式版的 `latest`。
# v1.0.0-rc.0 → npm publish --tag rc
# v1.0.0-beta.1 → npm publish --tag beta
# v1.0.0 → npm publish (默认 latest)
if [[ "${VERSION}" == *-* ]]; then
suffix="${VERSION#*-}"
tag="${suffix%%.*}"
echo "Publishing pre-release to dist-tag: ${tag}"
npm publish --access public --provenance --tag "${tag}"
else
npm publish --access public --provenance
fi