CI.yml 16 KB

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