CI.yaml 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583
  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-beta
  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. if: matrix.os != 'macos-latest'
  57. run: yarn build
  58. - name: 'Build'
  59. if: matrix.os == 'macos-latest'
  60. run: yarn build
  61. env:
  62. MACOSX_DEPLOYMENT_TARGET: '10.13'
  63. - name: Upload artifact
  64. uses: actions/upload-artifact@v2
  65. with:
  66. name: bindings-${{ matrix.os }}
  67. path: ${{ env.APP_NAME }}.*.node
  68. - name: Clear the cargo caches
  69. run: |
  70. cargo install cargo-cache --no-default-features --features ci-autoclean
  71. cargo-cache
  72. build-linux-musl:
  73. if: "!contains(github.event.head_commit.message, 'skip ci')"
  74. name: stable - linux-musl - node@10
  75. runs-on: ubuntu-latest
  76. steps:
  77. - uses: actions/checkout@v2
  78. - name: Login to registry
  79. run: |
  80. docker login -u $DOCKER_USERNAME -p $DOCKER_PASSWORD $DOCKER_REGISTRY_URL
  81. env:
  82. DOCKER_REGISTRY_URL: docker.pkg.github.com
  83. DOCKER_USERNAME: ${{ github.actor }}
  84. DOCKER_PASSWORD: ${{ secrets.GITHUB_TOKEN }}
  85. - name: Pull docker image
  86. run: |
  87. docker pull docker.pkg.github.com/napi-rs/napi-rs/rust-nodejs-alpine:lts
  88. docker tag docker.pkg.github.com/napi-rs/napi-rs/rust-nodejs-alpine:lts builder
  89. - name: Generate Cargo.lock
  90. uses: actions-rs/cargo@v1
  91. with:
  92. command: generate-lockfile
  93. - name: Cache cargo registry
  94. uses: actions/cache@v1
  95. with:
  96. path: ~/.cargo/registry
  97. key: stable-node-alpine-@10-cargo-registry-trimmed-${{ hashFiles('**/Cargo.lock') }}
  98. - name: Cache cargo index
  99. uses: actions/cache@v1
  100. with:
  101. path: ~/.cargo/git
  102. key: stable-node-alpine-@10-cargo-index-trimmed-${{ hashFiles('**/Cargo.lock') }}
  103. - name: Cache NPM dependencies
  104. uses: actions/cache@v1
  105. with:
  106. path: node_modules
  107. key: npm-cache-alpine-node@10-${{ hashFiles('yarn.lock') }}
  108. - name: 'Install dependencies'
  109. run: yarn install --frozen-lockfile --registry https://registry.npmjs.org --network-timeout 300000
  110. - name: 'Build'
  111. run: |
  112. 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"
  113. - name: Upload artifact
  114. uses: actions/upload-artifact@v2
  115. with:
  116. name: bindings-linux-musl
  117. path: ${{ env.APP_NAME }}.*.node
  118. build-linux-arm7:
  119. name: stable - arm7-unknown-linux-gnu - node@14
  120. runs-on: ubuntu-latest
  121. steps:
  122. - run: docker run --rm --privileged multiarch/qemu-user-static:register --reset
  123. - uses: actions/checkout@v2
  124. - name: Setup node
  125. uses: actions/setup-node@v1
  126. with:
  127. node-version: 14
  128. - name: Install
  129. uses: actions-rs/toolchain@v1
  130. with:
  131. toolchain: stable
  132. profile: minimal
  133. override: true
  134. - name: Generate Cargo.lock
  135. uses: actions-rs/cargo@v1
  136. with:
  137. command: generate-lockfile
  138. - name: Cache cargo registry
  139. uses: actions/cache@v1
  140. with:
  141. path: ~/.cargo/registry
  142. key: stable-linux-arm7-gnu-node@14-cargo-registry-trimmed-${{ hashFiles('**/Cargo.lock') }}
  143. - name: Cache cargo index
  144. uses: actions/cache@v1
  145. with:
  146. path: ~/.cargo/git
  147. key: stable-linux-arm7-gnu-node@14-cargo-index-trimmed-${{ hashFiles('**/Cargo.lock') }}
  148. - name: Cache NPM dependencies
  149. uses: actions/cache@v1
  150. with:
  151. path: node_modules
  152. key: npm-cache-linux-arm7-gnu-node@14-${{ hashFiles('yarn.lock') }}
  153. - name: Install aarch64 toolchain
  154. run: rustup target add armv7-unknown-linux-gnueabihf
  155. - name: Install cross compile toolchain
  156. run: |
  157. sudo apt-get update
  158. sudo apt-get install gcc-arm-linux-gnueabihf -y
  159. - name: Install dependencies
  160. run: yarn install --frozen-lockfile --registry https://registry.npmjs.org --network-timeout 300000
  161. - name: Cross build arm7
  162. run: yarn build --target armv7-unknown-linux-gnueabihf
  163. - name: Upload artifact
  164. uses: actions/upload-artifact@v2
  165. with:
  166. name: bindings-linux-arm7
  167. path: ${{ env.APP_NAME }}.*.node
  168. build-linux-aarch64:
  169. name: stable - aarch64-unknown-linux-gnu - node@14
  170. runs-on: ubuntu-latest
  171. steps:
  172. - run: docker run --rm --privileged multiarch/qemu-user-static:register --reset
  173. - uses: actions/checkout@v2
  174. - name: Setup node
  175. uses: actions/setup-node@v2-beta
  176. with:
  177. node-version: 14
  178. check-latest: true
  179. - name: Install
  180. uses: actions-rs/toolchain@v1
  181. with:
  182. toolchain: stable
  183. profile: minimal
  184. override: true
  185. - name: Install aarch64 toolchain
  186. run: rustup target add aarch64-unknown-linux-gnu
  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-aarch64-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-aarch64-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-aarch64-gnu-node@14-${{ hashFiles('yarn.lock') }}
  206. - name: Install cross compile toolchain
  207. run: |
  208. sudo apt-get update
  209. sudo apt-get install gcc-aarch64-linux-gnu g++-aarch64-linux-gnu -y
  210. - name: Install dependencies
  211. run: yarn install --frozen-lockfile --registry https://registry.npmjs.org --network-timeout 300000
  212. - name: Cross build aarch64
  213. run: yarn build --target aarch64-unknown-linux-gnu
  214. - name: Upload artifact
  215. uses: actions/upload-artifact@v2
  216. with:
  217. name: bindings-linux-aarch64
  218. path: ${{ env.APP_NAME }}.*.node
  219. build-apple-silicon:
  220. name: nightly - aarch64-apple-darwin - node@14
  221. runs-on: macos-latest
  222. steps:
  223. - uses: actions/checkout@v2
  224. - name: Setup node
  225. uses: actions/setup-node@v2-beta
  226. with:
  227. node-version: 14
  228. check-latest: true
  229. - name: Install
  230. uses: actions-rs/toolchain@v1
  231. with:
  232. toolchain: nightly
  233. profile: minimal
  234. override: true
  235. - name: Install aarch64 toolchain
  236. run: rustup target add aarch64-apple-darwin
  237. - name: Generate Cargo.lock
  238. uses: actions-rs/cargo@v1
  239. with:
  240. command: generate-lockfile
  241. - name: Cache cargo registry
  242. uses: actions/cache@v1
  243. with:
  244. path: ~/.cargo/registry
  245. key: nightly-apple-aarch64-node@14-cargo-registry-trimmed-${{ hashFiles('**/Cargo.lock') }}
  246. - name: Cache cargo index
  247. uses: actions/cache@v1
  248. with:
  249. path: ~/.cargo/git
  250. key: nightly-apple-aarch64-node@14-cargo-index-trimmed-${{ hashFiles('**/Cargo.lock') }}
  251. - name: Cache NPM dependencies
  252. uses: actions/cache@v1
  253. with:
  254. path: node_modules
  255. key: npm-cache-apple-aarch64-node@14-${{ hashFiles('yarn.lock') }}
  256. - name: Install dependencies
  257. run: yarn install --frozen-lockfile --registry https://registry.npmjs.org --network-timeout 300000
  258. - name: Cross build aarch64
  259. run: yarn build --target aarch64-apple-darwin
  260. - name: Upload artifact
  261. uses: actions/upload-artifact@v2
  262. with:
  263. name: bindings-apple-aarch64
  264. path: ${{ env.APP_NAME }}.*.node
  265. build-android-aarch64:
  266. name: Build - Android - aarch64
  267. runs-on: macos-latest
  268. steps:
  269. - uses: actions/checkout@v2
  270. - name: Setup node
  271. uses: actions/setup-node@v1
  272. with:
  273. node-version: 14
  274. - name: Install aarch64 toolchain
  275. run: rustup target add aarch64-linux-android
  276. - name: Generate Cargo.lock
  277. uses: actions-rs/cargo@v1
  278. with:
  279. command: generate-lockfile
  280. - name: Cache cargo registry
  281. uses: actions/cache@v1
  282. with:
  283. path: ~/.cargo/registry
  284. key: nightly-apple-aarch64-node@14-cargo-registry-trimmed-${{ hashFiles('**/Cargo.lock') }}
  285. - name: Cache cargo index
  286. uses: actions/cache@v1
  287. with:
  288. path: ~/.cargo/git
  289. key: nightly-apple-aarch64-node@14-cargo-index-trimmed-${{ hashFiles('**/Cargo.lock') }}
  290. - name: Cache NPM dependencies
  291. uses: actions/cache@v1
  292. with:
  293. path: node_modules
  294. key: npm-cache-apple-aarch64-node@14-${{ hashFiles('yarn.lock') }}
  295. - name: Install dependencies
  296. run: yarn install --frozen-lockfile --registry https://registry.npmjs.org --network-timeout 300000
  297. - name: Build
  298. shell: bash
  299. run: |
  300. export CARGO_TARGET_AARCH64_LINUX_ANDROID_LINKER="${ANDROID_NDK_HOME}/toolchains/llvm/prebuilt/darwin-x86_64/bin/aarch64-linux-android24-clang"
  301. yarn build --target aarch64-linux-android
  302. - name: Upload artifact
  303. uses: actions/upload-artifact@v2
  304. with:
  305. name: bindings-android-aarch64
  306. path: ${{ env.APP_NAME }}.*.node
  307. test:
  308. name: Test bindings on ${{ matrix.os }} - node@${{ matrix.node }}
  309. needs:
  310. - build
  311. strategy:
  312. fail-fast: false
  313. matrix:
  314. os: [ubuntu-latest, macos-latest, windows-latest]
  315. node: ['10', '12', '14', '15']
  316. runs-on: ${{ matrix.os }}
  317. steps:
  318. - uses: actions/checkout@v2
  319. - name: Setup node
  320. uses: actions/setup-node@v2-beta
  321. with:
  322. node-version: ${{ matrix.node }}
  323. check-latest: true
  324. - name: Cache NPM dependencies
  325. uses: actions/cache@v1
  326. with:
  327. path: node_modules
  328. key: npm-cache-test-${{ matrix.os }}-node@${{ matrix.node }}-${{ hashFiles('yarn.lock') }}
  329. - name: 'Install dependencies'
  330. run: yarn install --frozen-lockfile --registry https://registry.npmjs.org --network-timeout 300000
  331. - name: Download artifacts
  332. uses: actions/download-artifact@v2
  333. with:
  334. name: bindings-${{ matrix.os }}
  335. path: .
  336. - name: List packages
  337. run: ls -R .
  338. shell: bash
  339. - name: Test bindings
  340. run: yarn test
  341. test-musl:
  342. name: Test bindings on alpine - node@${{ matrix.node }}
  343. needs:
  344. - build-linux-musl
  345. strategy:
  346. fail-fast: false
  347. matrix:
  348. node: ['10', '12', '14', '15']
  349. runs-on: ubuntu-latest
  350. steps:
  351. - uses: actions/checkout@v2
  352. - name: Cache NPM dependencies
  353. uses: actions/cache@v1
  354. with:
  355. path: node_modules
  356. key: npm-cache-alpine-node@${{ matrix.node }}-${{ hashFiles('yarn.lock') }}
  357. - name: 'Install dependencies'
  358. run: yarn install --frozen-lockfile --ignore-scripts --registry https://registry.npmjs.org
  359. - name: Download artifacts
  360. uses: actions/download-artifact@v2
  361. with:
  362. name: bindings-linux-musl
  363. path: .
  364. - name: List files
  365. run: ls -R .
  366. shell: bash
  367. - name: Run tests
  368. run: docker run --rm -v $(pwd):/${{ env.APP_NAME }} -w /${{ env.APP_NAME }} node:${{ matrix.node }}-alpine sh -c "yarn test"
  369. test-aarch64:
  370. name: stable - aarch64-unknown-linux-gnu - node@${{ matrix.node }}
  371. runs-on: ubuntu-latest
  372. needs:
  373. - build-linux-aarch64
  374. strategy:
  375. fail-fast: false
  376. matrix:
  377. node: ['10', '12', '14', '15']
  378. steps:
  379. - run: docker run --rm --privileged multiarch/qemu-user-static:register --reset
  380. - uses: actions/checkout@v2
  381. - name: Setup node
  382. uses: actions/setup-node@v2-beta
  383. with:
  384. node-version: ${{ matrix.node }}
  385. check-latest: true
  386. - name: Cache NPM dependencies
  387. uses: actions/cache@v1
  388. with:
  389. path: node_modules
  390. key: npm-cache-test-linux-aarch64-gnu-node@${{ matrix.node }}-${{ hashFiles('yarn.lock') }}
  391. - name: 'Install dependencies'
  392. run: yarn install --frozen-lockfile --registry https://registry.npmjs.org --network-timeout 300000
  393. - name: Download artifacts
  394. uses: actions/download-artifact@v2
  395. with:
  396. name: bindings-linux-aarch64
  397. path: .
  398. - name: List
  399. run: ls -a
  400. - name: Run tests
  401. uses: docker://multiarch/ubuntu-core:arm64-focal
  402. with:
  403. args: >
  404. sh -c "
  405. apt-get update && \
  406. apt-get install -y ca-certificates gnupg2 curl && \
  407. curl -sL https://deb.nodesource.com/setup_${{ matrix.node }}.x | bash - && \
  408. apt-get install -y nodejs && \
  409. node ./simple-test.js
  410. "
  411. dependabot:
  412. needs:
  413. - test
  414. - test-musl
  415. - test-aarch64
  416. - build-apple-silicon
  417. - build-linux-arm7
  418. - build-android-aarch64
  419. runs-on: ubuntu-latest
  420. steps:
  421. - name: auto-merge
  422. uses: ridedott/dependabot-auto-merge-action@master
  423. with:
  424. GITHUB_LOGIN: dependabot[bot]
  425. GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  426. publish:
  427. name: Publish
  428. runs-on: ubuntu-latest
  429. needs:
  430. - test
  431. - test-musl
  432. - test-aarch64
  433. - build-apple-silicon
  434. - build-linux-arm7
  435. - build-android-aarch64
  436. steps:
  437. - uses: actions/checkout@v2
  438. - name: Setup node
  439. uses: actions/setup-node@v2-beta
  440. with:
  441. node-version: 14
  442. check-latest: true
  443. - name: Cache NPM dependencies
  444. uses: actions/cache@v1
  445. with:
  446. path: node_modules
  447. key: npm-cache-publish-ubuntu-latest-${{ hashFiles('yarn.lock') }}
  448. - name: 'Install dependencies'
  449. run: yarn install --frozen-lockfile --registry https://registry.npmjs.org --network-timeout 300000
  450. - name: Download all artifacts
  451. uses: actions/download-artifact@v2
  452. with:
  453. path: artifacts
  454. - name: Move artifacts
  455. run: yarn artifacts
  456. - name: List packages
  457. run: ls -R npm
  458. shell: bash
  459. - name: Publish
  460. run: |
  461. if 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
  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 }}