publish-packages.yml 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. name: Publish bolt-cli packages
  2. on:
  3. release:
  4. types: [ published ]
  5. push:
  6. branches:
  7. - 'release/v*'
  8. workflow_dispatch:
  9. inputs:
  10. release_version:
  11. description: 'The release version'
  12. required: true
  13. default: '0.0.1'
  14. jobs:
  15. publish-npm-binaries:
  16. name: Publish NPM packages
  17. runs-on: ${{ matrix.build.os }}
  18. strategy:
  19. fail-fast: false
  20. matrix:
  21. build:
  22. - {
  23. NAME: linux-x64-glibc,
  24. OS: ubuntu-20.04,
  25. TOOLCHAIN: stable,
  26. TARGET: x86_64-unknown-linux-gnu,
  27. }
  28. - {
  29. NAME: linux-x64-musl,
  30. OS: ubuntu-22.04,
  31. TOOLCHAIN: stable,
  32. TARGET: x86_64-unknown-linux-musl,
  33. }
  34. - {
  35. NAME: linux-x86-glibc,
  36. OS: ubuntu-22.04,
  37. TOOLCHAIN: stable,
  38. TARGET: i686-unknown-linux-gnu,
  39. }
  40. - {
  41. NAME: linux-x86-musl,
  42. OS: ubuntu-22.04,
  43. TOOLCHAIN: stable,
  44. TARGET: i686-unknown-linux-musl,
  45. }
  46. - {
  47. NAME: linux-arm64-glibc,
  48. OS: ubuntu-20.04,
  49. TOOLCHAIN: stable,
  50. TARGET: aarch64-unknown-linux-gnu,
  51. }
  52. - {
  53. NAME: linux-arm64-musl,
  54. OS: ubuntu-20.04,
  55. TOOLCHAIN: stable,
  56. TARGET: aarch64-unknown-linux-musl,
  57. }
  58. - {
  59. NAME: win32-x64-msvc,
  60. OS: windows-2022,
  61. TOOLCHAIN: stable,
  62. TARGET: x86_64-pc-windows-msvc,
  63. }
  64. - {
  65. NAME: win32-x86-msvc,
  66. OS: windows-2022,
  67. TOOLCHAIN: stable,
  68. TARGET: i686-pc-windows-msvc,
  69. }
  70. - {
  71. NAME: darwin-x64,
  72. OS: macos-11,
  73. TOOLCHAIN: stable,
  74. TARGET: x86_64-apple-darwin,
  75. }
  76. - {
  77. NAME: darwin-arm64,
  78. OS: macos-11,
  79. TOOLCHAIN: stable,
  80. TARGET: aarch64-apple-darwin,
  81. }
  82. steps:
  83. - name: Checkout
  84. uses: actions/checkout@v4
  85. - name: Set DRY_RUN based on trigger
  86. shell: bash
  87. run: echo "DRY_RUN=true" >> $GITHUB_ENV
  88. if: github.event_name == 'push' && startsWith(github.ref, 'refs/heads/release/v')
  89. - name: Set the release version
  90. shell: bash
  91. run: |
  92. if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
  93. echo "RELEASE_VERSION=${{ github.event.inputs.release_version }}" >> $GITHUB_ENV
  94. elif [[ "${{ github.event_name }}" == "push" ]]; then
  95. VERSION=$(echo "${GITHUB_REF}" | sed -E 's|refs/heads/release/v||')
  96. echo "RELEASE_VERSION=${VERSION}" >> $GITHUB_ENV
  97. elif [[ "${{ github.event_name }}" == "release" ]]; then
  98. VERSION=$(echo "${GITHUB_REF}" | sed -E 's|refs/tags/v||')
  99. echo "RELEASE_VERSION=${VERSION}" >> $GITHUB_ENV
  100. fi
  101. - name: Install Rust toolchain
  102. uses: actions-rs/toolchain@v1
  103. with:
  104. toolchain: ${{ matrix.build.TOOLCHAIN }}
  105. target: ${{ matrix.build.TARGET }}
  106. override: true
  107. - name: Build (linux/macos)
  108. if: matrix.build.OS != 'windows-2022'
  109. uses: actions-rs/cargo@v1
  110. with:
  111. use-cross: true
  112. command: build
  113. args: --manifest-path=cli/Cargo.toml --release --locked --target ${{ matrix.build.TARGET }}
  114. - name: Build (windows)
  115. if: matrix.build.OS == 'windows-2022'
  116. uses: actions-rs/cargo@v1
  117. with:
  118. command: build
  119. args: --manifest-path=cli/Cargo.toml --no-default-features --release --locked --target ${{ matrix.build.TARGET }}
  120. - name: Check versions are aligned
  121. run: |
  122. # Fails if versions are not aligned
  123. cargo install git-cliff
  124. ./version-align.sh --check
  125. - name: Build the NPM package
  126. shell: bash
  127. run: |
  128. # set the binary name
  129. bin="bolt"
  130. # derive the OS and architecture from the build matrix name
  131. # note: when split by a hyphen, first part is the OS and the second is the architecture
  132. node_os=$(echo "${{ matrix.build.NAME }}" | cut -d '-' -f1)
  133. export node_os
  134. node_arch=$(echo "${{ matrix.build.NAME }}" | cut -d '-' -f2)
  135. export node_arch
  136. # set the version
  137. export node_version="${{ env.RELEASE_VERSION }}"
  138. # set the package name
  139. # note: use 'windows' as OS name instead of 'win32'
  140. if [ "${{ matrix.build.OS }}" = "windows-2022" ]; then
  141. export node_pkg="${bin}-cli-windows-${node_arch}"
  142. else
  143. export node_pkg="${bin}-cli-${node_os}-${node_arch}"
  144. fi
  145. echo "node_pkg=${node_pkg}" >> $GITHUB_ENV
  146. # create the package directory
  147. mkdir -p "${node_pkg}/bin"
  148. # generate package.json from the template
  149. envsubst < cli/npm-package/package.json.tmpl > "${node_pkg}/package.json"
  150. cat "${node_pkg}/package.json"
  151. # copy the binary into the package
  152. # note: windows binaries has '.exe' extension
  153. if [ "${{ matrix.build.OS }}" = "windows-2022" ]; then
  154. bin="${bin}.exe"
  155. fi
  156. echo "bin_name=${bin}" >> $GITHUB_ENV
  157. cp "target/${{ matrix.build.TARGET }}/release/${bin}" "${node_pkg}/bin"
  158. cp "target/${{ matrix.build.TARGET }}/release/${bin}" "${node_pkg}/bin"
  159. # Create the release bin file
  160. release_name="bolt-cli-${{ matrix.build.NAME }}"
  161. if [ "${{ matrix.build.OS }}" = "windows-2022" ]; then
  162. release_name="${release_name}.exe"
  163. fi
  164. echo "release_name=${release_name}" >> $GITHUB_ENV
  165. mv "target/${{ matrix.build.TARGET }}/release/${bin}" "target/${{ matrix.build.TARGET }}/release/${release_name}"
  166. - name: Publish binary to GitHub release
  167. if: ${{ env.DRY_RUN != 'true' }}
  168. uses: svenstaro/upload-release-action@v2
  169. with:
  170. repo_token: ${{ secrets.GITHUB_TOKEN }}
  171. file: target/${{ matrix.build.TARGET }}/release/${{ env.release_name }}
  172. overwrite: true
  173. tag: "v${{ env.RELEASE_VERSION }}"
  174. release_name: "v${{ env.RELEASE_VERSION }}"
  175. asset_name: "${{ env.release_name }}"
  176. - name: Publish the NPM package
  177. run: |
  178. echo "DRY_RUN=${{ env.DRY_RUN }}"
  179. cd ${{ env.node_pkg }}
  180. echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}" > ~/.npmrc
  181. npm set //registry.npmjs.org/:_authToken ${{ secrets.NPM_TOKEN }}
  182. if [ "${{ env.DRY_RUN }}" = "true" ]; then
  183. echo "Running npm publish in dry-run mode"
  184. npm publish --access public --dry-run
  185. else
  186. npm publish --access public
  187. fi
  188. shell: bash
  189. env:
  190. NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
  191. publish-wrapper-npm-package:
  192. name: Publish wrapper NPM packages
  193. runs-on: ubuntu-20.04
  194. needs: publish-npm-binaries
  195. steps:
  196. - name: Checkout
  197. uses: actions/checkout@v4
  198. - name: Set DRY_RUN based on trigger
  199. run: echo "DRY_RUN=true" >> $GITHUB_ENV
  200. if: github.event_name == 'push' && startsWith(github.ref, 'refs/heads/release/v')
  201. - name: Publish the NPM package
  202. shell: bash
  203. run: |
  204. cd cli/npm-package
  205. npm install
  206. npm run build
  207. cd lib
  208. echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}" > ~/.npmrc
  209. npm set //registry.npmjs.org/:_authToken ${{ secrets.NPM_TOKEN }}
  210. if [ "${DRY_RUN}" = "true" ]; then
  211. echo "Running npm publish in dry-run mode"
  212. npm publish --access public --dry-run
  213. else
  214. npm publish --access public
  215. fi
  216. env:
  217. NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}