CI.yaml 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486
  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-20.04
  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-20.04
  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-20.04
  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-20.04
  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-20.04
  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. setup: |
  72. sudo apt-get update
  73. sudo apt-get install gcc-aarch64-linux-gnu -y
  74. build: yarn build --target aarch64-unknown-linux-musl
  75. - host: windows-latest
  76. target: 'aarch64-pc-windows-msvc'
  77. build: yarn build --target aarch64-pc-windows-msvc
  78. name: stable - ${{ matrix.settings.target }} - node@14
  79. runs-on: ${{ matrix.settings.host }}
  80. steps:
  81. - uses: actions/checkout@v2
  82. - name: Setup node
  83. uses: actions/setup-node@v2
  84. with:
  85. node-version: 14
  86. check-latest: true
  87. - name: Install
  88. uses: actions-rs/toolchain@v1
  89. with:
  90. profile: minimal
  91. override: true
  92. toolchain: stable
  93. target: ${{ matrix.settings.target }}
  94. - name: Generate Cargo.lock
  95. uses: actions-rs/cargo@v1
  96. with:
  97. command: generate-lockfile
  98. - name: Cache cargo registry
  99. uses: actions/cache@v1
  100. with:
  101. path: ~/.cargo/registry
  102. key: ${{ matrix.settings.target }}-node@14-cargo-registry-trimmed-${{ hashFiles('**/Cargo.lock') }}
  103. - name: Cache cargo index
  104. uses: actions/cache@v1
  105. with:
  106. path: ~/.cargo/git
  107. key: ${{ matrix.settings.target }}-node@14-cargo-index-trimmed-${{ hashFiles('**/Cargo.lock') }}
  108. - name: Cache NPM dependencies
  109. uses: actions/cache@v1
  110. with:
  111. path: node_modules
  112. key: npm-cache-${{ matrix.settings.target }}-node@14-${{ hashFiles('yarn.lock') }}
  113. - name: Pull latest image
  114. run: ${{ matrix.settings.docker }}
  115. env:
  116. DOCKER_REGISTRY_URL: ghcr.io
  117. DOCKER_USERNAME: ${{ github.actor }}
  118. DOCKER_PASSWORD: ${{ secrets.GITHUB_TOKEN }}
  119. if: ${{ matrix.settings.docker }}
  120. - name: Setup toolchain
  121. run: ${{ matrix.settings.setup }}
  122. if: ${{ matrix.settings.setup }}
  123. shell: bash
  124. - name: 'Install dependencies'
  125. run: yarn install --ignore-scripts --frozen-lockfile --registry https://registry.npmjs.org --network-timeout 300000
  126. - name: 'Build'
  127. run: ${{ matrix.settings.build }}
  128. shell: bash
  129. - name: Upload artifact
  130. uses: actions/upload-artifact@v2
  131. with:
  132. name: bindings-${{ matrix.settings.target }}
  133. path: ${{ env.APP_NAME }}.*.node
  134. build-freebsd:
  135. runs-on: macos-latest
  136. name: Build FreeBSD
  137. steps:
  138. - uses: actions/checkout@v2
  139. - name: Build
  140. id: build
  141. uses: vmactions/freebsd-vm@v0.1.4
  142. env:
  143. DEBUG: 'napi:*'
  144. RUSTUP_HOME: /usr/local/rustup
  145. CARGO_HOME: /usr/local/cargo
  146. RUSTUP_IO_THREADS: 1
  147. with:
  148. envs: 'DEBUG RUSTUP_HOME CARGO_HOME RUSTUP_IO_THREADS'
  149. usesh: true
  150. mem: 3000
  151. prepare: |
  152. pkg install -y curl node yarn npm python2
  153. curl https://sh.rustup.rs -sSf --output rustup.sh
  154. sh rustup.sh -y --profile minimal --default-toolchain stable
  155. export PATH="/usr/local/cargo/bin:$PATH"
  156. echo "~~~~ rustc --version ~~~~"
  157. rustc --version
  158. echo "~~~~ node -v ~~~~"
  159. node -v
  160. echo "~~~~ yarn --version ~~~~"
  161. yarn --version
  162. run: |
  163. export PATH="/usr/local/cargo/bin:$PATH"
  164. pwd
  165. ls -lah
  166. whoami
  167. env
  168. freebsd-version
  169. yarn install --ignore-scripts --frozen-lockfile --registry https://registry.npmjs.org --network-timeout 300000
  170. yarn build
  171. yarn test
  172. rm -rf node_modules
  173. rm -rf target
  174. - name: Upload artifact
  175. uses: actions/upload-artifact@v2
  176. with:
  177. name: bindings-freebsd
  178. path: ${{ env.APP_NAME }}.*.node
  179. test-macOS-windows-binding:
  180. name: Test bindings on ${{ matrix.settings.target }} - node@${{ matrix.node }}
  181. needs:
  182. - build
  183. strategy:
  184. fail-fast: false
  185. matrix:
  186. settings:
  187. - host: macos-latest
  188. target: 'x86_64-apple-darwin'
  189. - host: windows-latest
  190. target: 'x86_64-pc-windows-msvc'
  191. node: ['12', '14', '16']
  192. runs-on: ${{ matrix.settings.host }}
  193. steps:
  194. - uses: actions/checkout@v2
  195. - name: Setup node
  196. uses: actions/setup-node@v2
  197. with:
  198. node-version: ${{ matrix.node }}
  199. check-latest: true
  200. - name: Cache NPM dependencies
  201. uses: actions/cache@v1
  202. with:
  203. path: node_modules
  204. key: npm-cache-test-${{ matrix.settings.target }}-${{ matrix.node }}-${{ hashFiles('yarn.lock') }}
  205. - name: 'Install dependencies'
  206. run: yarn install --ignore-scripts --frozen-lockfile --registry https://registry.npmjs.org --network-timeout 300000
  207. - name: Download artifacts
  208. uses: actions/download-artifact@v2
  209. with:
  210. name: bindings-${{ matrix.settings.target }}
  211. path: .
  212. - name: List packages
  213. run: ls -R .
  214. shell: bash
  215. - name: Test bindings
  216. run: yarn test
  217. test-linux-x64-gnu-binding:
  218. name: Test bindings on Linux-x64-gnu - node@${{ matrix.node }}
  219. needs:
  220. - build
  221. strategy:
  222. fail-fast: false
  223. matrix:
  224. node: ['12', '14', '16']
  225. runs-on: ubuntu-20.04
  226. steps:
  227. - uses: actions/checkout@v2
  228. - name: Setup node
  229. uses: actions/setup-node@v2
  230. with:
  231. node-version: ${{ matrix.node }}
  232. check-latest: true
  233. - name: Cache NPM dependencies
  234. uses: actions/cache@v1
  235. with:
  236. path: node_modules
  237. key: npm-cache-test-linux-x64-gnu-${{ matrix.node }}-${{ hashFiles('yarn.lock') }}
  238. - name: 'Install dependencies'
  239. run: yarn install --ignore-scripts --frozen-lockfile --registry https://registry.npmjs.org --network-timeout 300000
  240. - name: Download artifacts
  241. uses: actions/download-artifact@v2
  242. with:
  243. name: bindings-x86_64-unknown-linux-gnu
  244. path: .
  245. - name: List packages
  246. run: ls -R .
  247. shell: bash
  248. - name: Test bindings
  249. run: docker run --rm -v $(pwd):/canvas -w /canvas node:${{ matrix.node }}-slim yarn test
  250. test-linux-x64-musl-binding:
  251. name: Test bindings on x86_64-unknown-linux-musl - node@${{ matrix.node }}
  252. needs:
  253. - build
  254. strategy:
  255. fail-fast: false
  256. matrix:
  257. node: ['12', '14', '16']
  258. runs-on: ubuntu-20.04
  259. steps:
  260. - uses: actions/checkout@v2
  261. - name: Setup node
  262. uses: actions/setup-node@v2
  263. with:
  264. node-version: ${{ matrix.node }}
  265. check-latest: true
  266. - name: Cache NPM dependencies
  267. uses: actions/cache@v1
  268. with:
  269. path: node_modules
  270. key: npm-cache-test-x86_64-unknown-linux-musl-${{ matrix.node }}-${{ hashFiles('yarn.lock') }}
  271. - name: 'Install dependencies'
  272. run: yarn install --ignore-scripts --frozen-lockfile --registry https://registry.npmjs.org --network-timeout 300000
  273. - name: Download artifacts
  274. uses: actions/download-artifact@v2
  275. with:
  276. name: bindings-x86_64-unknown-linux-musl
  277. path: .
  278. - name: List packages
  279. run: ls -R .
  280. shell: bash
  281. - name: Test bindings
  282. run: docker run --rm -v $(pwd):/canvas -w /canvas node:${{ matrix.node }}-alpine yarn test
  283. test-linux-aarch64-gnu-binding:
  284. name: Test bindings on aarch64-unknown-linux-gnu - node@${{ matrix.node }}
  285. needs:
  286. - build
  287. strategy:
  288. fail-fast: false
  289. matrix:
  290. node: ['12', '14', '16']
  291. runs-on: ubuntu-20.04
  292. steps:
  293. - run: docker run --rm --privileged multiarch/qemu-user-static:register --reset
  294. - uses: actions/checkout@v2
  295. - name: Download artifacts
  296. uses: actions/download-artifact@v2
  297. with:
  298. name: bindings-aarch64-unknown-linux-gnu
  299. path: .
  300. - name: List packages
  301. run: ls -R .
  302. shell: bash
  303. - uses: uraimo/run-on-arch-action@v2.0.9
  304. name: Setup and run tests
  305. id: runcmd
  306. with:
  307. arch: aarch64
  308. distro: ubuntu20.04
  309. dockerRunArgs: |
  310. --volume "${PWD}:/canvas"
  311. -w /canvas
  312. # Not required, but speeds up builds by storing container images in
  313. # a GitHub package registry.
  314. githubToken: ${{ github.token }}
  315. install: |
  316. apt-get update && \
  317. apt-get install -y ca-certificates gnupg2 curl apt-transport-https && \
  318. curl -sL https://deb.nodesource.com/setup_${{ matrix.node }}.x | bash - && \
  319. apt-get install -y nodejs && \
  320. npm install -g yarn
  321. run: |
  322. yarn install --ignore-scripts --registry https://registry.npmjs.org --network-timeout 300000
  323. yarn test
  324. ls -la
  325. test-linux-arm-gnueabihf-binding:
  326. name: Test bindings on armv7-unknown-linux-gnueabihf - node@${{ matrix.node }}
  327. needs:
  328. - build
  329. strategy:
  330. fail-fast: false
  331. matrix:
  332. node: ['12', '14', '16']
  333. runs-on: ubuntu-20.04
  334. steps:
  335. - run: docker run --rm --privileged multiarch/qemu-user-static:register --reset
  336. - uses: actions/checkout@v2
  337. - name: Download artifacts
  338. uses: actions/download-artifact@v2
  339. with:
  340. name: bindings-armv7-unknown-linux-gnueabihf
  341. path: .
  342. - name: List packages
  343. run: ls -R .
  344. shell: bash
  345. - uses: uraimo/run-on-arch-action@v2.0.9
  346. name: Setup and run tests
  347. id: runcmd
  348. with:
  349. arch: armv7
  350. distro: ubuntu20.04
  351. dockerRunArgs: |
  352. --volume "${PWD}:/canvas"
  353. -w /canvas
  354. # Not required, but speeds up builds by storing container images in
  355. # a GitHub package registry.
  356. githubToken: ${{ github.token }}
  357. install: |
  358. apt-get update && \
  359. apt-get install -y ca-certificates gnupg2 curl apt-transport-https && \
  360. curl -sL https://deb.nodesource.com/setup_${{ matrix.node }}.x | bash - && \
  361. apt-get install -y nodejs && \
  362. npm install -g yarn
  363. run: |
  364. yarn install --ignore-scripts --registry https://registry.npmjs.org --network-timeout 300000
  365. yarn test
  366. ls -la
  367. publish:
  368. name: Publish
  369. runs-on: ubuntu-20.04
  370. needs:
  371. - test-linux-x64-gnu-binding
  372. - test-linux-x64-musl-binding
  373. - test-linux-aarch64-gnu-binding
  374. - test-linux-arm-gnueabihf-binding
  375. - test-macOS-windows-binding
  376. - build-freebsd
  377. steps:
  378. - uses: actions/checkout@v2
  379. - name: Setup node
  380. uses: actions/setup-node@v2
  381. with:
  382. node-version: 14
  383. check-latest: true
  384. - name: Cache NPM dependencies
  385. uses: actions/cache@v1
  386. with:
  387. path: node_modules
  388. key: npm-cache-ubuntu-latest-${{ hashFiles('yarn.lock') }}
  389. restore-keys: |
  390. npm-cache-
  391. - name: 'Install dependencies'
  392. run: yarn install --ignore-scripts --frozen-lockfile --registry https://registry.npmjs.org --network-timeout 300000
  393. - name: Download all artifacts
  394. uses: actions/download-artifact@v2
  395. with:
  396. path: artifacts
  397. - name: Move artifacts
  398. run: yarn artifacts
  399. - name: List packages
  400. run: ls -R ./npm
  401. shell: bash
  402. - name: Publish
  403. run: |
  404. if git log -1 --pretty=%B | grep "^[0-9]\+\.[0-9]\+\.[0-9]\+$";
  405. then
  406. echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" >> ~/.npmrc
  407. npm publish --access public
  408. elif git log -1 --pretty=%B | grep "^[0-9]\+\.[0-9]\+\.[0-9]\+";
  409. then
  410. echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" >> ~/.npmrc
  411. npm publish --tag next --access public
  412. else
  413. echo "Not a release, skipping publish"
  414. fi
  415. env:
  416. GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  417. NPM_TOKEN: ${{ secrets.NPM_TOKEN }}