CI.yml 15 KB

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