CI.yaml 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503
  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-10.15
  137. name: Build FreeBSD
  138. steps:
  139. - uses: actions/checkout@v2
  140. - name: Build
  141. id: build
  142. uses: vmactions/freebsd-vm@v0.1.5
  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 python2 node14
  154. curl -qL https://www.npmjs.com/install.sh | sh
  155. npm install -g yarn
  156. curl https://sh.rustup.rs -sSf --output rustup.sh
  157. sh rustup.sh -y --profile minimal --default-toolchain stable
  158. export PATH="/usr/local/cargo/bin:$PATH"
  159. echo "~~~~ rustc --version ~~~~"
  160. rustc --version
  161. echo "~~~~ node -v ~~~~"
  162. node -v
  163. echo "~~~~ yarn --version ~~~~"
  164. yarn --version
  165. run: |
  166. export PATH="/usr/local/cargo/bin:$PATH"
  167. pwd
  168. ls -lah
  169. whoami
  170. env
  171. freebsd-version
  172. yarn install --ignore-scripts --frozen-lockfile --registry https://registry.npmjs.org --network-timeout 300000
  173. yarn build
  174. yarn test
  175. rm -rf node_modules
  176. rm -rf target
  177. - name: Upload artifact
  178. uses: actions/upload-artifact@v2
  179. with:
  180. name: bindings-freebsd
  181. path: ${{ env.APP_NAME }}.*.node
  182. test-macOS-windows-binding:
  183. name: Test bindings on ${{ matrix.settings.target }} - node@${{ matrix.node }}
  184. needs:
  185. - build
  186. strategy:
  187. fail-fast: false
  188. matrix:
  189. settings:
  190. - host: macos-latest
  191. target: 'x86_64-apple-darwin'
  192. - host: windows-latest
  193. target: 'x86_64-pc-windows-msvc'
  194. node: ['12', '14', '16']
  195. runs-on: ${{ matrix.settings.host }}
  196. steps:
  197. - uses: actions/checkout@v2
  198. - name: Setup node
  199. uses: actions/setup-node@v2
  200. with:
  201. node-version: ${{ matrix.node }}
  202. check-latest: true
  203. - name: Cache NPM dependencies
  204. uses: actions/cache@v1
  205. with:
  206. path: node_modules
  207. key: npm-cache-test-${{ matrix.settings.target }}-${{ matrix.node }}-${{ hashFiles('yarn.lock') }}
  208. - name: 'Install dependencies'
  209. run: yarn install --ignore-scripts --frozen-lockfile --registry https://registry.npmjs.org --network-timeout 300000
  210. - name: Download artifacts
  211. uses: actions/download-artifact@v2
  212. with:
  213. name: bindings-${{ matrix.settings.target }}
  214. path: .
  215. - name: List packages
  216. run: ls -R .
  217. shell: bash
  218. - name: Test bindings
  219. run: yarn test
  220. test-linux-x64-gnu-binding:
  221. name: Test bindings on Linux-x64-gnu - node@${{ matrix.node }}
  222. needs:
  223. - build
  224. strategy:
  225. fail-fast: false
  226. matrix:
  227. node: ['12', '14', '16']
  228. runs-on: ubuntu-latest
  229. steps:
  230. - uses: actions/checkout@v2
  231. - name: Setup node
  232. uses: actions/setup-node@v2
  233. with:
  234. node-version: ${{ matrix.node }}
  235. check-latest: true
  236. - name: Cache NPM dependencies
  237. uses: actions/cache@v1
  238. with:
  239. path: node_modules
  240. key: npm-cache-test-linux-x64-gnu-${{ matrix.node }}-${{ hashFiles('yarn.lock') }}
  241. - name: 'Install dependencies'
  242. run: yarn install --ignore-scripts --frozen-lockfile --registry https://registry.npmjs.org --network-timeout 300000
  243. - name: Download artifacts
  244. uses: actions/download-artifact@v2
  245. with:
  246. name: bindings-x86_64-unknown-linux-gnu
  247. path: .
  248. - name: List packages
  249. run: ls -R .
  250. shell: bash
  251. - name: Test bindings
  252. run: docker run --rm -v $(pwd):/${{ env.APP_NAME }} -w /${{ env.APP_NAME }} node:${{ matrix.node }}-slim yarn test
  253. test-linux-x64-musl-binding:
  254. name: Test bindings on x86_64-unknown-linux-musl - node@${{ matrix.node }}
  255. needs:
  256. - build
  257. strategy:
  258. fail-fast: false
  259. matrix:
  260. node: ['12', '14', '16']
  261. runs-on: ubuntu-latest
  262. steps:
  263. - uses: actions/checkout@v2
  264. - name: Setup node
  265. uses: actions/setup-node@v2
  266. with:
  267. node-version: ${{ matrix.node }}
  268. check-latest: true
  269. - name: Cache NPM dependencies
  270. uses: actions/cache@v1
  271. with:
  272. path: node_modules
  273. key: npm-cache-test-x86_64-unknown-linux-musl-${{ matrix.node }}-${{ hashFiles('yarn.lock') }}
  274. - name: 'Install dependencies'
  275. run: yarn install --ignore-scripts --frozen-lockfile --registry https://registry.npmjs.org --network-timeout 300000
  276. - name: Download artifacts
  277. uses: actions/download-artifact@v2
  278. with:
  279. name: bindings-x86_64-unknown-linux-musl
  280. path: .
  281. - name: List packages
  282. run: ls -R .
  283. shell: bash
  284. - name: Test bindings
  285. run: docker run --rm -v $(pwd):/${{ env.APP_NAME }} -w /${{ env.APP_NAME }} node:${{ matrix.node }}-alpine yarn test
  286. test-linux-aarch64-gnu-binding:
  287. name: Test bindings on aarch64-unknown-linux-gnu - node@${{ matrix.node }}
  288. needs:
  289. - build
  290. strategy:
  291. fail-fast: false
  292. matrix:
  293. node: ['12', '14', '16']
  294. runs-on: ubuntu-latest
  295. steps:
  296. - run: docker run --rm --privileged multiarch/qemu-user-static:register --reset
  297. - uses: actions/checkout@v2
  298. - name: Download artifacts
  299. uses: actions/download-artifact@v2
  300. with:
  301. name: bindings-aarch64-unknown-linux-gnu
  302. path: .
  303. - name: List packages
  304. run: ls -R .
  305. shell: bash
  306. - name: Setup and run tests
  307. uses: docker://multiarch/ubuntu-core:arm64-focal
  308. id: runcmd
  309. with:
  310. args: >
  311. sh -c "
  312. apt-get update && \
  313. apt-get install -y ca-certificates gnupg2 curl apt-transport-https && \
  314. curl -sL https://deb.nodesource.com/setup_${{ matrix.node }}.x | bash - && \
  315. apt-get install -y nodejs && \
  316. npm install -g yarn && \
  317. yarn install --ignore-scripts --registry https://registry.npmjs.org --network-timeout 300000 && \
  318. yarn test && \
  319. ls -la
  320. "
  321. test-linux-aarch64-musl-binding:
  322. name: Test bindings on aarch64-unknown-linux-musl - node@lts
  323. needs:
  324. - build
  325. runs-on: ubuntu-latest
  326. steps:
  327. - run: docker run --rm --privileged multiarch/qemu-user-static:register --reset
  328. - uses: actions/checkout@v2
  329. - name: Download artifacts
  330. uses: actions/download-artifact@v2
  331. with:
  332. name: bindings-aarch64-unknown-linux-musl
  333. path: .
  334. - name: List packages
  335. run: ls -R .
  336. shell: bash
  337. - name: Setup and run tests
  338. uses: docker://multiarch/alpine:aarch64-latest-stable
  339. with:
  340. args: >
  341. sh -c "
  342. apk add nodejs npm && \
  343. npm install -g yarn && \
  344. yarn install --ignore-scripts --registry https://registry.npmjs.org --network-timeout 300000 && \
  345. npm test
  346. "
  347. test-linux-arm-gnueabihf-binding:
  348. name: Test bindings on armv7-unknown-linux-gnueabihf - node@${{ matrix.node }}
  349. needs:
  350. - build
  351. strategy:
  352. fail-fast: false
  353. matrix:
  354. node: ['12', '14', '16']
  355. runs-on: ubuntu-latest
  356. steps:
  357. - run: docker run --rm --privileged multiarch/qemu-user-static:register --reset
  358. - uses: actions/checkout@v2
  359. - name: Download artifacts
  360. uses: actions/download-artifact@v2
  361. with:
  362. name: bindings-armv7-unknown-linux-gnueabihf
  363. path: .
  364. - name: List packages
  365. run: ls -R .
  366. shell: bash
  367. - name: Setup and run tests
  368. uses: docker://multiarch/ubuntu-core:armhf-focal
  369. id: runcmd
  370. with:
  371. args: >
  372. sh -c "
  373. apt-get update && \
  374. apt-get install -y ca-certificates gnupg2 curl apt-transport-https && \
  375. curl -sL https://deb.nodesource.com/setup_${{ matrix.node }}.x | bash - && \
  376. apt-get install -y nodejs && \
  377. npm install -g yarn && \
  378. yarn install --ignore-scripts --registry https://registry.npmjs.org --network-timeout 300000 && \
  379. yarn test && \
  380. ls -la
  381. "
  382. publish:
  383. name: Publish
  384. runs-on: ubuntu-latest
  385. needs:
  386. - test-linux-x64-gnu-binding
  387. - test-linux-x64-musl-binding
  388. - test-linux-aarch64-gnu-binding
  389. - test-linux-arm-gnueabihf-binding
  390. - test-macOS-windows-binding
  391. - test-linux-aarch64-musl-binding
  392. - build-freebsd
  393. steps:
  394. - uses: actions/checkout@v2
  395. - name: Setup node
  396. uses: actions/setup-node@v2
  397. with:
  398. node-version: 14
  399. check-latest: true
  400. - name: Cache NPM dependencies
  401. uses: actions/cache@v1
  402. with:
  403. path: node_modules
  404. key: npm-cache-ubuntu-latest-${{ hashFiles('yarn.lock') }}
  405. restore-keys: |
  406. npm-cache-
  407. - name: 'Install dependencies'
  408. run: yarn install --ignore-scripts --frozen-lockfile --registry https://registry.npmjs.org --network-timeout 300000
  409. - name: Download all artifacts
  410. uses: actions/download-artifact@v2
  411. with:
  412. path: artifacts
  413. - name: Move artifacts
  414. run: yarn artifacts
  415. - name: List packages
  416. run: ls -R ./npm
  417. shell: bash
  418. - name: Publish
  419. run: |
  420. if git log -1 --pretty=%B | grep "^[0-9]\+\.[0-9]\+\.[0-9]\+$";
  421. then
  422. echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" >> ~/.npmrc
  423. npm publish --access public
  424. elif git log -1 --pretty=%B | grep "^[0-9]\+\.[0-9]\+\.[0-9]\+";
  425. then
  426. echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" >> ~/.npmrc
  427. npm publish --tag next --access public
  428. else
  429. echo "Not a release, skipping publish"
  430. fi
  431. env:
  432. GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  433. NPM_TOKEN: ${{ secrets.NPM_TOKEN }}