CI.yaml 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  1. name: CI
  2. env:
  3. DEBUG: 'napi:*'
  4. on:
  5. push:
  6. branches: [master, develop]
  7. tags-ignore:
  8. - '**'
  9. pull_request:
  10. jobs:
  11. build:
  12. if: "!contains(github.event.head_commit.message, 'skip ci')"
  13. strategy:
  14. fail-fast: false
  15. matrix:
  16. os: [ubuntu-latest, macos-latest, windows-latest]
  17. name: stable - ${{ matrix.os }} - node@12
  18. runs-on: ${{ matrix.os }}
  19. steps:
  20. - uses: actions/checkout@v2
  21. - name: Setup node
  22. uses: actions/setup-node@v1
  23. with:
  24. node-version: 12
  25. - name: Set platform name
  26. run: |
  27. export NODE_PLATFORM_NAME=$(node -e "console.log(require('os').platform())")
  28. echo "::set-env name=PLATFORM_NAME::$NODE_PLATFORM_NAME"
  29. shell: bash
  30. - name: Install llvm
  31. if: matrix.os == 'windows-latest'
  32. run: choco install -y llvm
  33. - name: Set llvm path
  34. if: matrix.os == 'windows-latest'
  35. uses: allenevans/set-env@v1.0.0
  36. with:
  37. LIBCLANG_PATH: 'C:\\Program Files\\LLVM\\bin'
  38. - name: Install
  39. uses: actions-rs/toolchain@v1
  40. with:
  41. toolchain: stable
  42. profile: minimal
  43. override: true
  44. - name: Generate Cargo.lock
  45. uses: actions-rs/cargo@v1
  46. with:
  47. command: generate-lockfile
  48. - name: Cache cargo registry
  49. uses: actions/cache@v1
  50. with:
  51. path: ~/.cargo/registry
  52. key: stable-${{ matrix.os }}-node@12-cargo-registry-trimmed-${{ hashFiles('**/Cargo.lock') }}
  53. - name: Cache cargo index
  54. uses: actions/cache@v1
  55. with:
  56. path: ~/.cargo/git
  57. key: stable-${{ matrix.os }}gnu-node@12-cargo-index-trimmed-${{ hashFiles('**/Cargo.lock') }}
  58. - name: Cache NPM dependencies
  59. uses: actions/cache@v1
  60. with:
  61. path: node_modules
  62. key: npm-cache-${{ matrix.os }}-node@12-${{ hashFiles('yarn.lock') }}
  63. restore-keys: |
  64. npm-cache-
  65. - name: 'Install dependencies'
  66. run: yarn install --frozen-lockfile --registry https://registry.npmjs.org
  67. - name: 'Build'
  68. if: matrix.os != 'macos-latest'
  69. run: yarn build
  70. - name: 'Build'
  71. if: matrix.os == 'macos-latest'
  72. run: yarn build
  73. env:
  74. MACOSX_DEPLOYMENT_TARGET: '10.13'
  75. - name: Upload artifact
  76. uses: actions/upload-artifact@v2
  77. with:
  78. name: bindings-${{ env.PLATFORM_NAME }}
  79. path: package-template.${{ env.PLATFORM_NAME }}.node
  80. - name: Clear the cargo caches
  81. run: |
  82. cargo install cargo-cache --no-default-features --features ci-autoclean
  83. cargo-cache
  84. build_musl:
  85. if: "!contains(github.event.head_commit.message, 'skip ci')"
  86. name: stable - linux-musl - node@12
  87. runs-on: ubuntu-latest
  88. steps:
  89. - uses: actions/checkout@v2
  90. - name: Login to registry
  91. run: |
  92. docker login -u $DOCKER_USERNAME -p $DOCKER_PASSWORD $DOCKER_REGISTRY_URL
  93. env:
  94. DOCKER_REGISTRY_URL: docker.pkg.github.com
  95. DOCKER_USERNAME: ${{ github.actor }}
  96. DOCKER_PASSWORD: ${{ secrets.GITHUB_TOKEN }}
  97. - name: Pull docker image
  98. run: |
  99. docker pull docker.pkg.github.com/napi-rs/napi-rs/rust-nodejs-alpine:lts
  100. docker tag docker.pkg.github.com/napi-rs/napi-rs/rust-nodejs-alpine:lts builder
  101. - name: 'Install dependencies'
  102. run: yarn install --frozen-lockfile --registry https://registry.npmjs.org
  103. - name: 'Build'
  104. run: |
  105. docker run --rm -v $(pwd)/.cargo:/root/.cargo -v $(pwd):/fast-escape -w /fast-escape builder sh -c "yarn build --musl"
  106. - name: Upload artifact
  107. uses: actions/upload-artifact@v2
  108. with:
  109. name: bindings-linux-musl
  110. path: package-template.linux-musl.node
  111. test_binding:
  112. name: Test bindings on ${{ matrix.os }} - node@${{ matrix.node }}
  113. needs:
  114. - build
  115. strategy:
  116. fail-fast: false
  117. matrix:
  118. os: [ubuntu-latest, macos-latest, windows-latest]
  119. node: ['10', '12', '14']
  120. runs-on: ${{ matrix.os }}
  121. steps:
  122. - uses: actions/checkout@v2
  123. - name: Setup node
  124. uses: actions/setup-node@v1
  125. with:
  126. node-version: ${{ matrix.node }}
  127. - name: Set platform name
  128. run: |
  129. export NODE_PLATFORM_NAME=$(node -e "console.log(require('os').platform())")
  130. echo "::set-env name=PLATFORM_NAME::$NODE_PLATFORM_NAME"
  131. shell: bash
  132. # Do not cache node_modules, or yarn workspace links broken
  133. - name: 'Install dependencies'
  134. run: yarn install --frozen-lockfile --registry https://registry.npmjs.org
  135. - name: Download artifacts
  136. uses: actions/download-artifact@v2
  137. with:
  138. name: bindings-${{ env.PLATFORM_NAME }}
  139. path: .
  140. - name: List packages
  141. run: ls -R .
  142. shell: bash
  143. - name: Test bindings
  144. run: yarn test
  145. test_musl_binding:
  146. name: Test bindings on alpine - node@${{ matrix.node }}
  147. needs:
  148. - build_musl
  149. strategy:
  150. fail-fast: false
  151. matrix:
  152. node: ['12', '14']
  153. runs-on: ubuntu-latest
  154. steps:
  155. - uses: actions/checkout@v2
  156. - name: 'Install dependencies'
  157. run: yarn install --frozen-lockfile --ignore-scripts --registry https://registry.npmjs.org
  158. - name: Download artifacts
  159. uses: actions/download-artifact@v2
  160. with:
  161. name: bindings-linux-musl
  162. path: .
  163. - name: List files
  164. run: ls -R .
  165. shell: bash
  166. - name: Run simple tests
  167. run: docker run --rm -v $(pwd)/.cargo:/root/.cargo -v $(pwd):/fast-escape -w /fast-escape node:${{ matrix.node }}-alpine sh -c "node ./simple-test.js"
  168. dependabot:
  169. needs:
  170. - test_binding
  171. - test_musl_binding
  172. runs-on: ubuntu-latest
  173. steps:
  174. - name: auto-merge
  175. uses: ridedott/dependabot-auto-merge-action@master
  176. with:
  177. GITHUB_LOGIN: dependabot[bot]
  178. GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  179. publish:
  180. name: Publish
  181. runs-on: ubuntu-latest
  182. needs:
  183. - test_binding
  184. - test_musl_binding
  185. steps:
  186. - uses: actions/checkout@v2
  187. - name: Setup node
  188. uses: actions/setup-node@v1
  189. with:
  190. node-version: 12
  191. - name: Cache NPM dependencies
  192. uses: actions/cache@v1
  193. with:
  194. path: node_modules
  195. key: npm-cache-ubuntu-latest-${{ hashFiles('yarn.lock') }}
  196. restore-keys: |
  197. npm-cache-
  198. - name: 'Install dependencies'
  199. run: yarn install --frozen-lockfile --registry https://registry.npmjs.org
  200. - name: Download all artifacts
  201. uses: actions/download-artifact@v2
  202. with:
  203. path: artifacts
  204. - name: Move artifacts
  205. run: yarn artifacts
  206. - name: List packages
  207. run: ls -R .
  208. shell: bash
  209. - name: Publish
  210. run: |
  211. if git log -1 --pretty=%B | grep "^[0-9]\+\.[0-9]\+\.[0-9]\+$";
  212. then
  213. echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" >> ~/.npmrc
  214. npm publish
  215. else
  216. echo "Not a release, skipping publish"
  217. fi
  218. env:
  219. GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  220. NPM_TOKEN: ${{ secrets.NPM_TOKEN }}