CI.yaml 13 KB

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