-
-
Notifications
You must be signed in to change notification settings - Fork 18
242 lines (209 loc) · 7.14 KB
/
publish.yml
File metadata and controls
242 lines (209 loc) · 7.14 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
name: Publish Packages
permissions:
contents: read
packages: read
on:
push:
tags:
- 'v*'
workflow_dispatch:
inputs:
npm_tag:
description: 'NPM tag to publish as (overrides default)'
required: false
default: 'latest'
dry_run:
description: 'Set to "true" to skip publishing and release upload (dry run)'
required: false
default: 'false'
permissions:
contents: read
env:
NPM_TAG: "latest"
NPM_PACKAGES: canvas,canvas-babylon,canvas-media,canvas-phaser,canvas-phaser-ce,canvas-pixi,canvas-polyfill,canvas-three,canvas-svg
jobs:
build-linux:
name: Build Linux native artifacts
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: 22
- name: Cache node modules
uses: actions/cache@v4
with:
path: |
~/.npm
~/.cache
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}-${{ hashFiles('**/package.json') }}
restore-keys: |
${{ runner.os }}-node-
- name: Install Rust
run: |
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --profile minimal
echo "$HOME/.cargo/bin" >> $GITHUB_PATH
- name: Use Rust nightly
run: rustup default nightly
- name: Install deps (root)
run: npm ci
- name: Cache cargo
uses: actions/cache@v4
with:
path: |
~/.cargo/registry
~/.cargo/git
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-cargo-
- name: Build Android (make android)
run: |
set -e
make android
- name: Copy AAR into package
run: |
set -e
./tools/scripts/copy-android.sh
- name: Upload Android platforms
uses: actions/upload-artifact@v4
with:
name: android-platforms
path: packages/canvas/platforms/android
build-macos:
name: Build macOS native artifacts
runs-on: macos-14
steps:
- uses: actions/checkout@v4
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: 22
- name: Cache node modules
uses: actions/cache@v4
with:
path: |
~/.npm
~/.cache
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}-${{ hashFiles('**/package.json') }}
restore-keys: |
${{ runner.os }}-node-
- name: Install Rust
run: |
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --profile minimal
echo "$HOME/.cargo/bin" >> $GITHUB_PATH
- name: Use Rust nightly
run: rustup default nightly
- name: Install root deps
run: npm ci
- name: Cache cargo
uses: actions/cache@v4
with:
path: |
~/.cargo/registry
~/.cargo/git
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-cargo-
- name: Build iOS (make ios)
run: |
set -e
make ios
- name: Build and copy iOS XCFramework
run: |
set -e
./tools/scripts/canvas-build.sh
- name: Upload iOS platforms
uses: actions/upload-artifact@v4
with:
name: ios-platforms
path: packages/canvas/platforms/ios
publish:
name: Publish to npm
runs-on: ubuntu-22.04
needs: [ build-linux, build-macos ]
steps:
- uses: actions/checkout@v4
- name: Download linux artifacts
uses: actions/download-artifact@v4
with:
name: napi-linux-artifacts
path: ./artifacts/linux
- name: Cache cargo
uses: actions/cache@v4
with:
path: |
~/.cargo/registry
~/.cargo/git
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-cargo-
- name: Download mac artifacts
uses: actions/download-artifact@v4
with:
name: napi-macos-artifacts
path: ./artifacts/macos
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: 22
- name: Install root deps
run: npm ci
- name: Compute NPM_VERSION
run: |
if [[ "${GITHUB_REF}" == refs/tags/* ]]; then
TAG=${GITHUB_REF#refs/tags/}
echo "Detected tag $TAG"
echo "NPM_VERSION=$TAG" >> $GITHUB_ENV
# set NPM_TAG to prefix of tag (e.g. rc/, beta) or the tag itself
echo "NPM_TAG=${TAG%%-*}" >> $GITHUB_ENV
else
if [ -n "${{ github.event.inputs.npm_tag }}" ]; then
NT="${{ github.event.inputs.npm_tag }}"
else
NT="$NPM_TAG"
fi
echo "NPM_TAG=$NT" >> $GITHUB_ENV
echo "NPM_VERSION=$(node -e \"console.log(require('./packages/canvas/package.json').version)\")-$NT-$(date +\"%Y%m%d\")-$GITHUB_RUN_ID" >> $GITHUB_ENV
fi
- name: Bump packages (no git tags)
run: |
for pkg in packages/canvas packages/canvas-babylon packages/canvas-media packages/canvas-phaser packages/canvas-phaser-ce packages/canvas-pixi packages/canvas-polyfill packages/canvas-three packages/canvas-svg; do
if [ -f "$pkg/package.json" ]; then
(cd "$pkg" && npm --no-git-tag-version version "$NPM_VERSION")
fi
done
- name: Create project .npmrc (in-repo)
if: ${{ secrets.NPM_PUBLISH_TOKEN != '' }}
run: |
echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_PUBLISH_TOKEN }}" > .npmrc
- name: Build all packages
run: |
npx nx run canvas:build.all
- name: Publish packages
if: ${{ github.event.inputs.dry_run != 'true' }}
env:
NPM_TOKEN: ${{ secrets.NPM_PUBLISH_TOKEN }}
run: |
if [ -z "$NPM_TOKEN" ]; then
echo "NPM token missing. Set secrets.NPM_PUBLISH_TOKEN to proceed." && exit 1
fi
echo "Publishing packages with version $NPM_VERSION and tag $NPM_TAG"
npm run publish-packages --name "$NPM_PACKAGES" --verify true --version "$NPM_VERSION" --tag "$NPM_TAG"
- name: Clean up .npmrc
if: always()
run: rm -f .npmrc || true
- name: Create release tarball
if: startsWith(github.ref, 'refs/tags/') && github.event.inputs.dry_run != 'true'
run: |
set -e
TAR_NAME=release-${NPM_VERSION}.tar.gz
tar -czf ${TAR_NAME} dist packages/canvas/platforms || true
echo "Created ${TAR_NAME}"
- name: Create GitHub release and upload assets
if: startsWith(github.ref, 'refs/tags/') && github.event.inputs.dry_run != 'true'
uses: softprops/action-gh-release@v1
with:
files: release-${NPM_VERSION}.tar.gz
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}