CI.yaml 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. name: CI
  2. on:
  3. push:
  4. branches:
  5. - '**'
  6. tags-ignore:
  7. - '**'
  8. pull_request:
  9. branches:
  10. - '**'
  11. jobs:
  12. build:
  13. if: "!contains(github.event.head_commit.message, 'skip ci')"
  14. strategy:
  15. fail-fast: false
  16. matrix:
  17. os: [ubuntu-latest, macos-latest, windows-latest]
  18. name: stable - ${{ matrix.os }} - node@12
  19. runs-on: ${{ matrix.os }}
  20. steps:
  21. - uses: actions/checkout@v2
  22. - name: Setup node
  23. uses: actions/setup-node@v1
  24. with:
  25. node-version: 12
  26. - name: Set platform name
  27. run: |
  28. export NODE_PLATFORM_NAME=$(node -e "console.log(require('os').platform())")
  29. echo "::set-env name=PLATFORM_NAME::$NODE_PLATFORM_NAME"
  30. shell: bash
  31. - name: Install llvm
  32. if: matrix.os == 'windows-latest'
  33. run: choco install -y llvm
  34. - name: Set llvm path
  35. if: matrix.os == 'windows-latest'
  36. uses: allenevans/set-env@v1.0.0
  37. with:
  38. LIBCLANG_PATH: 'C:\\Program Files\\LLVM\\bin'
  39. - name: Install
  40. uses: actions-rs/toolchain@v1
  41. with:
  42. toolchain: stable
  43. profile: minimal
  44. override: true
  45. - name: Generate Cargo.lock
  46. uses: actions-rs/cargo@v1
  47. with:
  48. command: generate-lockfile
  49. - name: Cache cargo registry
  50. uses: actions/cache@v1
  51. with:
  52. path: ~/.cargo/registry
  53. key: stable-${{ matrix.os }}-node@12-cargo-registry-trimmed-${{ hashFiles('**/Cargo.lock') }}
  54. - name: Cache cargo index
  55. uses: actions/cache@v1
  56. with:
  57. path: ~/.cargo/git
  58. key: stable-${{ matrix.os }}gnu-node@12-cargo-index-trimmed-${{ hashFiles('**/Cargo.lock') }}
  59. - name: Cache NPM dependencies
  60. uses: actions/cache@v1
  61. with:
  62. path: node_modules
  63. key: npm-cache-${{ matrix.os }}-node@12-${{ hashFiles('yarn.lock') }}
  64. restore-keys: |
  65. npm-cache-
  66. - name: 'Install dependencies'
  67. run: yarn install --frozen-lockfile --registry https://registry.npmjs.org
  68. - name: 'Build'
  69. run: yarn build
  70. - name: Upload artifact
  71. uses: actions/upload-artifact@v2
  72. with:
  73. name: bindings-${{ env.PLATFORM_NAME }}
  74. path: index.${{ env.PLATFORM_NAME }}.node
  75. - name: Clear the cargo caches
  76. run: |
  77. cargo install cargo-cache --no-default-features --features ci-autoclean
  78. cargo-cache
  79. test_binding:
  80. name: Test bindings on ${{ matrix.os }} - node@${{ matrix.node }}
  81. needs:
  82. - build
  83. strategy:
  84. fail-fast: false
  85. matrix:
  86. os: [ubuntu-latest, macos-latest, windows-latest]
  87. node: ['10', '12', '14']
  88. runs-on: ${{ matrix.os }}
  89. steps:
  90. - uses: actions/checkout@v2
  91. - name: Setup node
  92. uses: actions/setup-node@v1
  93. with:
  94. node-version: ${{ matrix.node }}
  95. - name: Set platform name
  96. run: |
  97. export NODE_PLATFORM_NAME=$(node -e "console.log(require('os').platform())")
  98. echo "::set-env name=PLATFORM_NAME::$NODE_PLATFORM_NAME"
  99. shell: bash
  100. # Do not cache node_modules, or yarn workspace links broken
  101. - name: 'Install dependencies'
  102. run: yarn install --frozen-lockfile --registry https://registry.npmjs.org
  103. - name: Download artifacts
  104. uses: actions/download-artifact@v2
  105. with:
  106. name: bindings-${{ env.PLATFORM_NAME }}
  107. path: .
  108. - name: List packages
  109. run: ls -R .
  110. shell: bash
  111. - name: Test bindings
  112. run: yarn test
  113. publish:
  114. name: Publish
  115. runs-on: ubuntu-latest
  116. needs: test_binding
  117. steps:
  118. - uses: actions/checkout@v2
  119. - name: Setup node
  120. uses: actions/setup-node@v1
  121. with:
  122. node-version: 12
  123. - name: Cache NPM dependencies
  124. uses: actions/cache@v1
  125. with:
  126. path: node_modules
  127. key: npm-cache-ubuntu-latest-${{ hashFiles('yarn.lock') }}
  128. restore-keys: |
  129. npm-cache-
  130. - name: 'Install dependencies'
  131. run: yarn install --frozen-lockfile --registry https://registry.npmjs.org
  132. - name: Download all artifacts
  133. uses: actions/download-artifact@v2
  134. with:
  135. path: .
  136. - name: List packages
  137. run: ls -R .
  138. shell: bash
  139. - name: Publish
  140. run: |
  141. if git log -1 --pretty=%B | grep "^[0-9]\+\.[0-9]\+\.[0-9]\+$";
  142. then
  143. node ./scripts/upload-to-release.js
  144. echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" >> ~/.npmrc
  145. npm publish
  146. else
  147. echo "Not a release, skipping publish"
  148. fi
  149. env:
  150. GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  151. NPM_TOKEN: ${{ secrets.NPM_TOKEN }}