CI.yaml 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654
  1. name: CI
  2. env:
  3. DEBUG: 'napi:*'
  4. APP_NAME: 'package-template'
  5. on:
  6. push:
  7. branches:
  8. - main
  9. tags-ignore:
  10. - '**'
  11. pull_request:
  12. jobs:
  13. build:
  14. if: "!contains(github.event.head_commit.message, 'skip ci')"
  15. strategy:
  16. fail-fast: false
  17. matrix:
  18. os: [ubuntu-latest, macos-latest, windows-latest]
  19. name: stable - ${{ matrix.os }} - node@14
  20. runs-on: ${{ matrix.os }}
  21. steps:
  22. - uses: actions/checkout@v2
  23. - name: Setup node
  24. uses: actions/setup-node@v2
  25. with:
  26. node-version: 14
  27. check-latest: true
  28. - name: Install
  29. uses: actions-rs/toolchain@v1
  30. with:
  31. toolchain: stable
  32. profile: minimal
  33. override: true
  34. - name: Generate Cargo.lock
  35. uses: actions-rs/cargo@v1
  36. with:
  37. command: generate-lockfile
  38. - name: Cache cargo registry
  39. uses: actions/cache@v1
  40. with:
  41. path: ~/.cargo/registry
  42. key: stable-${{ matrix.os }}-node@14-cargo-registry-trimmed-${{ hashFiles('**/Cargo.lock') }}
  43. - name: Cache cargo index
  44. uses: actions/cache@v1
  45. with:
  46. path: ~/.cargo/git
  47. key: stable-${{ matrix.os }}-node@14-cargo-index-trimmed-${{ hashFiles('**/Cargo.lock') }}
  48. - name: Cache NPM dependencies
  49. uses: actions/cache@v1
  50. with:
  51. path: node_modules
  52. key: npm-cache-${{ matrix.os }}-node@14-${{ hashFiles('yarn.lock') }}
  53. - name: 'Install dependencies'
  54. run: yarn install --frozen-lockfile --registry https://registry.npmjs.org --network-timeout 300000
  55. - name: 'Build'
  56. run: yarn build
  57. env:
  58. MACOSX_DEPLOYMENT_TARGET: '10.13'
  59. - name: Upload artifact
  60. uses: actions/upload-artifact@v2
  61. with:
  62. name: bindings-${{ matrix.os }}
  63. path: ${{ env.APP_NAME }}.*.node
  64. - name: Clear the cargo caches
  65. run: |
  66. cargo install cargo-cache --no-default-features --features ci-autoclean
  67. cargo-cache
  68. build-windows-i686:
  69. if: "!contains(github.event.head_commit.message, 'skip ci')"
  70. name: stable - windows-i686 - node@10
  71. runs-on: windows-latest
  72. env:
  73. CARGO_PROFILE_RELEASE_CODEGEN_UNITS: 32
  74. CARGO_PROFILE_RELEASE_LTO: 'false'
  75. steps:
  76. - uses: actions/checkout@v2
  77. - name: Install node x86
  78. run: |
  79. choco install nodejs-lts --x86 -y --force
  80. refreshenv
  81. - name: Set 32bit NodeJS path
  82. run: |
  83. echo "C:\\Program Files (x86)\\nodejs" >> $GITHUB_PATH
  84. shell: bash
  85. - name: NodeJS arch
  86. run: node -e "console.log(process.arch)"
  87. - name: Cache NPM dependencies
  88. uses: actions/cache@v1
  89. with:
  90. path: node_modules
  91. key: npm-cache-windows-i686-node@lts-${{ hashFiles('yarn.lock') }}
  92. - name: Install dependencies
  93. run: yarn install --frozen-lockfile --registry https://registry.npmjs.org --network-timeout 300000
  94. - name: Install
  95. uses: actions-rs/toolchain@v1
  96. with:
  97. toolchain: stable
  98. profile: minimal
  99. override: true
  100. - name: Install i686 toolchain
  101. run: rustup target add i686-pc-windows-msvc
  102. - name: Generate Cargo.lock
  103. uses: actions-rs/cargo@v1
  104. with:
  105. command: generate-lockfile
  106. - name: Cache cargo registry
  107. uses: actions/cache@v1
  108. with:
  109. path: ~/.cargo/registry
  110. key: stable-windows-i686-node@lts-cargo-registry-trimmed-${{ hashFiles('**/Cargo.lock') }}
  111. - name: Cache cargo index
  112. uses: actions/cache@v1
  113. with:
  114. path: ~/.cargo/git
  115. key: stable-windows-i686-node@lts-cargo-index-trimmed-${{ hashFiles('**/Cargo.lock') }}
  116. - name: Cross build i686
  117. run: yarn build --target i686-pc-windows-msvc
  118. - name: Test binary
  119. run: yarn test
  120. - name: Upload artifact
  121. uses: actions/upload-artifact@v2
  122. with:
  123. name: bindings-win32-i686
  124. path: ${{ env.APP_NAME }}.*.node
  125. build-linux-musl:
  126. if: "!contains(github.event.head_commit.message, 'skip ci')"
  127. name: stable - linux-musl - node@10
  128. runs-on: ubuntu-latest
  129. steps:
  130. - uses: actions/checkout@v2
  131. - name: Login to registry
  132. run: |
  133. docker login -u $DOCKER_USERNAME -p $DOCKER_PASSWORD $DOCKER_REGISTRY_URL
  134. env:
  135. DOCKER_REGISTRY_URL: docker.pkg.github.com
  136. DOCKER_USERNAME: ${{ github.actor }}
  137. DOCKER_PASSWORD: ${{ secrets.GITHUB_TOKEN }}
  138. - name: Pull docker image
  139. run: |
  140. docker pull docker.pkg.github.com/napi-rs/napi-rs/rust-nodejs-alpine:lts
  141. docker tag docker.pkg.github.com/napi-rs/napi-rs/rust-nodejs-alpine:lts builder
  142. - name: Generate Cargo.lock
  143. uses: actions-rs/cargo@v1
  144. with:
  145. command: generate-lockfile
  146. - name: Cache cargo registry
  147. uses: actions/cache@v1
  148. with:
  149. path: ~/.cargo/registry
  150. key: stable-node-alpine-@10-cargo-registry-trimmed-${{ hashFiles('**/Cargo.lock') }}
  151. - name: Cache cargo index
  152. uses: actions/cache@v1
  153. with:
  154. path: ~/.cargo/git
  155. key: stable-node-alpine-@10-cargo-index-trimmed-${{ hashFiles('**/Cargo.lock') }}
  156. - name: Cache NPM dependencies
  157. uses: actions/cache@v1
  158. with:
  159. path: node_modules
  160. key: npm-cache-alpine-node@10-${{ hashFiles('yarn.lock') }}
  161. - name: 'Install dependencies'
  162. run: yarn install --frozen-lockfile --registry https://registry.npmjs.org --network-timeout 300000
  163. - name: 'Build'
  164. run: |
  165. docker run --rm -v ~/.cargo/git:/root/.cargo/git -v ~/.cargo/registry:/root/.cargo/registry -v $(pwd):/${{ env.APP_NAME }} -e DEBUG="napi:*" -w /${{ env.APP_NAME }} builder sh -c "yarn build"
  166. - name: Upload artifact
  167. uses: actions/upload-artifact@v2
  168. with:
  169. name: bindings-linux-musl
  170. path: ${{ env.APP_NAME }}.*.node
  171. build-linux-arm7:
  172. name: stable - arm7-unknown-linux-gnu - node@14
  173. runs-on: ubuntu-latest
  174. steps:
  175. - run: docker run --rm --privileged multiarch/qemu-user-static:register --reset
  176. - uses: actions/checkout@v2
  177. - name: Setup node
  178. uses: actions/setup-node@v1
  179. with:
  180. node-version: 14
  181. - name: Install
  182. uses: actions-rs/toolchain@v1
  183. with:
  184. toolchain: stable
  185. profile: minimal
  186. override: true
  187. - name: Generate Cargo.lock
  188. uses: actions-rs/cargo@v1
  189. with:
  190. command: generate-lockfile
  191. - name: Cache cargo registry
  192. uses: actions/cache@v1
  193. with:
  194. path: ~/.cargo/registry
  195. key: stable-linux-arm7-gnu-node@14-cargo-registry-trimmed-${{ hashFiles('**/Cargo.lock') }}
  196. - name: Cache cargo index
  197. uses: actions/cache@v1
  198. with:
  199. path: ~/.cargo/git
  200. key: stable-linux-arm7-gnu-node@14-cargo-index-trimmed-${{ hashFiles('**/Cargo.lock') }}
  201. - name: Cache NPM dependencies
  202. uses: actions/cache@v1
  203. with:
  204. path: node_modules
  205. key: npm-cache-linux-arm7-gnu-node@14-${{ hashFiles('yarn.lock') }}
  206. - name: Install aarch64 toolchain
  207. run: rustup target add armv7-unknown-linux-gnueabihf
  208. - name: Install cross compile toolchain
  209. run: |
  210. sudo apt-get update
  211. sudo apt-get install gcc-arm-linux-gnueabihf -y
  212. - name: Install dependencies
  213. run: yarn install --frozen-lockfile --registry https://registry.npmjs.org --network-timeout 300000
  214. - name: Cross build arm7
  215. run: yarn build --target armv7-unknown-linux-gnueabihf
  216. - name: Upload artifact
  217. uses: actions/upload-artifact@v2
  218. with:
  219. name: bindings-linux-arm7
  220. path: ${{ env.APP_NAME }}.*.node
  221. build-linux-aarch64:
  222. name: stable - aarch64-unknown-linux-gnu - node@14
  223. runs-on: ubuntu-latest
  224. steps:
  225. - run: docker run --rm --privileged multiarch/qemu-user-static:register --reset
  226. - uses: actions/checkout@v2
  227. - name: Setup node
  228. uses: actions/setup-node@v2
  229. with:
  230. node-version: 14
  231. check-latest: true
  232. - name: Install
  233. uses: actions-rs/toolchain@v1
  234. with:
  235. toolchain: stable
  236. profile: minimal
  237. override: true
  238. - name: Install aarch64 toolchain
  239. run: rustup target add aarch64-unknown-linux-gnu
  240. - name: Generate Cargo.lock
  241. uses: actions-rs/cargo@v1
  242. with:
  243. command: generate-lockfile
  244. - name: Cache cargo registry
  245. uses: actions/cache@v1
  246. with:
  247. path: ~/.cargo/registry
  248. key: stable-linux-aarch64-gnu-node@14-cargo-registry-trimmed-${{ hashFiles('**/Cargo.lock') }}
  249. - name: Cache cargo index
  250. uses: actions/cache@v1
  251. with:
  252. path: ~/.cargo/git
  253. key: stable-linux-aarch64-gnu-node@14-cargo-index-trimmed-${{ hashFiles('**/Cargo.lock') }}
  254. - name: Cache NPM dependencies
  255. uses: actions/cache@v1
  256. with:
  257. path: node_modules
  258. key: npm-cache-linux-aarch64-gnu-node@14-${{ hashFiles('yarn.lock') }}
  259. - name: Install cross compile toolchain
  260. run: |
  261. sudo apt-get update
  262. sudo apt-get install gcc-aarch64-linux-gnu g++-aarch64-linux-gnu -y
  263. - name: Install dependencies
  264. run: yarn install --frozen-lockfile --registry https://registry.npmjs.org --network-timeout 300000
  265. - name: Cross build aarch64
  266. run: yarn build --target aarch64-unknown-linux-gnu
  267. - name: Upload artifact
  268. uses: actions/upload-artifact@v2
  269. with:
  270. name: bindings-linux-aarch64
  271. path: ${{ env.APP_NAME }}.*.node
  272. build-apple-silicon:
  273. name: stable - aarch64-apple-darwin - node@14
  274. runs-on: macos-latest
  275. steps:
  276. - uses: actions/checkout@v2
  277. - name: Setup node
  278. uses: actions/setup-node@v2
  279. with:
  280. node-version: 14
  281. check-latest: true
  282. - name: Install
  283. uses: actions-rs/toolchain@v1
  284. with:
  285. toolchain: stable
  286. profile: minimal
  287. override: true
  288. - name: Install aarch64 toolchain
  289. run: rustup target add aarch64-apple-darwin
  290. - name: Generate Cargo.lock
  291. uses: actions-rs/cargo@v1
  292. with:
  293. command: generate-lockfile
  294. - name: Cache cargo registry
  295. uses: actions/cache@v1
  296. with:
  297. path: ~/.cargo/registry
  298. key: stable-apple-aarch64-node@14-cargo-registry-trimmed-${{ hashFiles('**/Cargo.lock') }}
  299. - name: Cache cargo index
  300. uses: actions/cache@v1
  301. with:
  302. path: ~/.cargo/git
  303. key: stable-apple-aarch64-node@14-cargo-index-trimmed-${{ hashFiles('**/Cargo.lock') }}
  304. - name: Cache NPM dependencies
  305. uses: actions/cache@v1
  306. with:
  307. path: node_modules
  308. key: npm-cache-apple-aarch64-node@14-${{ hashFiles('yarn.lock') }}
  309. - name: Install dependencies
  310. run: yarn install --frozen-lockfile --registry https://registry.npmjs.org --network-timeout 300000
  311. - name: Cross build aarch64
  312. run: yarn build --target aarch64-apple-darwin
  313. - name: Upload artifact
  314. uses: actions/upload-artifact@v2
  315. with:
  316. name: bindings-apple-aarch64
  317. path: ${{ env.APP_NAME }}.*.node
  318. build-android-aarch64:
  319. name: Build - Android - aarch64
  320. runs-on: macos-latest
  321. steps:
  322. - uses: actions/checkout@v2
  323. - name: Setup node
  324. uses: actions/setup-node@v1
  325. with:
  326. node-version: 14
  327. - name: Install aarch64 toolchain
  328. run: rustup target add aarch64-linux-android
  329. - name: Generate Cargo.lock
  330. uses: actions-rs/cargo@v1
  331. with:
  332. command: generate-lockfile
  333. - name: Cache cargo registry
  334. uses: actions/cache@v1
  335. with:
  336. path: ~/.cargo/registry
  337. key: stable-apple-aarch64-node@14-cargo-registry-trimmed-${{ hashFiles('**/Cargo.lock') }}
  338. - name: Cache cargo index
  339. uses: actions/cache@v1
  340. with:
  341. path: ~/.cargo/git
  342. key: stable-apple-aarch64-node@14-cargo-index-trimmed-${{ hashFiles('**/Cargo.lock') }}
  343. - name: Cache NPM dependencies
  344. uses: actions/cache@v1
  345. with:
  346. path: node_modules
  347. key: npm-cache-apple-aarch64-node@14-${{ hashFiles('yarn.lock') }}
  348. - name: Install dependencies
  349. run: yarn install --frozen-lockfile --registry https://registry.npmjs.org --network-timeout 300000
  350. - name: Build
  351. shell: bash
  352. run: |
  353. export CARGO_TARGET_AARCH64_LINUX_ANDROID_LINKER="${ANDROID_NDK_HOME}/toolchains/llvm/prebuilt/darwin-x86_64/bin/aarch64-linux-android24-clang"
  354. yarn build --target aarch64-linux-android
  355. - name: Upload artifact
  356. uses: actions/upload-artifact@v2
  357. with:
  358. name: bindings-android-aarch64
  359. path: ${{ env.APP_NAME }}.*.node
  360. test:
  361. name: Test bindings on ${{ matrix.os }} - node@${{ matrix.node }}
  362. needs:
  363. - build
  364. strategy:
  365. fail-fast: false
  366. matrix:
  367. os: [ubuntu-latest, macos-latest, windows-latest]
  368. node: ['10', '12', '14', '15']
  369. runs-on: ${{ matrix.os }}
  370. steps:
  371. - uses: actions/checkout@v2
  372. - name: Setup node
  373. uses: actions/setup-node@v2
  374. with:
  375. node-version: ${{ matrix.node }}
  376. check-latest: true
  377. - name: Cache NPM dependencies
  378. uses: actions/cache@v1
  379. with:
  380. path: node_modules
  381. key: npm-cache-test-${{ matrix.os }}-node@${{ matrix.node }}-${{ hashFiles('yarn.lock') }}
  382. - name: 'Install dependencies'
  383. run: yarn install --frozen-lockfile --registry https://registry.npmjs.org --network-timeout 300000
  384. - name: Download artifacts
  385. uses: actions/download-artifact@v2
  386. with:
  387. name: bindings-${{ matrix.os }}
  388. path: .
  389. - name: List packages
  390. run: ls -R .
  391. shell: bash
  392. - name: Test bindings
  393. run: yarn test
  394. test-musl:
  395. name: Test bindings on alpine - node@${{ matrix.node }}
  396. needs:
  397. - build-linux-musl
  398. strategy:
  399. fail-fast: false
  400. matrix:
  401. node: ['10', '12', '14', '15']
  402. runs-on: ubuntu-latest
  403. steps:
  404. - uses: actions/checkout@v2
  405. - name: Cache NPM dependencies
  406. uses: actions/cache@v1
  407. with:
  408. path: node_modules
  409. key: npm-cache-alpine-node@${{ matrix.node }}-${{ hashFiles('yarn.lock') }}
  410. - name: 'Install dependencies'
  411. run: yarn install --frozen-lockfile --ignore-scripts --registry https://registry.npmjs.org --network-timeout 300000
  412. - name: Download artifacts
  413. uses: actions/download-artifact@v2
  414. with:
  415. name: bindings-linux-musl
  416. path: .
  417. - name: List files
  418. run: ls -R .
  419. shell: bash
  420. - name: Run tests
  421. run: docker run --rm -v $(pwd):/${{ env.APP_NAME }} -w /${{ env.APP_NAME }} node:${{ matrix.node }}-alpine sh -c "yarn test"
  422. test-aarch64:
  423. name: stable - aarch64-unknown-linux-gnu - node@${{ matrix.node }}
  424. runs-on: ubuntu-latest
  425. needs:
  426. - build-linux-aarch64
  427. strategy:
  428. fail-fast: false
  429. matrix:
  430. node: ['10', '12', '14', '15']
  431. steps:
  432. - run: docker run --rm --privileged multiarch/qemu-user-static:register --reset
  433. - uses: actions/checkout@v2
  434. - name: Setup node
  435. uses: actions/setup-node@v2
  436. with:
  437. node-version: ${{ matrix.node }}
  438. check-latest: true
  439. - name: Cache NPM dependencies
  440. uses: actions/cache@v1
  441. with:
  442. path: node_modules
  443. key: npm-cache-test-linux-aarch64-gnu-node@${{ matrix.node }}-${{ hashFiles('yarn.lock') }}
  444. - name: 'Install dependencies'
  445. run: yarn install --frozen-lockfile --registry https://registry.npmjs.org --network-timeout 300000
  446. - name: Download artifacts
  447. uses: actions/download-artifact@v2
  448. with:
  449. name: bindings-linux-aarch64
  450. path: .
  451. - name: List
  452. run: ls -a
  453. - name: Run tests
  454. uses: docker://multiarch/ubuntu-core:arm64-focal
  455. with:
  456. args: >
  457. sh -c "
  458. apt-get update && \
  459. apt-get install -y ca-certificates gnupg2 curl && \
  460. curl -sL https://deb.nodesource.com/setup_${{ matrix.node }}.x | bash - && \
  461. apt-get install -y nodejs && \
  462. node ./simple-test.js
  463. "
  464. dependabot:
  465. needs:
  466. - test
  467. - test-musl
  468. - test-aarch64
  469. - build-windows-i686
  470. - build-apple-silicon
  471. - build-linux-arm7
  472. - build-android-aarch64
  473. runs-on: ubuntu-latest
  474. steps:
  475. - name: auto-merge
  476. uses: ridedott/dependabot-auto-merge-action@master
  477. with:
  478. GITHUB_LOGIN: dependabot[bot]
  479. GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  480. publish:
  481. name: Publish
  482. runs-on: ubuntu-latest
  483. needs:
  484. - test
  485. - test-musl
  486. - test-aarch64
  487. - build-windows-i686
  488. - build-apple-silicon
  489. - build-linux-arm7
  490. - build-android-aarch64
  491. steps:
  492. - uses: actions/checkout@v2
  493. - name: Setup node
  494. uses: actions/setup-node@v2
  495. with:
  496. node-version: 14
  497. check-latest: true
  498. - name: Cache NPM dependencies
  499. uses: actions/cache@v1
  500. with:
  501. path: node_modules
  502. key: npm-cache-publish-ubuntu-latest-${{ hashFiles('yarn.lock') }}
  503. - name: 'Install dependencies'
  504. run: yarn install --frozen-lockfile --registry https://registry.npmjs.org --network-timeout 300000
  505. - name: Download all artifacts
  506. uses: actions/download-artifact@v2
  507. with:
  508. path: artifacts
  509. - name: Move artifacts
  510. run: yarn artifacts
  511. - name: List packages
  512. run: ls -R npm
  513. shell: bash
  514. - name: Publish
  515. run: |
  516. if git log -1 --pretty=%B | grep "^[0-9]\+\.[0-9]\+\.[0-9]\+$";
  517. then
  518. echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" >> ~/.npmrc
  519. npm publish --access public
  520. elif git log -1 --pretty=%B | grep "^[0-9]\+\.[0-9]\+\.[0-9]\+";
  521. then
  522. echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" >> ~/.npmrc
  523. npm publish --tag next --access public
  524. else
  525. echo "Not a release, skipping publish"
  526. fi
  527. env:
  528. GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  529. NPM_TOKEN: ${{ secrets.NPM_TOKEN }}