CI.yml 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465
  1. name: CI
  2. env:
  3. DEBUG: napi:*
  4. APP_NAME: package-template
  5. MACOSX_DEPLOYMENT_TARGET: '10.13'
  6. permissions:
  7. contents: write
  8. id-token: write
  9. 'on':
  10. push:
  11. branches:
  12. - main
  13. tags-ignore:
  14. - '**'
  15. paths-ignore:
  16. - '**/*.md'
  17. - LICENSE
  18. - '**/*.gitignore'
  19. - .editorconfig
  20. - docs/**
  21. pull_request: null
  22. concurrency:
  23. group: ${{ github.workflow }}-${{ github.ref }}
  24. cancel-in-progress: true
  25. jobs:
  26. build:
  27. strategy:
  28. fail-fast: false
  29. matrix:
  30. settings:
  31. - host: macos-latest
  32. target: x86_64-apple-darwin
  33. build: |
  34. yarn build
  35. strip -x *.node
  36. - host: windows-latest
  37. build: yarn build
  38. target: x86_64-pc-windows-msvc
  39. - host: windows-latest
  40. build: |
  41. yarn build --target i686-pc-windows-msvc
  42. yarn test
  43. target: i686-pc-windows-msvc
  44. - host: ubuntu-latest
  45. target: x86_64-unknown-linux-gnu
  46. docker: ghcr.io/napi-rs/napi-rs/nodejs-rust:lts-debian
  47. build: |-
  48. set -e &&
  49. yarn build --target x86_64-unknown-linux-gnu &&
  50. strip *.node
  51. - host: ubuntu-latest
  52. target: x86_64-unknown-linux-musl
  53. docker: ghcr.io/napi-rs/napi-rs/nodejs-rust:lts-alpine
  54. build: set -e && yarn build && strip *.node
  55. - host: macos-latest
  56. target: aarch64-apple-darwin
  57. build: |
  58. sudo rm -Rf /Library/Developer/CommandLineTools/SDKs/*;
  59. export CC=$(xcrun -f clang);
  60. export CXX=$(xcrun -f clang++);
  61. SYSROOT=$(xcrun --sdk macosx --show-sdk-path);
  62. export CFLAGS="-isysroot $SYSROOT -isystem $SYSROOT";
  63. yarn build --target aarch64-apple-darwin
  64. strip -x *.node
  65. - host: ubuntu-latest
  66. target: aarch64-unknown-linux-gnu
  67. docker: ghcr.io/napi-rs/napi-rs/nodejs-rust:lts-debian-aarch64
  68. build: |-
  69. set -e &&
  70. yarn build --target aarch64-unknown-linux-gnu &&
  71. aarch64-unknown-linux-gnu-strip *.node
  72. - host: ubuntu-latest
  73. target: armv7-unknown-linux-gnueabihf
  74. setup: |
  75. sudo apt-get update
  76. sudo apt-get install gcc-arm-linux-gnueabihf -y
  77. build: |
  78. yarn build --target armv7-unknown-linux-gnueabihf
  79. arm-linux-gnueabihf-strip *.node
  80. - host: ubuntu-latest
  81. target: aarch64-linux-android
  82. build: |
  83. yarn build --target aarch64-linux-android
  84. ${ANDROID_NDK_LATEST_HOME}/toolchains/llvm/prebuilt/linux-x86_64/bin/llvm-strip *.node
  85. - host: ubuntu-latest
  86. target: armv7-linux-androideabi
  87. build: |
  88. yarn build --target armv7-linux-androideabi
  89. ${ANDROID_NDK_LATEST_HOME}/toolchains/llvm/prebuilt/linux-x86_64/bin/llvm-strip *.node
  90. - host: ubuntu-latest
  91. target: aarch64-unknown-linux-musl
  92. docker: ghcr.io/napi-rs/napi-rs/nodejs-rust:lts-alpine
  93. build: |-
  94. set -e &&
  95. rustup target add aarch64-unknown-linux-musl &&
  96. yarn build --target aarch64-unknown-linux-musl &&
  97. /aarch64-linux-musl-cross/bin/aarch64-linux-musl-strip *.node
  98. - host: windows-latest
  99. target: aarch64-pc-windows-msvc
  100. build: yarn build --target aarch64-pc-windows-msvc
  101. name: stable - ${{ matrix.settings.target }} - node@18
  102. runs-on: ${{ matrix.settings.host }}
  103. steps:
  104. - uses: actions/checkout@v4
  105. - name: Setup node
  106. uses: actions/setup-node@v4
  107. if: ${{ !matrix.settings.docker }}
  108. with:
  109. node-version: 18
  110. cache: yarn
  111. - name: Install
  112. uses: dtolnay/rust-toolchain@stable
  113. if: ${{ !matrix.settings.docker }}
  114. with:
  115. toolchain: stable
  116. targets: ${{ matrix.settings.target }}
  117. - name: Cache cargo
  118. uses: actions/cache@v3
  119. with:
  120. path: |
  121. ~/.cargo/registry/index/
  122. ~/.cargo/registry/cache/
  123. ~/.cargo/git/db/
  124. .cargo-cache
  125. target/
  126. key: ${{ matrix.settings.target }}-cargo-${{ matrix.settings.host }}
  127. - uses: goto-bus-stop/setup-zig@v2
  128. if: ${{ matrix.settings.target == 'armv7-unknown-linux-gnueabihf' }}
  129. with:
  130. version: 0.11.0
  131. - name: Setup toolchain
  132. run: ${{ matrix.settings.setup }}
  133. if: ${{ matrix.settings.setup }}
  134. shell: bash
  135. - name: Setup node x86
  136. if: matrix.settings.target == 'i686-pc-windows-msvc'
  137. run: yarn config set supportedArchitectures.cpu "ia32"
  138. shell: bash
  139. - name: Install dependencies
  140. run: yarn install
  141. - name: Setup node x86
  142. uses: actions/setup-node@v4
  143. if: matrix.settings.target == 'i686-pc-windows-msvc'
  144. with:
  145. node-version: 18
  146. cache: yarn
  147. architecture: x86
  148. - name: Build in docker
  149. uses: addnab/docker-run-action@v3
  150. if: ${{ matrix.settings.docker }}
  151. with:
  152. image: ${{ matrix.settings.docker }}
  153. options: '--user 0:0 -v ${{ github.workspace }}/.cargo-cache/git/db:/usr/local/cargo/git/db -v ${{ github.workspace }}/.cargo/registry/cache:/usr/local/cargo/registry/cache -v ${{ github.workspace }}/.cargo/registry/index:/usr/local/cargo/registry/index -v ${{ github.workspace }}:/build -w /build'
  154. run: ${{ matrix.settings.build }}
  155. - name: Build
  156. run: ${{ matrix.settings.build }}
  157. if: ${{ !matrix.settings.docker }}
  158. shell: bash
  159. - name: Upload artifact
  160. uses: actions/upload-artifact@v4
  161. with:
  162. name: bindings-${{ matrix.settings.target }}
  163. path: ${{ env.APP_NAME }}.*.node
  164. if-no-files-found: error
  165. build-freebsd:
  166. runs-on: macos-13
  167. name: Build FreeBSD
  168. steps:
  169. - uses: actions/checkout@v4
  170. - name: Build
  171. id: build
  172. uses: cross-platform-actions/action@v0.21.1
  173. env:
  174. DEBUG: napi:*
  175. RUSTUP_IO_THREADS: 1
  176. with:
  177. operating_system: freebsd
  178. version: '13.2'
  179. memory: 13G
  180. cpu_count: 3
  181. environment_variables: 'DEBUG RUSTUP_IO_THREADS'
  182. shell: bash
  183. run: |
  184. sudo pkg install -y -f curl node libnghttp2 npm
  185. sudo npm install -g yarn --ignore-scripts
  186. curl https://sh.rustup.rs -sSf --output rustup.sh
  187. sh rustup.sh -y --profile minimal --default-toolchain beta
  188. source "$HOME/.cargo/env"
  189. echo "~~~~ rustc --version ~~~~"
  190. rustc --version
  191. echo "~~~~ node -v ~~~~"
  192. node -v
  193. echo "~~~~ yarn --version ~~~~"
  194. yarn --version
  195. pwd
  196. ls -lah
  197. whoami
  198. env
  199. freebsd-version
  200. yarn install
  201. yarn build
  202. rm -rf node_modules
  203. rm -rf target
  204. rm -rf .yarn/cache
  205. - name: Upload artifact
  206. uses: actions/upload-artifact@v4
  207. with:
  208. name: bindings-freebsd
  209. path: ${{ env.APP_NAME }}.*.node
  210. if-no-files-found: error
  211. test-macOS-windows-binding:
  212. name: Test bindings on ${{ matrix.settings.target }} - node@${{ matrix.node }}
  213. needs:
  214. - build
  215. strategy:
  216. fail-fast: false
  217. matrix:
  218. settings:
  219. - host: windows-latest
  220. target: x86_64-pc-windows-msvc
  221. - host: macos-latest
  222. target: x86_64-apple-darwin
  223. node:
  224. - '18'
  225. - '20'
  226. runs-on: ${{ matrix.settings.host }}
  227. steps:
  228. - uses: actions/checkout@v4
  229. - name: Setup node
  230. uses: actions/setup-node@v4
  231. with:
  232. node-version: ${{ matrix.node }}
  233. cache: yarn
  234. - name: Install dependencies
  235. run: yarn install
  236. - name: Download artifacts
  237. uses: actions/download-artifact@v3
  238. with:
  239. name: bindings-${{ matrix.settings.target }}
  240. path: .
  241. - name: List packages
  242. run: ls -R .
  243. shell: bash
  244. - name: Test bindings
  245. run: yarn test
  246. test-linux-x64-gnu-binding:
  247. name: Test bindings on Linux-x64-gnu - node@${{ matrix.node }}
  248. needs:
  249. - build
  250. strategy:
  251. fail-fast: false
  252. matrix:
  253. node:
  254. - '18'
  255. - '20'
  256. runs-on: ubuntu-latest
  257. steps:
  258. - uses: actions/checkout@v4
  259. - name: Setup node
  260. uses: actions/setup-node@v4
  261. with:
  262. node-version: ${{ matrix.node }}
  263. cache: yarn
  264. - name: Install dependencies
  265. run: yarn install
  266. - name: Download artifacts
  267. uses: actions/download-artifact@v3
  268. with:
  269. name: bindings-x86_64-unknown-linux-gnu
  270. path: .
  271. - name: List packages
  272. run: ls -R .
  273. shell: bash
  274. - name: Test bindings
  275. run: docker run --rm -v $(pwd):/build -w /build node:${{ matrix.node }}-slim yarn test
  276. test-linux-x64-musl-binding:
  277. name: Test bindings on x86_64-unknown-linux-musl - node@${{ matrix.node }}
  278. needs:
  279. - build
  280. strategy:
  281. fail-fast: false
  282. matrix:
  283. node:
  284. - '18'
  285. - '20'
  286. runs-on: ubuntu-latest
  287. steps:
  288. - uses: actions/checkout@v4
  289. - name: Setup node
  290. uses: actions/setup-node@v4
  291. with:
  292. node-version: ${{ matrix.node }}
  293. cache: yarn
  294. - name: Install dependencies
  295. run: |
  296. yarn config set supportedArchitectures.libc "musl"
  297. yarn install
  298. - name: Download artifacts
  299. uses: actions/download-artifact@v3
  300. with:
  301. name: bindings-x86_64-unknown-linux-musl
  302. path: .
  303. - name: List packages
  304. run: ls -R .
  305. shell: bash
  306. - name: Test bindings
  307. run: docker run --rm -v $(pwd):/build -w /build node:${{ matrix.node }}-alpine yarn test
  308. test-linux-aarch64-gnu-binding:
  309. name: Test bindings on aarch64-unknown-linux-gnu - node@${{ matrix.node }}
  310. needs:
  311. - build
  312. strategy:
  313. fail-fast: false
  314. matrix:
  315. node:
  316. - '18'
  317. - '20'
  318. runs-on: ubuntu-latest
  319. steps:
  320. - uses: actions/checkout@v4
  321. - name: Download artifacts
  322. uses: actions/download-artifact@v3
  323. with:
  324. name: bindings-aarch64-unknown-linux-gnu
  325. path: .
  326. - name: List packages
  327. run: ls -R .
  328. shell: bash
  329. - name: Install dependencies
  330. run: |
  331. yarn config set supportedArchitectures.cpu "arm64"
  332. yarn config set supportedArchitectures.libc "glibc"
  333. yarn install
  334. - name: Set up QEMU
  335. uses: docker/setup-qemu-action@v3
  336. with:
  337. platforms: arm64
  338. - run: docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
  339. - name: Setup and run tests
  340. uses: addnab/docker-run-action@v3
  341. with:
  342. image: node:${{ matrix.node }}-slim
  343. options: '--platform linux/arm64 -v ${{ github.workspace }}:/build -w /build'
  344. run: |
  345. set -e
  346. yarn test
  347. ls -la
  348. test-linux-aarch64-musl-binding:
  349. name: Test bindings on aarch64-unknown-linux-musl - node@lts
  350. needs:
  351. - build
  352. runs-on: ubuntu-latest
  353. steps:
  354. - uses: actions/checkout@v4
  355. - name: Download artifacts
  356. uses: actions/download-artifact@v3
  357. with:
  358. name: bindings-aarch64-unknown-linux-musl
  359. path: .
  360. - name: List packages
  361. run: ls -R .
  362. shell: bash
  363. - name: Install dependencies
  364. run: |
  365. yarn config set supportedArchitectures.cpu "arm64"
  366. yarn config set supportedArchitectures.libc "musl"
  367. yarn install
  368. - name: Set up QEMU
  369. uses: docker/setup-qemu-action@v3
  370. with:
  371. platforms: arm64
  372. - run: docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
  373. - name: Setup and run tests
  374. uses: addnab/docker-run-action@v3
  375. with:
  376. image: node:lts-alpine
  377. options: '--platform linux/arm64 -v ${{ github.workspace }}:/build -w /build'
  378. run: |
  379. set -e
  380. yarn test
  381. test-linux-arm-gnueabihf-binding:
  382. name: Test bindings on armv7-unknown-linux-gnueabihf - node@${{ matrix.node }}
  383. needs:
  384. - build
  385. strategy:
  386. fail-fast: false
  387. matrix:
  388. node:
  389. - '18'
  390. - '20'
  391. runs-on: ubuntu-latest
  392. steps:
  393. - uses: actions/checkout@v4
  394. - name: Download artifacts
  395. uses: actions/download-artifact@v3
  396. with:
  397. name: bindings-armv7-unknown-linux-gnueabihf
  398. path: .
  399. - name: List packages
  400. run: ls -R .
  401. shell: bash
  402. - name: Install dependencies
  403. run: |
  404. yarn config set supportedArchitectures.cpu "arm"
  405. yarn install
  406. - name: Set up QEMU
  407. uses: docker/setup-qemu-action@v3
  408. with:
  409. platforms: arm
  410. - run: docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
  411. - name: Setup and run tests
  412. uses: addnab/docker-run-action@v3
  413. with:
  414. image: node:${{ matrix.node }}-bullseye-slim
  415. options: '--platform linux/arm/v7 -v ${{ github.workspace }}:/build -w /build'
  416. run: |
  417. set -e
  418. yarn test
  419. ls -la
  420. publish:
  421. name: Publish
  422. runs-on: ubuntu-latest
  423. needs:
  424. - build-freebsd
  425. - test-macOS-windows-binding
  426. - test-linux-x64-gnu-binding
  427. - test-linux-x64-musl-binding
  428. - test-linux-aarch64-gnu-binding
  429. - test-linux-aarch64-musl-binding
  430. - test-linux-arm-gnueabihf-binding
  431. steps:
  432. - uses: actions/checkout@v4
  433. - name: Setup node
  434. uses: actions/setup-node@v4
  435. with:
  436. node-version: 18
  437. cache: yarn
  438. - name: Install dependencies
  439. run: yarn install
  440. - name: Download all artifacts
  441. uses: actions/download-artifact@v3
  442. with:
  443. path: artifacts
  444. - name: Move artifacts
  445. run: yarn artifacts
  446. - name: List packages
  447. run: ls -R ./npm
  448. shell: bash
  449. - name: Publish
  450. run: |
  451. npm config set provenance true
  452. if git log -1 --pretty=%B | grep "^[0-9]\+\.[0-9]\+\.[0-9]\+$";
  453. then
  454. echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" >> ~/.npmrc
  455. npm publish --access public
  456. elif git log -1 --pretty=%B | grep "^[0-9]\+\.[0-9]\+\.[0-9]\+";
  457. then
  458. echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" >> ~/.npmrc
  459. npm publish --tag next --access public
  460. else
  461. echo "Not a release, skipping publish"
  462. fi
  463. env:
  464. GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  465. NPM_TOKEN: ${{ secrets.NPM_TOKEN }}