Repository navigation
236 lines (216 loc) · 8.48 KB
/
Copy pathrelease.yml
File metadata and controls
236 lines (216 loc) · 8.48 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
name: release
on:
push:
tags: ["v*"]
workflow_dispatch:
inputs:
tag:
description: "Existing tag to (re)build, e.g. v0.1.0"
required: true
npm_only:
description: "Only publish that tag's npm packages (its GitHub release and crates.io are done)"
type: boolean
default: false
permissions:
contents: write
env:
CARGO_TERM_COLOR: always
BIN: idx
jobs:
build:
name: ${{ matrix.target }}
# Skipped with it: the release and crates.io, which need it.
if: ${{ !inputs.npm_only }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
include:
- { os: ubuntu-latest, target: x86_64-unknown-linux-musl, cross: true, archive: tar.gz }
- { os: ubuntu-latest, target: aarch64-unknown-linux-musl, cross: true, archive: tar.gz }
- { os: macos-latest, target: x86_64-apple-darwin, cross: false, archive: tar.gz }
- { os: macos-latest, target: aarch64-apple-darwin, cross: false, archive: tar.gz }
- { os: windows-latest, target: x86_64-pc-windows-msvc, cross: false, archive: zip }
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.event.inputs.tag || github.ref }}
- uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.target }}
- uses: Swatinem/rust-cache@v2
with:
key: ${{ matrix.target }}
- name: Install cross
if: matrix.cross
uses: taiki-e/install-action@cross
- name: Build (cross)
if: matrix.cross
run: cross build --release --locked --target ${{ matrix.target }}
- name: Build (native)
if: ${{ !matrix.cross }}
run: cargo build --release --locked --target ${{ matrix.target }}
- name: Version from tag
id: v
shell: bash
run: |
ref="${{ github.event.inputs.tag || github.ref_name }}"
echo "version=${ref#v}" >> "$GITHUB_OUTPUT"
- name: Package
shell: bash
run: |
set -euo pipefail
name="${BIN}-${{ steps.v.outputs.version }}-${{ matrix.target }}"
mkdir -p "dist/$name"
if [ "${{ matrix.archive }}" = "zip" ]; then
cp "target/${{ matrix.target }}/release/${BIN}.exe" "dist/$name/"
else
cp "target/${{ matrix.target }}/release/${BIN}" "dist/$name/"
fi
cp README.md LICENSE CHANGELOG.md "dist/$name/"
cd dist
if [ "${{ matrix.archive }}" = "zip" ]; then
7z a -tzip "$name.zip" "$name" >/dev/null
asset="$name.zip"
else
tar -czf "$name.tar.gz" "$name"
asset="$name.tar.gz"
fi
if command -v sha256sum >/dev/null; then sha256sum "$asset" > "$asset.sha256"; else shasum -a 256 "$asset" > "$asset.sha256"; fi
rm -rf "$name"
ls -la
- name: Smoke the binary
if: ${{ !matrix.cross }}
shell: bash
run: |
bin="target/${{ matrix.target }}/release/${BIN}"
[ -f "$bin" ] || bin="$bin.exe"
"$bin" version
"$bin" --offline -o json stocks quote BBCA || test $? -eq 5
- uses: actions/upload-artifact@v4
with:
name: ${{ matrix.target }}
path: dist/*
if-no-files-found: error
release:
needs: build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.event.inputs.tag || github.ref }}
- uses: actions/download-artifact@v4
with:
path: dist
merge-multiple: true
- name: Checksums
run: |
cd dist
rm -f SHA256SUMS
sha256sum *.tar.gz *.zip > SHA256SUMS
cat SHA256SUMS
- name: Release notes from CHANGELOG
id: notes
run: |
tag="${{ github.event.inputs.tag || github.ref_name }}"
ver="${tag#v}"
# The version's own section; [Unreleased] only when there is none
# (an empty [Unreleased] heading sits above the version after a release).
section() {
awk -v want="[$1]" '
/^## \[/ { if (found) exit; if (index($0, want)) { found=1; next } }
found { print }
' CHANGELOG.md
}
blank() { [ -z "$(tr -d '[:space:]' < notes.md)" ]; }
section "$ver" > notes.md
if blank; then section "Unreleased" > notes.md; fi
if blank; then echo "Release $tag" > notes.md; fi
echo "Install: \`curl -fsSL https://raw.githubusercontent.com/${{ github.repository }}/main/install.sh | sh\`" >> notes.md
- uses: softprops/action-gh-release@v2
with:
tag_name: ${{ github.event.inputs.tag || github.ref_name }}
body_path: notes.md
files: |
dist/*.tar.gz
dist/*.zip
dist/*.sha256
dist/SHA256SUMS
crates:
# Publishes ihsg-cli to crates.io. Enable with the repository variable
# CRATES_PUBLISH=true, then either add a CARGO_REGISTRY_TOKEN secret or
# configure crates.io Trusted Publishing for this workflow (no secret).
needs: release
runs-on: ubuntu-latest
if: ${{ vars.CRATES_PUBLISH == 'true' }}
permissions:
contents: read
id-token: write
env:
HAS_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN != '' }}
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.event.inputs.tag || github.ref }}
- uses: dtolnay/rust-toolchain@stable
- name: Tag matches Cargo.toml
run: |
tag="${{ github.event.inputs.tag || github.ref_name }}"
ver="$(cargo metadata --no-deps --format-version 1 | python3 -c 'import json,sys; print(json.load(sys.stdin)["packages"][0]["version"])')"
[ "v$ver" = "$tag" ] || { echo "Cargo.toml version $ver does not match tag $tag"; exit 1; }
- name: Trusted publishing token
id: auth
if: env.HAS_TOKEN != 'true'
uses: rust-lang/crates-io-auth-action@v1
- name: cargo publish
run: |
ver="$(cargo metadata --no-deps --format-version 1 | python3 -c 'import json,sys; print(json.load(sys.stdin)["packages"][0]["version"])')"
if curl -fsS -A "ihsg-cli-release (github.com/fzn0x/idx)" "https://crates.io/api/v1/crates/ihsg-cli/$ver" >/dev/null 2>&1; then
echo "ihsg-cli $ver is already on crates.io"; exit 0
fi
cargo publish --locked
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN || steps.auth.outputs.token }}
npm:
# Publishes both npm packages: ihsg-cli (npm/, the CLI) and ihsg-mcp
# (npm-mcp/, `npx -y ihsg-mcp` runs `idx mcp`). Enable with
# NPM_PUBLISH=true, then either add an NPM_TOKEN secret or configure npm
# Trusted Publishing for this workflow on each package. Trusted Publishing
# can only be set up on a package that already exists, so a new package
# is published once by hand (with 2FA) before this job takes it over.
# A dispatch with npm_only publishes an existing tag's packages alone,
# without rebuilding (and so changing) the release's binaries.
needs: release
runs-on: ubuntu-latest
if: ${{ !cancelled() && vars.NPM_PUBLISH == 'true' && (inputs.npm_only || needs.release.result == 'success') }}
strategy:
fail-fast: false
matrix:
dir: [npm, npm-mcp]
permissions:
contents: read
id-token: write
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.event.inputs.tag || github.ref }}
- uses: actions/setup-node@v4
with:
node-version: 24
registry-url: https://registry.npmjs.org
- name: Set version from tag
working-directory: ${{ matrix.dir }}
run: |
tag="${{ github.event.inputs.tag || github.ref_name }}"
npm version --no-git-tag-version --allow-same-version "${tag#v}"
- name: npm publish
working-directory: ${{ matrix.dir }}
run: |
name="$(node -p "require('./package.json').name")"
ver="$(node -p "require('./package.json').version")"
if npm view "$name@$ver" version >/dev/null 2>&1; then echo "$name $ver is already on npm"; exit 0; fi
# Verbose: npm logs a failed Trusted Publishing exchange only at
# this level, and then stops with a bare ENEEDAUTH (#124).
npm publish --access public --provenance --loglevel verbose
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}