CI.yaml 17 KB

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