-
Notifications
You must be signed in to change notification settings - Fork 0
262 lines (234 loc) · 9.28 KB
/
Copy pathrelease.yml
File metadata and controls
262 lines (234 loc) · 9.28 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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
name: Release
on:
push:
tags:
- "v*"
permissions:
contents: read
concurrency:
group: release-${{ github.ref }}
cancel-in-progress: false
jobs:
test:
name: Test (${{ matrix.os }})
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
runs-on: ${{ matrix.os }}
steps:
- name: Checkout
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7
with:
persist-credentials: false
- name: Setup Go
uses: actions/setup-go@924ae3a1cded613372ab5595356fb5720e22ba16 # v6
with:
go-version-file: go.mod
cache: false
- name: Verify mux import boundary
run: go test ./internal/muxtransport -run TestNoDirectMuxImports
- name: Test
run: go test ./...
release:
name: Publish
needs: test
runs-on: ubuntu-latest
permissions:
contents: write
id-token: write
steps:
- name: Checkout
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7
with:
persist-credentials: false
- name: Setup Go
uses: actions/setup-go@924ae3a1cded613372ab5595356fb5720e22ba16 # v6
with:
go-version-file: go.mod
cache: false
- name: Setup Node
uses: actions/setup-node@249970729cb0ef3589644e2896645e5dc5ba9c38 # v6
with:
node-version: 24
registry-url: https://registry.npmjs.org
package-manager-cache: false
- name: Prepare third-party source
run: |
go mod download github.com/libp2p/go-yamux/v5@v5.1.0
module_dir="$(go env GOMODCACHE)/github.com/libp2p/go-yamux/v5@v5.1.0"
test -f "$module_dir/LICENSE"
mkdir -p third_party
tar -C "$(dirname "$module_dir")" -czf third_party/go-yamux-v5.1.0-source.tar.gz "$(basename "$module_dir")"
sha256sum third_party/go-yamux-v5.1.0-source.tar.gz > third_party/go-yamux-v5.1.0-source.tar.gz.sha256
- name: Build package binaries
env:
GOFLAGS: -mod=readonly
VERSION: ${{ github.ref_name }}
run: |
version="${VERSION#v}"
mkdir -p vendor/linux-x64 vendor/linux-arm64 vendor/win32-x64 vendor/win32-arm64 vendor/darwin-x64 vendor/darwin-arm64
GOOS=linux GOARCH=amd64 go build -ldflags "-s -w -X main.version=${version}" -o vendor/linux-x64/gohere ./cmd/gohere
GOOS=linux GOARCH=arm64 go build -ldflags "-s -w -X main.version=${version}" -o vendor/linux-arm64/gohere ./cmd/gohere
GOOS=windows GOARCH=amd64 go build -ldflags "-s -w -X main.version=${version}" -o vendor/win32-x64/gohere.exe ./cmd/gohere
GOOS=windows GOARCH=arm64 go build -ldflags "-s -w -X main.version=${version}" -o vendor/win32-arm64/gohere.exe ./cmd/gohere
GOOS=darwin GOARCH=amd64 go build -ldflags "-s -w -X main.version=${version}" -o vendor/darwin-x64/gohere ./cmd/gohere
GOOS=darwin GOARCH=arm64 go build -ldflags "-s -w -X main.version=${version}" -o vendor/darwin-arm64/gohere ./cmd/gohere
- name: Generate npm package files
env:
VERSION: ${{ github.ref_name }}
run: |
version="${VERSION#v}"
mkdir -p bin
cat > package.json <<EOF
{
"name": "gohere",
"version": "${version}",
"description": "Tiny local dev URL launcher for .localhost projects.",
"bin": {
"gohere": "bin/gohere.js"
},
"files": [
"bin/",
"vendor/",
"third_party/",
"LICENSE",
"THIRD_PARTY_NOTICES"
],
"license": "Apache-2.0",
"repository": {
"type": "git",
"url": "git+https://github.com/roie/gohere.git"
},
"bugs": {
"url": "https://github.com/roie/gohere/issues"
},
"homepage": "https://github.com/roie/gohere#readme",
"keywords": [
"localhost",
"dev-server",
"cli"
],
"os": [
"linux",
"win32",
"darwin"
],
"cpu": [
"x64",
"arm64"
]
}
EOF
cat > bin/gohere.js <<'EOF'
#!/usr/bin/env node
const { spawnSync } = require("node:child_process");
const path = require("node:path");
const platform = process.platform;
const arch = process.arch;
const exe = platform === "win32" ? "gohere.exe" : "gohere";
const binary = path.join(__dirname, "..", "vendor", `${platform}-${arch}`, exe);
const result = spawnSync(binary, process.argv.slice(2), { stdio: "inherit" });
if (result.error) {
console.error(`gohere binary not available for ${platform}-${arch}`);
console.error(result.error.message);
process.exit(1);
}
if (result.signal) {
process.kill(process.pid, result.signal);
}
process.exit(result.status ?? 1);
EOF
chmod +x bin/gohere.js
- name: Pack and smoke test npm package
id: pack
env:
VERSION: ${{ github.ref_name }}
run: |
version="${VERSION#v}"
tarball="$(npm pack)"
echo "tarball=${tarball}" >> "$GITHUB_OUTPUT"
install_dir="$(mktemp -d)"
npm install --prefix "$install_dir" "$tarball"
gohere_bin="$install_dir/node_modules/.bin/gohere"
test "$("$gohere_bin" --version)" = "gohere ${version}"
test -f "$install_dir/node_modules/gohere/vendor/win32-x64/gohere.exe"
test -f "$install_dir/node_modules/gohere/vendor/win32-arm64/gohere.exe"
test -f "$install_dir/node_modules/gohere/LICENSE"
test -f "$install_dir/node_modules/gohere/THIRD_PARTY_NOTICES"
test -f "$install_dir/node_modules/gohere/third_party/go-yamux-v5.1.0-source.tar.gz"
test -f "$install_dir/node_modules/gohere/third_party/go-yamux-v5.1.0-source.tar.gz.sha256"
grep -q 'go-yamux v5.1.0' "$install_dir/node_modules/gohere/THIRD_PARTY_NOTICES"
grep -q 'gofrs/flock v0.13.0' "$install_dir/node_modules/gohere/THIRD_PARTY_NOTICES"
x_sys_version="$(go list -mod=mod -m -f '{{.Version}}' golang.org/x/sys)"
grep -q "golang.org/x/sys ${x_sys_version}" "$install_dir/node_modules/gohere/THIRD_PARTY_NOTICES"
smoke_dir="$(mktemp -d)"
mkdir -p "$smoke_dir/live" "$smoke_dir/dist" "$smoke_dir/pages"
echo '<html><body><h1>live</h1></body></html>' > "$smoke_dir/live/index.html"
echo '<h1>dist package smoke</h1>' > "$smoke_dir/dist/index.html"
echo '<h1>about package smoke</h1>' > "$smoke_dir/pages/about.html"
printf '\n' > "$smoke_dir/stdin"
route_pid=""
route_name=""
cleanup_route() {
if [ -n "$route_pid" ]; then
"$gohere_bin" stop "$route_name" >/dev/null 2>&1 || true
kill -TERM "$route_pid" >/dev/null 2>&1 || true
for _ in $(seq 1 40); do
if ! kill -0 "$route_pid" >/dev/null 2>&1; then
break
fi
sleep 0.25
done
kill -KILL "$route_pid" >/dev/null 2>&1 || true
wait "$route_pid" >/dev/null 2>&1 || true
route_pid=""
route_name=""
fi
}
wait_for_url() {
url="$1"
for _ in $(seq 1 80); do
if curl --fail --silent --max-time 2 "$url" > "$smoke_dir/response.html"; then
return 0
fi
sleep 0.25
done
echo "Timed out waiting for $url" >&2
return 1
}
start_route() {
name="$1"
url="$2"
shift 2
(
cd "$smoke_dir"
exec "$gohere_bin" "$@" --as "$name" < "$smoke_dir/stdin"
) > "$smoke_dir/$name.out" 2> "$smoke_dir/$name.err" &
route_pid="$!"
route_name="$name"
wait_for_url "$url"
}
trap cleanup_route EXIT
start_route package-live https://package-live.localhost/ ./live --live
grep -q '__gohere/live' "$smoke_dir/response.html"
cleanup_route
start_route package-dist https://package-dist.localhost/ ./dist
grep -q 'dist package smoke' "$smoke_dir/response.html"
cleanup_route
start_route package-about https://package-about.localhost/pages/about.html pages/about.html
grep -q 'about package smoke' "$smoke_dir/response.html"
cleanup_route
- name: Publish npm package
# Auth uses npm Trusted Publishing/OIDC for this workflow, so NODE_AUTH_TOKEN is intentionally not set.
env:
TARBALL: ${{ steps.pack.outputs.tarball }}
run: npm publish "$TARBALL" --access public
- name: Create GitHub release
env:
GH_TOKEN: ${{ github.token }}
RELEASE_TAG: ${{ github.ref_name }}
run: >-
gh release create "$RELEASE_TAG"
--title "$RELEASE_TAG"
--generate-notes