-
Notifications
You must be signed in to change notification settings - Fork 0
208 lines (206 loc) · 7.97 KB
/
publish.yml
File metadata and controls
208 lines (206 loc) · 7.97 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
name: Publish
on:
workflow_dispatch:
concurrency:
group: publish
cancel-in-progress: true
permissions:
contents: write
id-token: write
jobs:
release:
name: Check
runs-on: ubuntu-latest
outputs:
should_publish: ${{ steps.check.outputs.should_publish }}
publish_native_window: ${{ steps.check.outputs.publish_native_window }}
publish_ipc: ${{ steps.check.outputs.publish_ipc }}
publish_ipc_react: ${{ steps.check.outputs.publish_ipc_react }}
publish_tsdb: ${{ steps.check.outputs.publish_tsdb }}
steps:
- uses: actions/checkout@v6
- uses: actions/setup-node@v6
with:
node-version: 22
registry-url: https://registry.npmjs.org
- id: check
name: Check which packages need publishing
run: |
check_version() {
local pkg_dir=$1
local npm_name=$2
local output_name=$3
local local_ver=$(node -p "require('./${pkg_dir}/package.json').version")
local npm_ver
npm_ver=$(npm view "${npm_name}" version 2>/dev/null) || npm_ver="0.0.0"
echo "${output_name}: local=${local_ver} npm=${npm_ver}"
if [ "$local_ver" != "$npm_ver" ]; then
echo "${output_name}=true" >> $GITHUB_OUTPUT
else
echo "${output_name}=false" >> $GITHUB_OUTPUT
fi
}
check_version "packages/webview" "@nativewindow/webview" "publish_native_window"
check_version "packages/ipc" "@nativewindow/ipc" "publish_ipc"
check_version "packages/ipc-react" "@nativewindow/react" "publish_ipc_react"
check_version "packages/tsdb" "@nativewindow/tsdb" "publish_tsdb"
# should_publish is true if any package needs publishing
if grep -q "=true" <<< "$(cat $GITHUB_OUTPUT)"; then
echo "should_publish=true" >> $GITHUB_OUTPUT
else
echo "should_publish=false" >> $GITHUB_OUTPUT
fi
build:
name: Build - ${{ matrix.target }}
needs: release
if: needs.release.outputs.publish_native_window == 'true'
runs-on: ${{ matrix.runner }}
strategy:
fail-fast: false
matrix:
include:
- target: aarch64-apple-darwin
runner: macos-latest
- target: x86_64-apple-darwin
runner: macos-latest
- target: x86_64-pc-windows-msvc
runner: windows-latest
- target: aarch64-pc-windows-msvc
runner: windows-latest
- target: aarch64-unknown-linux-gnu
runner: ubuntu-24.04-arm
- target: x86_64-unknown-linux-gnu
runner: ubuntu-latest
steps:
- uses: actions/checkout@v6
- uses: oven-sh/setup-bun@v2
- run: bun install --frozen-lockfile
- uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.target }}
- name: Install Linux dependencies
if: contains(matrix.target, 'linux')
run: |
sudo apt-get update
sudo apt-get install -y \
pkg-config \
libgtk-3-dev \
libwebkit2gtk-4.1-dev \
libjavascriptcoregtk-4.1-dev \
libsoup-3.0-dev
- uses: actions/cache@v5
with:
path: |
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
packages/webview/target/
key: cargo-${{ matrix.target }}-${{ hashFiles('packages/webview/Cargo.lock') }}
restore-keys: cargo-${{ matrix.target }}-
- run: bun napi build --release --platform --target ${{ matrix.target }}
working-directory: packages/webview
- uses: actions/upload-artifact@v7
with:
name: bindings-${{ matrix.target }}
path: packages/webview/native-window.*.node
if-no-files-found: error
publish:
name: Publish to npm
needs: [release, build]
if: >-
always() &&
needs.release.outputs.should_publish == 'true' &&
(needs.build.result == 'success' || needs.build.result == 'skipped')
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- uses: oven-sh/setup-bun@v2
- run: bun install --frozen-lockfile
- uses: actions/setup-node@v6
with:
node-version: 24
# ---- @nativewindow/webview (conditional) ----
- name: Sync platform package versions
if: needs.release.outputs.publish_native_window == 'true'
run: bunx napi version
working-directory: packages/webview
- name: Sync optionalDependencies versions
if: needs.release.outputs.publish_native_window == 'true'
run: |
node -e "
const fs = require('fs');
const pkg = JSON.parse(fs.readFileSync('package.json', 'utf8'));
for (const dep of Object.keys(pkg.optionalDependencies || {})) {
pkg.optionalDependencies[dep] = pkg.version;
}
fs.writeFileSync('package.json', JSON.stringify(pkg, null, 2) + '\n');
"
working-directory: packages/webview
- uses: actions/download-artifact@v8
if: needs.release.outputs.publish_native_window == 'true'
with:
path: packages/webview/artifacts
- name: Move artifacts to platform packages
if: needs.release.outputs.publish_native_window == 'true'
run: bunx napi artifacts
working-directory: packages/webview
- name: Copy README to webview
run: cp README.md packages/webview/
- name: List platform packages
if: needs.release.outputs.publish_native_window == 'true'
run: ls -R packages/webview/npm/
- name: Build webview (ts)
if: needs.release.outputs.publish_native_window == 'true'
run: bun run build:ts
working-directory: packages/webview
# ---- Common ----
- name: Copy LICENSE to packages
run: |
for dir in packages/*/; do
cp LICENSE "$dir"
done
- name: Publish platform packages
if: needs.release.outputs.publish_native_window == 'true'
run: |
for dir in packages/webview/npm/*/; do
npm publish "$dir" --access public --provenance
done
# ---- @nativewindow/webview (conditional) ----
- name: Publish @nativewindow/webview
if: needs.release.outputs.publish_native_window == 'true'
run: npm publish --access public --provenance
working-directory: packages/webview
# ---- @nativewindow/ipc (conditional) ----
- name: Build @nativewindow/ipc
if: needs.release.outputs.publish_ipc == 'true'
run: bun run build
working-directory: packages/ipc
- name: Publish @nativewindow/ipc
if: needs.release.outputs.publish_ipc == 'true'
run: npm publish --access public --provenance
working-directory: packages/ipc
# ---- @nativewindow/react (conditional) ----
- name: Build @nativewindow/react
if: needs.release.outputs.publish_ipc_react == 'true'
run: bun run build
working-directory: packages/react
- name: Publish @nativewindow/react
if: needs.release.outputs.publish_ipc_react == 'true'
run: npm publish --access public --provenance
working-directory: packages/react
# ---- @nativewindow/tsdb (conditional) ----
- name: Build @nativewindow/tsdb
if: needs.release.outputs.publish_tsdb == 'true'
run: bun run build
working-directory: packages/tsdb
- name: Publish @nativewindow/tsdb
if: needs.release.outputs.publish_tsdb == 'true'
run: npm publish --access public --provenance
working-directory: packages/tsdb
- name: Create GitHub Release
if: needs.release.outputs.publish_native_window == 'true'
run: |
version=$(node -p "require('./packages/webview/package.json').version")
gh release create "v${version}" --title "v${version}" --generate-notes
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}