publish-packages.yml 6.0 KB

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