CI.yml 18 KB

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