CI.yml 18 KB

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