@@ -2,6 +2,7 @@ name: Build PDF Runtime
22
33on :
44 workflow_dispatch :
5+ workflow_call :
56 pull_request :
67 paths :
78 - ' packages/pdf-runtime/**'
@@ -40,34 +41,78 @@ jobs:
4041 with :
4142 node-version : 22
4243 cache : pnpm
43- - if : ${{ !contains(matrix.target, 'linuxmusl') }}
44+ - name : Cache runtime payload
45+ id : payload-cache
46+ uses : actions/cache@v4
47+ with :
48+ path : packages/pdf-runtime/.cache/payloads/${{ matrix.target }}
49+ key : pdf-runtime-payload-${{ matrix.target }}-${{ hashFiles(
50+ ' packages/pdf-runtime/pdf-runtime-build.json' ,
51+ ' packages/pdf-runtime/scripts/build-target.sh' ,
52+ ' packages/pdf-runtime/scripts/fetch-libpdfium.sh' ,
53+ ' packages/pdf-runtime/build/generate-functions.mjs' ,
54+ ' packages/pdf-runtime/build/generate-runtime-methods.mjs' ,
55+ ' packages/pdf-runtime/build/generate-napi-binding.mjs' ,
56+ ' packages/pdf-runtime/build/CMakeLists.txt' ,
57+ ' packages/pdf-runtime/build/compile.sh' ,
58+ ' packages/pdf-runtime/build/compile.esm.sh'
59+ ) }}
60+ - if : steps.payload-cache.outputs.cache-hit == 'true'
61+ name : Restore payload from cache
62+ shell : bash
63+ run : |
64+ mkdir -p "packages/pdf-runtime/npm/${{ matrix.target }}"
65+ cp -R "packages/pdf-runtime/.cache/payloads/${{ matrix.target }}/." \
66+ "packages/pdf-runtime/npm/${{ matrix.target }}/"
67+ - if : ${{ steps.payload-cache.outputs.cache-hit != 'true' && !contains(matrix.target, 'linuxmusl') }}
4468 run : pnpm install --frozen-lockfile
45- - if : ${{ !contains(matrix.target, 'linuxmusl') }}
69+ - if : ${{ steps.payload-cache.outputs.cache-hit != 'true' && !contains(matrix.target, 'linuxmusl') }}
4670 name : Install build tools
4771 run : sudo apt-get update && sudo apt-get install -y cmake clang lld
48- - if : matrix.target == 'wasm32'
72+ - if : ${{ steps.payload-cache.outputs.cache-hit != 'true' && matrix.target == 'wasm32' }}
4973 name : Install Emscripten
5074 run : |
5175 git clone https://github.com/emscripten-core/emsdk.git "$RUNNER_TEMP/emsdk"
5276 "$RUNNER_TEMP/emsdk/emsdk" install "$EMSDK_VERSION"
5377 "$RUNNER_TEMP/emsdk/emsdk" activate "$EMSDK_VERSION"
5478 echo "$RUNNER_TEMP/emsdk/upstream/emscripten" >> "$GITHUB_PATH"
5579 echo "$RUNNER_TEMP/emsdk/upstream/bin" >> "$GITHUB_PATH"
56- - if : ${{ !contains(matrix.target, 'linuxmusl') }}
80+ - if : ${{ steps.payload-cache.outputs.cache-hit != 'true' && !contains(matrix.target, 'linuxmusl') }}
5781 name : Build target
5882 env :
5983 CC : clang
6084 CXX : clang++
6185 LDFLAGS : -fuse-ld=lld
6286 run : pnpm --filter @embedpdf/pdf-runtime build:target ${{ matrix.target }}
63- - if : ${{ contains(matrix.target, 'linuxmusl') }}
87+ - if : ${{ steps.payload-cache.outputs.cache-hit != 'true' && contains(matrix.target, 'linuxmusl') }}
6488 name : Build musl target in Alpine
6589 run : |
6690 docker run --rm \
6791 -v "$GITHUB_WORKSPACE:/workspace" \
6892 -w /workspace \
6993 node:22-alpine \
7094 sh -lc "apk add --no-cache bash cmake clang g++ make python3 curl tar git && corepack enable && pnpm install --frozen-lockfile && pnpm --filter @embedpdf/pdf-runtime build:target ${{ matrix.target }}"
95+ - if : steps.payload-cache.outputs.cache-hit != 'true'
96+ name : Stage payload to cache path
97+ shell : bash
98+ run : |
99+ src="packages/pdf-runtime/npm/${{ matrix.target }}"
100+ dst="packages/pdf-runtime/.cache/payloads/${{ matrix.target }}"
101+ mkdir -p "$dst"
102+ case "${{ matrix.target }}" in
103+ wasm32)
104+ cp "$src/pdfium.js" "$src/pdfium.cjs" "$src/pdfium.wasm" "$dst/"
105+ ;;
106+ win32-*)
107+ cp "$src/pdf-runtime.node" "$src/pdfium.dll" "$dst/"
108+ ;;
109+ *)
110+ cp "$src/pdf-runtime.node" "$dst/"
111+ ;;
112+ esac
113+ - name : Verify payload
114+ shell : bash
115+ run : bash packages/pdf-runtime/scripts/verify-packages.sh ${{ matrix.target }}
71116 - uses : actions/upload-artifact@v6
72117 with :
73118 name : pdf-runtime-${{ matrix.target }}
@@ -91,26 +136,60 @@ jobs:
91136 with :
92137 node-version : 22
93138 cache : pnpm
94- - if : ${{ !contains(matrix.target, 'linuxmusl') }}
139+ - name : Cache runtime payload
140+ id : payload-cache
141+ uses : actions/cache@v4
142+ with :
143+ path : packages/pdf-runtime/.cache/payloads/${{ matrix.target }}
144+ key : pdf-runtime-payload-${{ matrix.target }}-${{ hashFiles(
145+ ' packages/pdf-runtime/pdf-runtime-build.json' ,
146+ ' packages/pdf-runtime/scripts/build-target.sh' ,
147+ ' packages/pdf-runtime/scripts/fetch-libpdfium.sh' ,
148+ ' packages/pdf-runtime/build/generate-functions.mjs' ,
149+ ' packages/pdf-runtime/build/generate-runtime-methods.mjs' ,
150+ ' packages/pdf-runtime/build/generate-napi-binding.mjs' ,
151+ ' packages/pdf-runtime/build/CMakeLists.txt' ,
152+ ' packages/pdf-runtime/build/compile.sh' ,
153+ ' packages/pdf-runtime/build/compile.esm.sh'
154+ ) }}
155+ - if : steps.payload-cache.outputs.cache-hit == 'true'
156+ name : Restore payload from cache
157+ shell : bash
158+ run : |
159+ mkdir -p "packages/pdf-runtime/npm/${{ matrix.target }}"
160+ cp -R "packages/pdf-runtime/.cache/payloads/${{ matrix.target }}/." \
161+ "packages/pdf-runtime/npm/${{ matrix.target }}/"
162+ - if : ${{ steps.payload-cache.outputs.cache-hit != 'true' && !contains(matrix.target, 'linuxmusl') }}
95163 run : pnpm install --frozen-lockfile
96- - if : ${{ !contains(matrix.target, 'linuxmusl') }}
164+ - if : ${{ steps.payload-cache.outputs.cache-hit != 'true' && !contains(matrix.target, 'linuxmusl') }}
97165 name : Install build tools
98166 run : sudo apt-get update && sudo apt-get install -y cmake clang lld
99- - if : ${{ !contains(matrix.target, 'linuxmusl') }}
167+ - if : ${{ steps.payload-cache.outputs.cache-hit != 'true' && !contains(matrix.target, 'linuxmusl') }}
100168 name : Build target
101169 env :
102170 CC : clang
103171 CXX : clang++
104172 LDFLAGS : -fuse-ld=lld
105173 run : pnpm --filter @embedpdf/pdf-runtime build:target ${{ matrix.target }}
106- - if : ${{ contains(matrix.target, 'linuxmusl') }}
174+ - if : ${{ steps.payload-cache.outputs.cache-hit != 'true' && contains(matrix.target, 'linuxmusl') }}
107175 name : Build musl target in Alpine
108176 run : |
109177 docker run --rm \
110178 -v "$GITHUB_WORKSPACE:/workspace" \
111179 -w /workspace \
112180 node:22-alpine \
113181 sh -lc "apk add --no-cache bash cmake clang g++ make python3 curl tar git && corepack enable && pnpm install --frozen-lockfile && pnpm --filter @embedpdf/pdf-runtime build:target ${{ matrix.target }}"
182+ - if : steps.payload-cache.outputs.cache-hit != 'true'
183+ name : Stage payload to cache path
184+ shell : bash
185+ run : |
186+ src="packages/pdf-runtime/npm/${{ matrix.target }}"
187+ dst="packages/pdf-runtime/.cache/payloads/${{ matrix.target }}"
188+ mkdir -p "$dst"
189+ cp "$src/pdf-runtime.node" "$dst/"
190+ - name : Verify payload
191+ shell : bash
192+ run : bash packages/pdf-runtime/scripts/verify-packages.sh ${{ matrix.target }}
114193 - uses : actions/upload-artifact@v6
115194 with :
116195 name : pdf-runtime-${{ matrix.target }}
@@ -132,9 +211,45 @@ jobs:
132211 with :
133212 node-version : 22
134213 cache : pnpm
135- - run : pnpm install --frozen-lockfile
136- - name : Build target
214+ - name : Cache runtime payload
215+ id : payload-cache
216+ uses : actions/cache@v4
217+ with :
218+ path : packages/pdf-runtime/.cache/payloads/${{ matrix.target }}
219+ key : pdf-runtime-payload-${{ matrix.target }}-${{ hashFiles(
220+ ' packages/pdf-runtime/pdf-runtime-build.json' ,
221+ ' packages/pdf-runtime/scripts/build-target.sh' ,
222+ ' packages/pdf-runtime/scripts/fetch-libpdfium.sh' ,
223+ ' packages/pdf-runtime/build/generate-functions.mjs' ,
224+ ' packages/pdf-runtime/build/generate-runtime-methods.mjs' ,
225+ ' packages/pdf-runtime/build/generate-napi-binding.mjs' ,
226+ ' packages/pdf-runtime/build/CMakeLists.txt' ,
227+ ' packages/pdf-runtime/build/compile.sh' ,
228+ ' packages/pdf-runtime/build/compile.esm.sh'
229+ ) }}
230+ - if : steps.payload-cache.outputs.cache-hit == 'true'
231+ name : Restore payload from cache
232+ shell : bash
233+ run : |
234+ mkdir -p "packages/pdf-runtime/npm/${{ matrix.target }}"
235+ cp -R "packages/pdf-runtime/.cache/payloads/${{ matrix.target }}/." \
236+ "packages/pdf-runtime/npm/${{ matrix.target }}/"
237+ - if : steps.payload-cache.outputs.cache-hit != 'true'
238+ run : pnpm install --frozen-lockfile
239+ - if : steps.payload-cache.outputs.cache-hit != 'true'
240+ name : Build target
137241 run : pnpm --filter @embedpdf/pdf-runtime build:target ${{ matrix.target }}
242+ - if : steps.payload-cache.outputs.cache-hit != 'true'
243+ name : Stage payload to cache path
244+ shell : bash
245+ run : |
246+ src="packages/pdf-runtime/npm/${{ matrix.target }}"
247+ dst="packages/pdf-runtime/.cache/payloads/${{ matrix.target }}"
248+ mkdir -p "$dst"
249+ cp "$src/pdf-runtime.node" "$dst/"
250+ - name : Verify payload
251+ shell : bash
252+ run : bash packages/pdf-runtime/scripts/verify-packages.sh ${{ matrix.target }}
138253 - uses : actions/upload-artifact@v6
139254 with :
140255 name : pdf-runtime-${{ matrix.target }}
@@ -156,10 +271,46 @@ jobs:
156271 with :
157272 node-version : 22
158273 cache : pnpm
159- - run : pnpm install --frozen-lockfile
160- - name : Build target
274+ - name : Cache runtime payload
275+ id : payload-cache
276+ uses : actions/cache@v4
277+ with :
278+ path : packages/pdf-runtime/.cache/payloads/${{ matrix.target }}
279+ key : pdf-runtime-payload-${{ matrix.target }}-${{ hashFiles(
280+ ' packages/pdf-runtime/pdf-runtime-build.json' ,
281+ ' packages/pdf-runtime/scripts/build-target.sh' ,
282+ ' packages/pdf-runtime/scripts/fetch-libpdfium.sh' ,
283+ ' packages/pdf-runtime/build/generate-functions.mjs' ,
284+ ' packages/pdf-runtime/build/generate-runtime-methods.mjs' ,
285+ ' packages/pdf-runtime/build/generate-napi-binding.mjs' ,
286+ ' packages/pdf-runtime/build/CMakeLists.txt' ,
287+ ' packages/pdf-runtime/build/compile.sh' ,
288+ ' packages/pdf-runtime/build/compile.esm.sh'
289+ ) }}
290+ - if : steps.payload-cache.outputs.cache-hit == 'true'
291+ name : Restore payload from cache
292+ shell : bash
293+ run : |
294+ mkdir -p "packages/pdf-runtime/npm/${{ matrix.target }}"
295+ cp -R "packages/pdf-runtime/.cache/payloads/${{ matrix.target }}/." \
296+ "packages/pdf-runtime/npm/${{ matrix.target }}/"
297+ - if : steps.payload-cache.outputs.cache-hit != 'true'
298+ run : pnpm install --frozen-lockfile
299+ - if : steps.payload-cache.outputs.cache-hit != 'true'
300+ name : Build target
161301 shell : bash
162302 run : pnpm --filter @embedpdf/pdf-runtime build:target ${{ matrix.target }}
303+ - if : steps.payload-cache.outputs.cache-hit != 'true'
304+ name : Stage payload to cache path
305+ shell : bash
306+ run : |
307+ src="packages/pdf-runtime/npm/${{ matrix.target }}"
308+ dst="packages/pdf-runtime/.cache/payloads/${{ matrix.target }}"
309+ mkdir -p "$dst"
310+ cp "$src/pdf-runtime.node" "$src/pdfium.dll" "$dst/"
311+ - name : Verify payload
312+ shell : bash
313+ run : bash packages/pdf-runtime/scripts/verify-packages.sh ${{ matrix.target }}
163314 - uses : actions/upload-artifact@v6
164315 with :
165316 name : pdf-runtime-${{ matrix.target }}
0 commit comments