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. '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@v4
  102. - name: Setup node
  103. uses: actions/setup-node@v3
  104. if: ${{ !matrix.settings.docker }}
  105. with:
  106. node-version: 18
  107. cache: yarn
  108. - name: Install
  109. uses: dtolnay/rust-toolchain@stable
  110. if: ${{ !matrix.settings.docker }}
  111. with:
  112. toolchain: stable
  113. targets: ${{ matrix.settings.target }}
  114. - name: Cache cargo
  115. uses: actions/cache@v3
  116. with:
  117. path: |
  118. ~/.cargo/registry/index/
  119. ~/.cargo/registry/cache/
  120. ~/.cargo/git/db/
  121. .cargo-cache
  122. target/
  123. key: ${{ matrix.settings.target }}-cargo-${{ matrix.settings.host }}
  124. - uses: goto-bus-stop/setup-zig@v2
  125. if: ${{ matrix.settings.target == 'armv7-unknown-linux-gnueabihf' }}
  126. with:
  127. version: 0.11.0
  128. - name: Setup toolchain
  129. run: ${{ matrix.settings.setup }}
  130. if: ${{ matrix.settings.setup }}
  131. shell: bash
  132. - name: Setup node x86
  133. if: matrix.settings.target == 'i686-pc-windows-msvc'
  134. run: yarn config set supportedArchitectures.cpu "ia32"
  135. shell: bash
  136. - name: Install dependencies
  137. run: yarn install
  138. - name: Setup node x86
  139. uses: actions/setup-node@v3
  140. if: matrix.settings.target == 'i686-pc-windows-msvc'
  141. with:
  142. node-version: 18
  143. check-latest: true
  144. cache: yarn
  145. architecture: x86
  146. - name: Build in docker
  147. uses: addnab/docker-run-action@v3
  148. if: ${{ matrix.settings.docker }}
  149. with:
  150. image: ${{ matrix.settings.docker }}
  151. 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'
  152. run: ${{ matrix.settings.build }}
  153. - name: Build
  154. run: ${{ matrix.settings.build }}
  155. if: ${{ !matrix.settings.docker }}
  156. shell: bash
  157. - name: Upload artifact
  158. uses: actions/upload-artifact@v3
  159. with:
  160. name: bindings-${{ matrix.settings.target }}
  161. path: ${{ env.APP_NAME }}.*.node
  162. if-no-files-found: error
  163. build-freebsd:
  164. runs-on: macos-12
  165. name: Build FreeBSD
  166. steps:
  167. - uses: actions/checkout@v4
  168. - name: Build
  169. id: build
  170. uses: vmactions/freebsd-vm@v0
  171. env:
  172. DEBUG: napi:*
  173. RUSTUP_HOME: /usr/local/rustup
  174. CARGO_HOME: /usr/local/cargo
  175. RUSTUP_IO_THREADS: 1
  176. with:
  177. envs: DEBUG RUSTUP_HOME CARGO_HOME RUSTUP_IO_THREADS
  178. usesh: true
  179. mem: 3000
  180. prepare: |
  181. pkg install -y -f curl node libnghttp2 npm
  182. npm install -g yarn --ignore-scripts
  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. - '16'
  226. - '18'
  227. runs-on: ${{ matrix.settings.host }}
  228. steps:
  229. - uses: actions/checkout@v4
  230. - name: Setup node
  231. uses: actions/setup-node@v3
  232. with:
  233. node-version: ${{ matrix.node }}
  234. cache: yarn
  235. - name: Install dependencies
  236. run: yarn install
  237. - name: Download artifacts
  238. uses: actions/download-artifact@v3
  239. with:
  240. name: bindings-${{ matrix.settings.target }}
  241. path: .
  242. - name: List packages
  243. run: ls -R .
  244. shell: bash
  245. - name: Test bindings
  246. run: yarn test
  247. test-linux-x64-gnu-binding:
  248. name: Test bindings on Linux-x64-gnu - node@${{ matrix.node }}
  249. needs:
  250. - build
  251. strategy:
  252. fail-fast: false
  253. matrix:
  254. node:
  255. - '16'
  256. - '18'
  257. runs-on: ubuntu-latest
  258. steps:
  259. - uses: actions/checkout@v4
  260. - name: Setup node
  261. uses: actions/setup-node@v3
  262. with:
  263. node-version: ${{ matrix.node }}
  264. cache: yarn
  265. - name: Install dependencies
  266. run: yarn install
  267. - name: Download artifacts
  268. uses: actions/download-artifact@v3
  269. with:
  270. name: bindings-x86_64-unknown-linux-gnu
  271. path: .
  272. - name: List packages
  273. run: ls -R .
  274. shell: bash
  275. - name: Test bindings
  276. run: docker run --rm -v $(pwd):/build -w /build node:${{ matrix.node }}-slim yarn test
  277. test-linux-x64-musl-binding:
  278. name: Test bindings on x86_64-unknown-linux-musl - node@${{ matrix.node }}
  279. needs:
  280. - build
  281. strategy:
  282. fail-fast: false
  283. matrix:
  284. node:
  285. - '16'
  286. - '18'
  287. runs-on: ubuntu-latest
  288. steps:
  289. - uses: actions/checkout@v4
  290. - name: Setup node
  291. uses: actions/setup-node@v3
  292. with:
  293. node-version: ${{ matrix.node }}
  294. cache: yarn
  295. - name: Install dependencies
  296. run: |
  297. yarn config set supportedArchitectures.libc "musl"
  298. yarn install
  299. - name: Download artifacts
  300. uses: actions/download-artifact@v3
  301. with:
  302. name: bindings-x86_64-unknown-linux-musl
  303. path: .
  304. - name: List packages
  305. run: ls -R .
  306. shell: bash
  307. - name: Test bindings
  308. run: docker run --rm -v $(pwd):/build -w /build node:${{ matrix.node }}-alpine yarn test
  309. test-linux-aarch64-gnu-binding:
  310. name: Test bindings on aarch64-unknown-linux-gnu - node@${{ matrix.node }}
  311. needs:
  312. - build
  313. strategy:
  314. fail-fast: false
  315. matrix:
  316. node:
  317. - '16'
  318. - '18'
  319. runs-on: ubuntu-latest
  320. steps:
  321. - uses: actions/checkout@v4
  322. - name: Download artifacts
  323. uses: actions/download-artifact@v3
  324. with:
  325. name: bindings-aarch64-unknown-linux-gnu
  326. path: .
  327. - name: List packages
  328. run: ls -R .
  329. shell: bash
  330. - name: Install dependencies
  331. run: |
  332. yarn config set supportedArchitectures.cpu "arm64"
  333. yarn config set supportedArchitectures.libc "glibc"
  334. yarn install
  335. - name: Set up QEMU
  336. uses: docker/setup-qemu-action@v3
  337. with:
  338. platforms: arm64
  339. - run: docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
  340. - name: Setup and run tests
  341. uses: addnab/docker-run-action@v3
  342. with:
  343. image: node:${{ matrix.node }}-slim
  344. options: '--platform linux/arm64 -v ${{ github.workspace }}:/build -w /build'
  345. run: |
  346. set -e
  347. yarn test
  348. ls -la
  349. test-linux-aarch64-musl-binding:
  350. name: Test bindings on aarch64-unknown-linux-musl - node@${{ matrix.node }}
  351. needs:
  352. - build
  353. runs-on: ubuntu-latest
  354. steps:
  355. - uses: actions/checkout@v4
  356. - name: Download artifacts
  357. uses: actions/download-artifact@v3
  358. with:
  359. name: bindings-aarch64-unknown-linux-musl
  360. path: .
  361. - name: List packages
  362. run: ls -R .
  363. shell: bash
  364. - name: Install dependencies
  365. run: |
  366. yarn config set supportedArchitectures.cpu "arm64"
  367. yarn config set supportedArchitectures.libc "musl"
  368. yarn install
  369. - name: Set up QEMU
  370. uses: docker/setup-qemu-action@v3
  371. with:
  372. platforms: arm64
  373. - run: docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
  374. - name: Setup and run tests
  375. uses: addnab/docker-run-action@v3
  376. with:
  377. image: node:lts-alpine
  378. options: '--platform linux/arm64 -v ${{ github.workspace }}:/build -w /build'
  379. run: |
  380. set -e
  381. yarn test
  382. test-linux-arm-gnueabihf-binding:
  383. name: Test bindings on armv7-unknown-linux-gnueabihf - node@${{ matrix.node }}
  384. needs:
  385. - build
  386. strategy:
  387. fail-fast: false
  388. matrix:
  389. node:
  390. - '16'
  391. - '18'
  392. runs-on: ubuntu-latest
  393. steps:
  394. - uses: actions/checkout@v4
  395. - name: Download artifacts
  396. uses: actions/download-artifact@v3
  397. with:
  398. name: bindings-armv7-unknown-linux-gnueabihf
  399. path: .
  400. - name: List packages
  401. run: ls -R .
  402. shell: bash
  403. - name: Install dependencies
  404. run: |
  405. yarn config set supportedArchitectures.cpu "arm"
  406. yarn install
  407. - name: Set up QEMU
  408. uses: docker/setup-qemu-action@v3
  409. with:
  410. platforms: arm
  411. - run: docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
  412. - name: Setup and run tests
  413. uses: addnab/docker-run-action@v3
  414. with:
  415. image: node:${{ matrix.node }}-bullseye-slim
  416. options: '--platform linux/arm/v7 -v ${{ github.workspace }}:/build -w /build'
  417. run: |
  418. set -e
  419. yarn test
  420. ls -la
  421. publish:
  422. name: Publish
  423. runs-on: ubuntu-latest
  424. needs:
  425. - build-freebsd
  426. - test-macOS-windows-binding
  427. - test-linux-x64-gnu-binding
  428. - test-linux-x64-musl-binding
  429. - test-linux-aarch64-gnu-binding
  430. - test-linux-aarch64-musl-binding
  431. - test-linux-arm-gnueabihf-binding
  432. steps:
  433. - uses: actions/checkout@v4
  434. - name: Setup node
  435. uses: actions/setup-node@v3
  436. with:
  437. node-version: 18
  438. cache: yarn
  439. - name: Install dependencies
  440. run: yarn install
  441. - name: Download all artifacts
  442. uses: actions/download-artifact@v3
  443. with:
  444. path: artifacts
  445. - name: Move artifacts
  446. run: yarn artifacts
  447. - name: List packages
  448. run: ls -R ./npm
  449. shell: bash
  450. - name: Publish
  451. run: |
  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 }}