CI.yml 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472
  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@v3
  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@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 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. node:
  223. - '14'
  224. - '16'
  225. - '18'
  226. runs-on: ${{ matrix.settings.host }}
  227. steps:
  228. - uses: actions/checkout@v3
  229. - name: Setup node
  230. uses: actions/setup-node@v3
  231. with:
  232. node-version: ${{ matrix.node }}
  233. check-latest: true
  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. - '14'
  256. - '16'
  257. - '18'
  258. runs-on: ubuntu-latest
  259. steps:
  260. - uses: actions/checkout@v3
  261. - name: Setup node
  262. uses: actions/setup-node@v3
  263. with:
  264. node-version: ${{ matrix.node }}
  265. check-latest: true
  266. cache: yarn
  267. - name: Install dependencies
  268. run: yarn install
  269. - name: Download artifacts
  270. uses: actions/download-artifact@v3
  271. with:
  272. name: bindings-x86_64-unknown-linux-gnu
  273. path: .
  274. - name: List packages
  275. run: ls -R .
  276. shell: bash
  277. - name: Test bindings
  278. run: docker run --rm -v $(pwd):/build -w /build node:${{ matrix.node }}-slim yarn test
  279. test-linux-x64-musl-binding:
  280. name: Test bindings on x86_64-unknown-linux-musl - node@${{ matrix.node }}
  281. needs:
  282. - build
  283. strategy:
  284. fail-fast: false
  285. matrix:
  286. node:
  287. - '14'
  288. - '16'
  289. - '18'
  290. runs-on: ubuntu-latest
  291. steps:
  292. - uses: actions/checkout@v3
  293. - name: Setup node
  294. uses: actions/setup-node@v3
  295. with:
  296. node-version: ${{ matrix.node }}
  297. check-latest: true
  298. cache: yarn
  299. - name: Install dependencies
  300. run: |
  301. yarn config set supportedArchitectures.libc "musl"
  302. yarn install
  303. - name: Download artifacts
  304. uses: actions/download-artifact@v3
  305. with:
  306. name: bindings-x86_64-unknown-linux-musl
  307. path: .
  308. - name: List packages
  309. run: ls -R .
  310. shell: bash
  311. - name: Test bindings
  312. run: docker run --rm -v $(pwd):/build -w /build node:${{ matrix.node }}-alpine yarn test
  313. test-linux-aarch64-gnu-binding:
  314. name: Test bindings on aarch64-unknown-linux-gnu - node@${{ matrix.node }}
  315. needs:
  316. - build
  317. strategy:
  318. fail-fast: false
  319. matrix:
  320. node:
  321. - '14'
  322. - '16'
  323. - '18'
  324. runs-on: ubuntu-latest
  325. steps:
  326. - uses: actions/checkout@v3
  327. - name: Download artifacts
  328. uses: actions/download-artifact@v3
  329. with:
  330. name: bindings-aarch64-unknown-linux-gnu
  331. path: .
  332. - name: List packages
  333. run: ls -R .
  334. shell: bash
  335. - name: Install dependencies
  336. run: |
  337. yarn config set supportedArchitectures.cpu "arm64"
  338. yarn config set supportedArchitectures.libc "glibc"
  339. yarn install
  340. - name: Set up QEMU
  341. uses: docker/setup-qemu-action@v2
  342. with:
  343. platforms: arm64
  344. - run: docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
  345. - name: Setup and run tests
  346. uses: addnab/docker-run-action@v3
  347. with:
  348. image: node:${{ matrix.node }}-slim
  349. options: '--platform linux/arm64 -v ${{ github.workspace }}:/build -w /build'
  350. run: |
  351. set -e
  352. yarn test
  353. ls -la
  354. test-linux-aarch64-musl-binding:
  355. name: Test bindings on aarch64-unknown-linux-musl - node@${{ matrix.node }}
  356. needs:
  357. - build
  358. runs-on: ubuntu-latest
  359. steps:
  360. - uses: actions/checkout@v3
  361. - name: Download artifacts
  362. uses: actions/download-artifact@v3
  363. with:
  364. name: bindings-aarch64-unknown-linux-musl
  365. path: .
  366. - name: List packages
  367. run: ls -R .
  368. shell: bash
  369. - name: Install dependencies
  370. run: |
  371. yarn config set supportedArchitectures.cpu "arm64"
  372. yarn config set supportedArchitectures.libc "musl"
  373. yarn install
  374. - name: Set up QEMU
  375. uses: docker/setup-qemu-action@v2
  376. with:
  377. platforms: arm64
  378. - run: docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
  379. - name: Setup and run tests
  380. uses: addnab/docker-run-action@v3
  381. with:
  382. image: node:lts-alpine
  383. options: '--platform linux/arm64 -v ${{ github.workspace }}:/build -w /build'
  384. run: |
  385. set -e
  386. yarn test
  387. test-linux-arm-gnueabihf-binding:
  388. name: Test bindings on armv7-unknown-linux-gnueabihf - node@${{ matrix.node }}
  389. needs:
  390. - build
  391. strategy:
  392. fail-fast: false
  393. matrix:
  394. node:
  395. - '14'
  396. - '16'
  397. - '18'
  398. runs-on: ubuntu-latest
  399. steps:
  400. - uses: actions/checkout@v3
  401. - name: Download artifacts
  402. uses: actions/download-artifact@v3
  403. with:
  404. name: bindings-armv7-unknown-linux-gnueabihf
  405. path: .
  406. - name: List packages
  407. run: ls -R .
  408. shell: bash
  409. - name: Install dependencies
  410. run: |
  411. yarn config set supportedArchitectures.cpu "arm"
  412. yarn install
  413. - name: Set up QEMU
  414. uses: docker/setup-qemu-action@v2
  415. with:
  416. platforms: arm
  417. - run: docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
  418. - name: Setup and run tests
  419. uses: addnab/docker-run-action@v3
  420. with:
  421. image: node:${{ matrix.node }}-bullseye-slim
  422. options: '--platform linux/arm/v7 -v ${{ github.workspace }}:/build -w /build'
  423. run: |
  424. set -e
  425. yarn test
  426. ls -la
  427. publish:
  428. name: Publish
  429. runs-on: ubuntu-latest
  430. needs:
  431. - build-freebsd
  432. - test-macOS-windows-binding
  433. - test-linux-x64-gnu-binding
  434. - test-linux-x64-musl-binding
  435. - test-linux-aarch64-gnu-binding
  436. - test-linux-aarch64-musl-binding
  437. - test-linux-arm-gnueabihf-binding
  438. steps:
  439. - uses: actions/checkout@v3
  440. - name: Setup node
  441. uses: actions/setup-node@v3
  442. with:
  443. node-version: 18
  444. check-latest: true
  445. cache: yarn
  446. - name: Install dependencies
  447. run: yarn install
  448. - name: Download all artifacts
  449. uses: actions/download-artifact@v3
  450. with:
  451. path: artifacts
  452. - name: Move artifacts
  453. run: yarn artifacts
  454. - name: List packages
  455. run: ls -R ./npm
  456. shell: bash
  457. - name: Publish
  458. run: |
  459. if git log -1 --pretty=%B | grep "^[0-9]\+\.[0-9]\+\.[0-9]\+$";
  460. then
  461. echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" >> ~/.npmrc
  462. npm publish --access public
  463. elif git log -1 --pretty=%B | grep "^[0-9]\+\.[0-9]\+\.[0-9]\+";
  464. then
  465. echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" >> ~/.npmrc
  466. npm publish --tag next --access public
  467. else
  468. echo "Not a release, skipping publish"
  469. fi
  470. env:
  471. GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  472. NPM_TOKEN: ${{ secrets.NPM_TOKEN }}