CI.yaml 16 KB

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