-
Notifications
You must be signed in to change notification settings - Fork 0
161 lines (140 loc) · 5.7 KB
/
Copy pathrelease-macos.yml
File metadata and controls
161 lines (140 loc) · 5.7 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
name: Release CLI (macOS)
# macOS lives in its own workflow so its slower runners never block the
# linux/windows release. Triggered by the same v* tags (and manual dispatch);
# runs in parallel with "Release CLI".
on:
push:
tags:
- "v*"
workflow_dispatch:
inputs:
release_version:
description: Release version without the leading v
required: true
type: string
jobs:
build-macos:
name: Build ${{ matrix.target.rust_target }}
runs-on: ${{ matrix.target.runner }}
strategy:
fail-fast: false
matrix:
target:
- runner: macos-14
rust_target: aarch64-apple-darwin
- runner: macos-14
rust_target: x86_64-apple-darwin
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.target.rust_target }}
- name: Build release binary
run: cargo build --release --target ${{ matrix.target.rust_target }}
# Guard against the v0.1.10 incident: the npm package version is stamped
# from the tag / dispatch input, so a binary built from a checkout whose
# Cargo.toml wasn't bumped would ship mislabeled — and its self-update
# check would nag users forever. Fail the release instead.
- name: Verify binary version matches the release version
shell: bash
run: |
if [ "${GITHUB_EVENT_NAME}" = "workflow_dispatch" ]; then
expected="${{ inputs.release_version }}"
else
expected="${GITHUB_REF_NAME#v}"
fi
actual="$(./target/${{ matrix.target.rust_target }}/release/jucode --version | awk '{print $NF}')"
echo "expected=${expected} actual=${actual}"
if [ "${actual}" != "${expected}" ]; then
echo "::error::built binary reports ${actual} but the release is ${expected} — bump Cargo.toml (and commit) before tagging"
exit 1
fi
- name: Stage artifact
shell: bash
run: |
mkdir -p artifacts/${{ matrix.target.rust_target }}
cp target/${{ matrix.target.rust_target }}/release/jucode artifacts/${{ matrix.target.rust_target }}/jucode
- uses: actions/upload-artifact@v4
with:
name: ${{ matrix.target.rust_target }}
path: artifacts/${{ matrix.target.rust_target }}/jucode
release-macos:
name: Publish macOS release assets
needs: build-macos
runs-on: ubuntu-latest
permissions:
contents: write
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
registry-url: https://registry.npmjs.org/
- uses: actions/download-artifact@v4
with:
path: artifacts
merge-multiple: false
- name: Resolve release metadata
id: release_meta
shell: bash
run: |
if [ "${GITHUB_EVENT_NAME}" = "workflow_dispatch" ]; then
echo "version=${{ inputs.release_version }}" >> "$GITHUB_OUTPUT"
echo "tag=v${{ inputs.release_version }}" >> "$GITHUB_OUTPUT"
else
echo "version=${GITHUB_REF_NAME#v}" >> "$GITHUB_OUTPUT"
echo "tag=${GITHUB_REF_NAME}" >> "$GITHUB_OUTPUT"
fi
- name: Normalize artifact layout
shell: bash
run: |
mkdir -p artifacts-normalized
for dir in artifacts/*; do
target="$(basename "$dir")"
mkdir -p "artifacts-normalized/$target"
cp "$dir"/* "artifacts-normalized/$target/"
done
- name: Sync npm versions
env:
RELEASE_VERSION: ${{ steps.release_meta.outputs.version }}
run: npm run release:sync-version
- name: Stage npm binaries
run: npm run release:stage-binaries -- --source-root artifacts-normalized --target aarch64-apple-darwin --target x86_64-apple-darwin
- name: Pack npm packages
run: npm run release:pack -- --target aarch64-apple-darwin --target x86_64-apple-darwin
- name: Name macOS binaries uniquely for the release
shell: bash
run: |
cp artifacts-normalized/aarch64-apple-darwin/jucode jucode-aarch64-apple-darwin
cp artifacts-normalized/x86_64-apple-darwin/jucode jucode-x86_64-apple-darwin
- name: Upload macOS assets to GitHub release
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ steps.release_meta.outputs.tag }}
files: |
jucode-*-apple-darwin
dist/npm/*darwin*.tgz
- name: Publish macOS npm packages
if: ${{ env.NODE_AUTH_TOKEN != '' }}
shell: bash
run: |
version="${{ steps.release_meta.outputs.version }}"
npm view "@jucode/cli-darwin-arm64@${version}" version >/dev/null 2>&1 || npm publish ./npm/cli-darwin-arm64 --access public
npm view "@jucode/cli-darwin-x64@${version}" version >/dev/null 2>&1 || npm publish ./npm/cli-darwin-x64 --access public
- name: Publish root npm package after all platforms
if: ${{ env.NODE_AUTH_TOKEN != '' }}
shell: bash
run: |
version="${{ steps.release_meta.outputs.version }}"
for _ in {1..30}; do
if npm view "@jucode/cli-linux-x64@${version}" version >/dev/null 2>&1 && \
npm view "@jucode/cli-win32-x64@${version}" version >/dev/null 2>&1; then
npm view "@jucode/cli@${version}" version >/dev/null 2>&1 || npm publish ./npm/cli --access public
exit 0
fi
sleep 10
done
echo "::error::Linux/Windows npm packages for ${version} were not published"
exit 1