CI.yml 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450
  1. name: CI
  2. env:
  3. DEBUG: napi:*
  4. APP_NAME: laster-tool
  5. MACOSX_DEPLOYMENT_TARGET: '10.13'
  6. permissions:
  7. contents: write
  8. id-token: write
  9. 'on':
  10. push:
  11. branches:
  12. - main
  13. tags-ignore:
  14. - '**'
  15. paths-ignore:
  16. - '**/*.md'
  17. - LICENSE
  18. - '**/*.gitignore'
  19. - .editorconfig
  20. - docs/**
  21. pull_request: null
  22. concurrency:
  23. group: ${{ github.workflow }}-${{ github.ref }}
  24. cancel-in-progress: true
  25. jobs:
  26. build:
  27. strategy:
  28. fail-fast: false
  29. matrix:
  30. settings:
  31. - host: macos-latest
  32. target: x86_64-apple-darwin
  33. build: yarn build --target x86_64-apple-darwin
  34. - host: windows-latest
  35. build: yarn build --target x86_64-pc-windows-msvc
  36. target: x86_64-pc-windows-msvc
  37. - host: windows-latest
  38. build: |
  39. yarn build --target i686-pc-windows-msvc
  40. yarn test
  41. target: i686-pc-windows-msvc
  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: yarn build --target x86_64-unknown-linux-gnu
  46. - host: ubuntu-latest
  47. target: x86_64-unknown-linux-musl
  48. docker: ghcr.io/napi-rs/napi-rs/nodejs-rust:lts-alpine
  49. build: yarn build --target x86_64-unknown-linux-musl
  50. - host: macos-latest
  51. target: aarch64-apple-darwin
  52. build: yarn build --target aarch64-apple-darwin
  53. - host: ubuntu-latest
  54. target: aarch64-unknown-linux-gnu
  55. docker: ghcr.io/napi-rs/napi-rs/nodejs-rust:lts-debian-aarch64
  56. build: yarn build --target aarch64-unknown-linux-gnu
  57. - host: ubuntu-latest
  58. target: armv7-unknown-linux-gnueabihf
  59. setup: |
  60. sudo apt-get update
  61. sudo apt-get install gcc-arm-linux-gnueabihf -y
  62. build: |
  63. yarn build --target armv7-unknown-linux-gnueabihf
  64. - host: ubuntu-latest
  65. target: aarch64-linux-android
  66. build: yarn build --target aarch64-linux-android
  67. - host: ubuntu-latest
  68. target: armv7-linux-androideabi
  69. build: yarn build --target armv7-linux-androideabi
  70. - host: ubuntu-latest
  71. target: aarch64-unknown-linux-musl
  72. docker: ghcr.io/napi-rs/napi-rs/nodejs-rust:lts-alpine
  73. build: |-
  74. set -e &&
  75. rustup target add aarch64-unknown-linux-musl &&
  76. yarn build --target aarch64-unknown-linux-musl
  77. - host: windows-latest
  78. target: aarch64-pc-windows-msvc
  79. build: yarn build --target aarch64-pc-windows-msvc
  80. name: stable - ${{ matrix.settings.target }} - node@18
  81. runs-on: ${{ matrix.settings.host }}
  82. steps:
  83. - uses: actions/checkout@v4
  84. - name: Setup node
  85. uses: actions/setup-node@v4
  86. if: ${{ !matrix.settings.docker }}
  87. with:
  88. node-version: 20
  89. cache: yarn
  90. - name: Install
  91. uses: dtolnay/rust-toolchain@stable
  92. if: ${{ !matrix.settings.docker }}
  93. with:
  94. toolchain: stable
  95. targets: ${{ matrix.settings.target }}
  96. - name: Cache cargo
  97. uses: actions/cache@v4
  98. with:
  99. path: |
  100. ~/.cargo/registry/index/
  101. ~/.cargo/registry/cache/
  102. ~/.cargo/git/db/
  103. .cargo-cache
  104. target/
  105. key: ${{ matrix.settings.target }}-cargo-${{ matrix.settings.host }}
  106. - uses: goto-bus-stop/setup-zig@v2
  107. if: ${{ matrix.settings.target == 'armv7-unknown-linux-gnueabihf' }}
  108. with:
  109. version: 0.12.0
  110. - name: Setup toolchain
  111. run: ${{ matrix.settings.setup }}
  112. if: ${{ matrix.settings.setup }}
  113. shell: bash
  114. - name: Setup node x86
  115. if: matrix.settings.target == 'i686-pc-windows-msvc'
  116. run: yarn config set supportedArchitectures.cpu "ia32"
  117. shell: bash
  118. - name: Install dependencies
  119. run: yarn install
  120. - name: Setup node x86
  121. uses: actions/setup-node@v4
  122. if: matrix.settings.target == 'i686-pc-windows-msvc'
  123. with:
  124. node-version: 20
  125. cache: yarn
  126. architecture: x86
  127. - name: Build in docker
  128. uses: addnab/docker-run-action@v3
  129. if: ${{ matrix.settings.docker }}
  130. with:
  131. image: ${{ matrix.settings.docker }}
  132. 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'
  133. run: ${{ matrix.settings.build }}
  134. - name: Build
  135. run: ${{ matrix.settings.build }}
  136. if: ${{ !matrix.settings.docker }}
  137. shell: bash
  138. - name: Upload artifact
  139. uses: actions/upload-artifact@v4
  140. with:
  141. name: bindings-${{ matrix.settings.target }}
  142. path: ${{ env.APP_NAME }}.*.node
  143. if-no-files-found: error
  144. build-freebsd:
  145. runs-on: macos-13
  146. name: Build FreeBSD
  147. steps:
  148. - uses: actions/checkout@v4
  149. - name: Build
  150. id: build
  151. uses: cross-platform-actions/action@v0.24.0
  152. env:
  153. DEBUG: napi:*
  154. RUSTUP_IO_THREADS: 1
  155. with:
  156. operating_system: freebsd
  157. version: '13.2'
  158. memory: 8G
  159. cpu_count: 3
  160. environment_variables: DEBUG RUSTUP_IO_THREADS
  161. shell: bash
  162. run: |
  163. sudo pkg install -y -f curl node libnghttp2 npm
  164. sudo npm install -g yarn --ignore-scripts
  165. curl https://sh.rustup.rs -sSf --output rustup.sh
  166. sh rustup.sh -y --profile minimal --default-toolchain beta
  167. source "$HOME/.cargo/env"
  168. echo "~~~~ rustc --version ~~~~"
  169. rustc --version
  170. echo "~~~~ node -v ~~~~"
  171. node -v
  172. echo "~~~~ yarn --version ~~~~"
  173. yarn --version
  174. pwd
  175. ls -lah
  176. whoami
  177. env
  178. freebsd-version
  179. yarn install
  180. yarn build
  181. rm -rf node_modules
  182. rm -rf target
  183. rm -rf .yarn/cache
  184. - name: Upload artifact
  185. uses: actions/upload-artifact@v4
  186. with:
  187. name: bindings-freebsd
  188. path: ${{ env.APP_NAME }}.*.node
  189. if-no-files-found: error
  190. test-macOS-windows-binding:
  191. name: Test bindings on ${{ matrix.settings.target }} - node@${{ matrix.node }}
  192. needs:
  193. - build
  194. strategy:
  195. fail-fast: false
  196. matrix:
  197. settings:
  198. - host: windows-latest
  199. target: x86_64-pc-windows-msvc
  200. architecture: x64
  201. - host: macos-latest
  202. target: aarch64-apple-darwin
  203. architecture: arm64
  204. - host: macos-latest
  205. target: x86_64-apple-darwin
  206. architecture: x64
  207. node:
  208. - '18'
  209. - '20'
  210. runs-on: ${{ matrix.settings.host }}
  211. steps:
  212. - uses: actions/checkout@v4
  213. - name: Setup node
  214. uses: actions/setup-node@v4
  215. with:
  216. node-version: ${{ matrix.node }}
  217. cache: yarn
  218. architecture: ${{ matrix.settings.architecture }}
  219. - name: Install dependencies
  220. run: yarn install
  221. - name: Download artifacts
  222. uses: actions/download-artifact@v4
  223. with:
  224. name: bindings-${{ matrix.settings.target }}
  225. path: .
  226. - name: List packages
  227. run: ls -R .
  228. shell: bash
  229. - name: Test bindings
  230. run: yarn test
  231. test-linux-x64-gnu-binding:
  232. name: Test bindings on Linux-x64-gnu - node@${{ matrix.node }}
  233. needs:
  234. - build
  235. strategy:
  236. fail-fast: false
  237. matrix:
  238. node:
  239. - '18'
  240. - '20'
  241. runs-on: ubuntu-latest
  242. steps:
  243. - uses: actions/checkout@v4
  244. - name: Setup node
  245. uses: actions/setup-node@v4
  246. with:
  247. node-version: ${{ matrix.node }}
  248. cache: yarn
  249. - name: Install dependencies
  250. run: yarn install
  251. - name: Download artifacts
  252. uses: actions/download-artifact@v4
  253. with:
  254. name: bindings-x86_64-unknown-linux-gnu
  255. path: .
  256. - name: List packages
  257. run: ls -R .
  258. shell: bash
  259. - name: Test bindings
  260. run: docker run --rm -v $(pwd):/build -w /build node:${{ matrix.node }}-slim yarn test
  261. test-linux-x64-musl-binding:
  262. name: Test bindings on x86_64-unknown-linux-musl - node@${{ matrix.node }}
  263. needs:
  264. - build
  265. strategy:
  266. fail-fast: false
  267. matrix:
  268. node:
  269. - '18'
  270. - '20'
  271. runs-on: ubuntu-latest
  272. steps:
  273. - uses: actions/checkout@v4
  274. - name: Setup node
  275. uses: actions/setup-node@v4
  276. with:
  277. node-version: ${{ matrix.node }}
  278. cache: yarn
  279. - name: Install dependencies
  280. run: |
  281. yarn config set supportedArchitectures.libc "musl"
  282. yarn install
  283. - name: Download artifacts
  284. uses: actions/download-artifact@v4
  285. with:
  286. name: bindings-x86_64-unknown-linux-musl
  287. path: .
  288. - name: List packages
  289. run: ls -R .
  290. shell: bash
  291. - name: Test bindings
  292. run: docker run --rm -v $(pwd):/build -w /build node:${{ matrix.node }}-alpine yarn test
  293. test-linux-aarch64-gnu-binding:
  294. name: Test bindings on aarch64-unknown-linux-gnu - node@${{ matrix.node }}
  295. needs:
  296. - build
  297. strategy:
  298. fail-fast: false
  299. matrix:
  300. node:
  301. - '18'
  302. - '20'
  303. runs-on: ubuntu-latest
  304. steps:
  305. - uses: actions/checkout@v4
  306. - name: Download artifacts
  307. uses: actions/download-artifact@v4
  308. with:
  309. name: bindings-aarch64-unknown-linux-gnu
  310. path: .
  311. - name: List packages
  312. run: ls -R .
  313. shell: bash
  314. - name: Install dependencies
  315. run: |
  316. yarn config set supportedArchitectures.cpu "arm64"
  317. yarn config set supportedArchitectures.libc "glibc"
  318. yarn install
  319. - name: Set up QEMU
  320. uses: docker/setup-qemu-action@v3
  321. with:
  322. platforms: arm64
  323. - run: docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
  324. - name: Setup and run tests
  325. uses: addnab/docker-run-action@v3
  326. with:
  327. image: node:${{ matrix.node }}-slim
  328. options: '--platform linux/arm64 -v ${{ github.workspace }}:/build -w /build'
  329. run: |
  330. set -e
  331. yarn test
  332. ls -la
  333. test-linux-aarch64-musl-binding:
  334. name: Test bindings on aarch64-unknown-linux-musl - node@lts
  335. needs:
  336. - build
  337. runs-on: ubuntu-latest
  338. steps:
  339. - uses: actions/checkout@v4
  340. - name: Download artifacts
  341. uses: actions/download-artifact@v4
  342. with:
  343. name: bindings-aarch64-unknown-linux-musl
  344. path: .
  345. - name: List packages
  346. run: ls -R .
  347. shell: bash
  348. - name: Install dependencies
  349. run: |
  350. yarn config set supportedArchitectures.cpu "arm64"
  351. yarn config set supportedArchitectures.libc "musl"
  352. yarn install
  353. - name: Set up QEMU
  354. uses: docker/setup-qemu-action@v3
  355. with:
  356. platforms: arm64
  357. - run: docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
  358. - name: Setup and run tests
  359. uses: addnab/docker-run-action@v3
  360. with:
  361. image: node:lts-alpine
  362. options: '--platform linux/arm64 -v ${{ github.workspace }}:/build -w /build'
  363. run: |
  364. set -e
  365. yarn test
  366. test-linux-arm-gnueabihf-binding:
  367. name: Test bindings on armv7-unknown-linux-gnueabihf - node@${{ matrix.node }}
  368. needs:
  369. - build
  370. strategy:
  371. fail-fast: false
  372. matrix:
  373. node:
  374. - '18'
  375. - '20'
  376. runs-on: ubuntu-latest
  377. steps:
  378. - uses: actions/checkout@v4
  379. - name: Download artifacts
  380. uses: actions/download-artifact@v4
  381. with:
  382. name: bindings-armv7-unknown-linux-gnueabihf
  383. path: .
  384. - name: List packages
  385. run: ls -R .
  386. shell: bash
  387. - name: Install dependencies
  388. run: |
  389. yarn config set supportedArchitectures.cpu "arm"
  390. yarn install
  391. - name: Set up QEMU
  392. uses: docker/setup-qemu-action@v3
  393. with:
  394. platforms: arm
  395. - run: docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
  396. - name: Setup and run tests
  397. uses: addnab/docker-run-action@v3
  398. with:
  399. image: node:${{ matrix.node }}-bullseye-slim
  400. options: '--platform linux/arm/v7 -v ${{ github.workspace }}:/build -w /build'
  401. run: |
  402. set -e
  403. yarn test
  404. ls -la
  405. publish:
  406. name: Publish
  407. runs-on: ubuntu-latest
  408. needs:
  409. - build-freebsd
  410. - test-macOS-windows-binding
  411. - test-linux-x64-gnu-binding
  412. - test-linux-x64-musl-binding
  413. - test-linux-aarch64-gnu-binding
  414. - test-linux-aarch64-musl-binding
  415. - test-linux-arm-gnueabihf-binding
  416. steps:
  417. - uses: actions/checkout@v4
  418. - name: Setup node
  419. uses: actions/setup-node@v4
  420. with:
  421. node-version: 20
  422. cache: yarn
  423. - name: Install dependencies
  424. run: yarn install
  425. - name: Download all artifacts
  426. uses: actions/download-artifact@v4
  427. with:
  428. path: artifacts
  429. - name: Move artifacts
  430. run: yarn artifacts
  431. - name: List packages
  432. run: ls -R ./npm
  433. shell: bash
  434. - name: Publish
  435. run: |
  436. npm config set provenance true
  437. if git log -1 --pretty=%B | grep "^[0-9]\+\.[0-9]\+\.[0-9]\+$";
  438. then
  439. echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" >> ~/.npmrc
  440. npm publish --access public
  441. elif git log -1 --pretty=%B | grep "^[0-9]\+\.[0-9]\+\.[0-9]\+";
  442. then
  443. echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" >> ~/.npmrc
  444. npm publish --tag next --access public
  445. else
  446. echo "Not a release, skipping publish"
  447. fi
  448. env:
  449. GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  450. NPM_TOKEN: ${{ secrets.NPM_TOKEN }}