Repository navigation
217 lines (188 loc) · 6.67 KB
/
Copy pathpublish-to-npm.yml
File metadata and controls
217 lines (188 loc) · 6.67 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
name: Publish to npm
on:
workflow_call:
inputs:
version:
description: 'Version to publish (e.g., 1.0.0)'
required: true
type: string
dry_run:
description: 'Dry run (do not actually publish)'
required: false
default: false
type: boolean
workflow_dispatch:
inputs:
version:
description: 'Version to publish (e.g., 1.0.0)'
required: true
type: string
dry_run:
description: 'Dry run (do not actually publish)'
required: false
default: false
type: boolean
permissions:
contents: read
jobs:
build-and-publish:
runs-on: ${{ matrix.os }}
timeout-minutes: 60
strategy:
fail-fast: false
matrix:
include:
- target: x86_64-unknown-linux-musl
os: ubuntu-latest
platform: linux-x64
- target: aarch64-unknown-linux-musl
os: ubuntu-latest
platform: linux-arm64
- target: x86_64-apple-darwin
os: macos-latest
platform: darwin-x64
- target: aarch64-apple-darwin
os: macos-latest
platform: darwin-arm64
- target: x86_64-pc-windows-gnu
os: ubuntu-latest
platform: win32-x64
- target: aarch64-pc-windows-msvc
os: windows-latest
platform: win32-arm64
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Get version from release or input
id: get_version
shell: bash
run: |
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
VERSION="${{ github.event.inputs.version }}"
else
VERSION="${{ github.event.release.tag_name }}"
fi
echo "version=${VERSION}" >> $GITHUB_OUTPUT
echo "tag=${VERSION}" >> $GITHUB_OUTPUT
- name: Setup Rust
uses: ./.github/actions/setup-rust
with:
targets: ${{ matrix.target }}
cache-key: ${{ matrix.target }}
- name: Install musl toolchain
if: contains(matrix.target, 'musl')
run: |
sudo apt-get update
sudo apt-get install -y musl-tools
if [ "${{ matrix.target }}" = "aarch64-unknown-linux-musl" ]; then
# Install aarch64 cross-compilation tools
sudo apt-get install -y gcc-aarch64-linux-gnu libc6-dev-arm64-cross
fi
- name: Install Windows cross-compilation tools
if: matrix.target == 'x86_64-pc-windows-gnu'
run: |
sudo apt-get update
sudo apt-get install -y gcc-mingw-w64-x86-64
- name: Install cargo-audit
if: matrix.target == 'x86_64-unknown-linux-musl'
uses: taiki-e/install-action@v2
with:
tool: cargo-audit
- name: Security audit
if: matrix.target == 'x86_64-unknown-linux-musl'
run: cargo audit
- name: Build binary
timeout-minutes: 30
run: cargo build --release --target ${{ matrix.target }}
env:
CARGO_TERM_COLOR: always
RUST_BACKTRACE: 1
RUSTFLAGS: "-C strip=symbols -C codegen-units=1"
# aarch64 cross-compilation linker
CC_aarch64_unknown_linux_musl: aarch64-linux-gnu-gcc
CARGO_TARGET_AARCH64_UNKNOWN_LINUX_MUSL_LINKER: aarch64-linux-gnu-gcc
- name: Verify binary
shell: bash
run: |
if [ "${{ matrix.platform }}" = "win32-x64" ] || [ "${{ matrix.platform }}" = "win32-arm64" ]; then
BINARY_PATH="target/${{ matrix.target }}/release/mocks.exe"
else
BINARY_PATH="target/${{ matrix.target }}/release/mocks"
fi
if [ ! -f "$BINARY_PATH" ]; then
echo "Binary not found at $BINARY_PATH"
exit 1
fi
ls -la "$BINARY_PATH"
- name: Prepare platform package
shell: bash
run: |
mkdir -p dist/${{ matrix.platform }}
# Check if packages directory exists
if [ ! -d "packages/@mocks-rs/mocks-${{ matrix.platform }}" ]; then
echo "packages/@mocks-rs/mocks-${{ matrix.platform }} directory not found"
exit 1
fi
cp -r packages/@mocks-rs/mocks-${{ matrix.platform }}/* dist/${{ matrix.platform }}/
# Copy the binary to the platform package
if [ "${{ matrix.platform }}" = "win32-x64" ] || [ "${{ matrix.platform }}" = "win32-arm64" ]; then
cp target/${{ matrix.target }}/release/mocks.exe dist/${{ matrix.platform }}/
else
cp target/${{ matrix.target }}/release/mocks dist/${{ matrix.platform }}/
fi
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
registry-url: 'https://registry.npmjs.org'
cache: 'npm'
cache-dependency-path: 'dist/${{ matrix.platform }}/package.json'
- name: Dry run publish platform package
if: github.event.inputs.dry_run == 'true' || inputs.dry_run == true
shell: bash
run: |
cd dist/${{ matrix.platform }}
npm publish --access public --dry-run
- name: Publish platform package
if: github.event.inputs.dry_run == 'false' || inputs.dry_run == false
shell: bash
run: |
cd dist/${{ matrix.platform }}
npm publish --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
publish-main:
needs: build-and-publish
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
registry-url: 'https://registry.npmjs.org'
cache: 'npm'
cache-dependency-path: 'packages/@mocks-rs/mocks/package.json'
- name: Verify main package
shell: bash
run: |
if [ ! -d "packages/@mocks-rs/mocks" ]; then
echo "packages/@mocks-rs/mocks directory not found"
exit 1
fi
ls -la packages/@mocks-rs/mocks/
- name: Dry run publish main package
if: github.event.inputs.dry_run == 'true' || inputs.dry_run == true
shell: bash
run: |
cd packages/@mocks-rs/mocks
npm publish --access public --dry-run
- name: Publish main package
if: github.event.inputs.dry_run == 'false' || inputs.dry_run == false
shell: bash
run: |
cd packages/@mocks-rs/mocks
npm publish --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}