CI.yaml 17 KB

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