CI.yml 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462
  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@v4
  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@v4
  140. if: matrix.settings.target == 'i686-pc-windows-msvc'
  141. with:
  142. node-version: 18
  143. cache: yarn
  144. architecture: x86
  145. - name: Build in docker
  146. uses: addnab/docker-run-action@v3
  147. if: ${{ matrix.settings.docker }}
  148. with:
  149. image: ${{ matrix.settings.docker }}
  150. 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'
  151. run: ${{ matrix.settings.build }}
  152. - name: Build
  153. run: ${{ matrix.settings.build }}
  154. if: ${{ !matrix.settings.docker }}
  155. shell: bash
  156. - name: Upload artifact
  157. uses: actions/upload-artifact@v3
  158. with:
  159. name: bindings-${{ matrix.settings.target }}
  160. path: ${{ env.APP_NAME }}.*.node
  161. if-no-files-found: error
  162. build-freebsd:
  163. runs-on: macos-12
  164. name: Build FreeBSD
  165. steps:
  166. - uses: actions/checkout@v4
  167. - name: Build
  168. id: build
  169. uses: cross-platform-actions/action@v0.21.1
  170. env:
  171. DEBUG: napi:*
  172. RUSTUP_IO_THREADS: 1
  173. with:
  174. operating_system: freebsd
  175. version: '13.2'
  176. memory: 13G
  177. cpu_count: 3
  178. environment_variables: 'DEBUG RUSTUP_IO_THREADS'
  179. shell: bash
  180. run: |
  181. sudo pkg install -y -f curl node libnghttp2 npm
  182. sudo 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. source "$HOME/.cargo/env"
  186. echo "~~~~ rustc --version ~~~~"
  187. rustc --version
  188. echo "~~~~ node -v ~~~~"
  189. node -v
  190. echo "~~~~ yarn --version ~~~~"
  191. yarn --version
  192. pwd
  193. ls -lah
  194. whoami
  195. env
  196. freebsd-version
  197. yarn install
  198. yarn build
  199. rm -rf node_modules
  200. rm -rf target
  201. rm -rf .yarn/cache
  202. - name: Upload artifact
  203. uses: actions/upload-artifact@v3
  204. with:
  205. name: bindings-freebsd
  206. path: ${{ env.APP_NAME }}.*.node
  207. if-no-files-found: error
  208. test-macOS-windows-binding:
  209. name: Test bindings on ${{ matrix.settings.target }} - node@${{ matrix.node }}
  210. needs:
  211. - build
  212. strategy:
  213. fail-fast: false
  214. matrix:
  215. settings:
  216. - host: windows-latest
  217. target: x86_64-pc-windows-msvc
  218. - host: macos-latest
  219. target: x86_64-apple-darwin
  220. node:
  221. - '18'
  222. - '20'
  223. runs-on: ${{ matrix.settings.host }}
  224. steps:
  225. - uses: actions/checkout@v4
  226. - name: Setup node
  227. uses: actions/setup-node@v4
  228. with:
  229. node-version: ${{ matrix.node }}
  230. cache: yarn
  231. - name: Install dependencies
  232. run: yarn install
  233. - name: Download artifacts
  234. uses: actions/download-artifact@v3
  235. with:
  236. name: bindings-${{ matrix.settings.target }}
  237. path: .
  238. - name: List packages
  239. run: ls -R .
  240. shell: bash
  241. - name: Test bindings
  242. run: yarn test
  243. test-linux-x64-gnu-binding:
  244. name: Test bindings on Linux-x64-gnu - node@${{ matrix.node }}
  245. needs:
  246. - build
  247. strategy:
  248. fail-fast: false
  249. matrix:
  250. node:
  251. - '18'
  252. - '20'
  253. runs-on: ubuntu-latest
  254. steps:
  255. - uses: actions/checkout@v4
  256. - name: Setup node
  257. uses: actions/setup-node@v4
  258. with:
  259. node-version: ${{ matrix.node }}
  260. cache: yarn
  261. - name: Install dependencies
  262. run: yarn install
  263. - name: Download artifacts
  264. uses: actions/download-artifact@v3
  265. with:
  266. name: bindings-x86_64-unknown-linux-gnu
  267. path: .
  268. - name: List packages
  269. run: ls -R .
  270. shell: bash
  271. - name: Test bindings
  272. run: docker run --rm -v $(pwd):/build -w /build node:${{ matrix.node }}-slim yarn test
  273. test-linux-x64-musl-binding:
  274. name: Test bindings on x86_64-unknown-linux-musl - node@${{ matrix.node }}
  275. needs:
  276. - build
  277. strategy:
  278. fail-fast: false
  279. matrix:
  280. node:
  281. - '18'
  282. - '20'
  283. runs-on: ubuntu-latest
  284. steps:
  285. - uses: actions/checkout@v4
  286. - name: Setup node
  287. uses: actions/setup-node@v4
  288. with:
  289. node-version: ${{ matrix.node }}
  290. cache: yarn
  291. - name: Install dependencies
  292. run: |
  293. yarn config set supportedArchitectures.libc "musl"
  294. yarn install
  295. - name: Download artifacts
  296. uses: actions/download-artifact@v3
  297. with:
  298. name: bindings-x86_64-unknown-linux-musl
  299. path: .
  300. - name: List packages
  301. run: ls -R .
  302. shell: bash
  303. - name: Test bindings
  304. run: docker run --rm -v $(pwd):/build -w /build node:${{ matrix.node }}-alpine yarn test
  305. test-linux-aarch64-gnu-binding:
  306. name: Test bindings on aarch64-unknown-linux-gnu - node@${{ matrix.node }}
  307. needs:
  308. - build
  309. strategy:
  310. fail-fast: false
  311. matrix:
  312. node:
  313. - '18'
  314. - '20'
  315. runs-on: ubuntu-latest
  316. steps:
  317. - uses: actions/checkout@v4
  318. - name: Download artifacts
  319. uses: actions/download-artifact@v3
  320. with:
  321. name: bindings-aarch64-unknown-linux-gnu
  322. path: .
  323. - name: List packages
  324. run: ls -R .
  325. shell: bash
  326. - name: Install dependencies
  327. run: |
  328. yarn config set supportedArchitectures.cpu "arm64"
  329. yarn config set supportedArchitectures.libc "glibc"
  330. yarn install
  331. - name: Set up QEMU
  332. uses: docker/setup-qemu-action@v3
  333. with:
  334. platforms: arm64
  335. - run: docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
  336. - name: Setup and run tests
  337. uses: addnab/docker-run-action@v3
  338. with:
  339. image: node:${{ matrix.node }}-slim
  340. options: '--platform linux/arm64 -v ${{ github.workspace }}:/build -w /build'
  341. run: |
  342. set -e
  343. yarn test
  344. ls -la
  345. test-linux-aarch64-musl-binding:
  346. name: Test bindings on aarch64-unknown-linux-musl - node@lts
  347. needs:
  348. - build
  349. runs-on: ubuntu-latest
  350. steps:
  351. - uses: actions/checkout@v4
  352. - name: Download artifacts
  353. uses: actions/download-artifact@v3
  354. with:
  355. name: bindings-aarch64-unknown-linux-musl
  356. path: .
  357. - name: List packages
  358. run: ls -R .
  359. shell: bash
  360. - name: Install dependencies
  361. run: |
  362. yarn config set supportedArchitectures.cpu "arm64"
  363. yarn config set supportedArchitectures.libc "musl"
  364. yarn install
  365. - name: Set up QEMU
  366. uses: docker/setup-qemu-action@v3
  367. with:
  368. platforms: arm64
  369. - run: docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
  370. - name: Setup and run tests
  371. uses: addnab/docker-run-action@v3
  372. with:
  373. image: node:lts-alpine
  374. options: '--platform linux/arm64 -v ${{ github.workspace }}:/build -w /build'
  375. run: |
  376. set -e
  377. yarn test
  378. test-linux-arm-gnueabihf-binding:
  379. name: Test bindings on armv7-unknown-linux-gnueabihf - node@${{ matrix.node }}
  380. needs:
  381. - build
  382. strategy:
  383. fail-fast: false
  384. matrix:
  385. node:
  386. - '18'
  387. - '20'
  388. runs-on: ubuntu-latest
  389. steps:
  390. - uses: actions/checkout@v4
  391. - name: Download artifacts
  392. uses: actions/download-artifact@v3
  393. with:
  394. name: bindings-armv7-unknown-linux-gnueabihf
  395. path: .
  396. - name: List packages
  397. run: ls -R .
  398. shell: bash
  399. - name: Install dependencies
  400. run: |
  401. yarn config set supportedArchitectures.cpu "arm"
  402. yarn install
  403. - name: Set up QEMU
  404. uses: docker/setup-qemu-action@v3
  405. with:
  406. platforms: arm
  407. - run: docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
  408. - name: Setup and run tests
  409. uses: addnab/docker-run-action@v3
  410. with:
  411. image: node:${{ matrix.node }}-bullseye-slim
  412. options: '--platform linux/arm/v7 -v ${{ github.workspace }}:/build -w /build'
  413. run: |
  414. set -e
  415. yarn test
  416. ls -la
  417. publish:
  418. name: Publish
  419. runs-on: ubuntu-latest
  420. needs:
  421. - build-freebsd
  422. - test-macOS-windows-binding
  423. - test-linux-x64-gnu-binding
  424. - test-linux-x64-musl-binding
  425. - test-linux-aarch64-gnu-binding
  426. - test-linux-aarch64-musl-binding
  427. - test-linux-arm-gnueabihf-binding
  428. steps:
  429. - uses: actions/checkout@v4
  430. - name: Setup node
  431. uses: actions/setup-node@v4
  432. with:
  433. node-version: 18
  434. cache: yarn
  435. - name: Install dependencies
  436. run: yarn install
  437. - name: Download all artifacts
  438. uses: actions/download-artifact@v3
  439. with:
  440. path: artifacts
  441. - name: Move artifacts
  442. run: yarn artifacts
  443. - name: List packages
  444. run: ls -R ./npm
  445. shell: bash
  446. - name: Publish
  447. run: |
  448. npm config set provenance true
  449. if git log -1 --pretty=%B | grep "^[0-9]\+\.[0-9]\+\.[0-9]\+$";
  450. then
  451. echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" >> ~/.npmrc
  452. npm publish --access public
  453. elif git log -1 --pretty=%B | grep "^[0-9]\+\.[0-9]\+\.[0-9]\+";
  454. then
  455. echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" >> ~/.npmrc
  456. npm publish --tag next --access public
  457. else
  458. echo "Not a release, skipping publish"
  459. fi
  460. env:
  461. GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  462. NPM_TOKEN: ${{ secrets.NPM_TOKEN }}