CI.yml 15 KB

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