publish-packages.yml 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  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: Build the NPM package
  87. shell: bash
  88. run: |
  89. # set the binary name
  90. bin="bolt"
  91. # derive the OS and architecture from the build matrix name
  92. # note: when split by a hyphen, first part is the OS and the second is the architecture
  93. node_os=$(echo "${{ matrix.build.NAME }}" | cut -d '-' -f1)
  94. export node_os
  95. node_arch=$(echo "${{ matrix.build.NAME }}" | cut -d '-' -f2)
  96. export node_arch
  97. # set the version
  98. export node_version="${{ env.RELEASE_VERSION }}"
  99. # set the package name
  100. # note: use 'windows' as OS name instead of 'win32'
  101. if [ "${{ matrix.build.OS }}" = "windows-2022" ]; then
  102. export node_pkg="${bin}-cli-windows-${node_arch}"
  103. else
  104. export node_pkg="${bin}-cli-${node_os}-${node_arch}"
  105. fi
  106. echo "node_pkg=${node_pkg}" >> $GITHUB_ENV
  107. # create the package directory
  108. mkdir -p "${node_pkg}/bin"
  109. # generate package.json from the template
  110. envsubst < cli/npm-package/package.json.tmpl > "${node_pkg}/package.json"
  111. cat "${node_pkg}/package.json"
  112. # copy the binary into the package
  113. # note: windows binaries has '.exe' extension
  114. if [ "${{ matrix.build.OS }}" = "windows-2022" ]; then
  115. bin="${bin}.exe"
  116. fi
  117. echo "bin_name=${bin}" >> $GITHUB_ENV
  118. cp "target/${{ matrix.build.TARGET }}/release/${bin}" "${node_pkg}/bin"
  119. cp "target/${{ matrix.build.TARGET }}/release/${bin}" "${node_pkg}/bin"
  120. # Create the release bin file
  121. release_name="bolt-${{ matrix.build.NAME }}"
  122. if [ "${{ matrix.build.OS }}" = "windows-2022" ]; then
  123. release_name="${release_name}.exe"
  124. fi
  125. echo "release_name=${release_name}" >> $GITHUB_ENV
  126. mv "target/${{ matrix.build.TARGET }}/release/${bin}" "target/${{ matrix.build.TARGET }}/release/${release_name}"
  127. - name: Publish binary to GitHub release
  128. uses: svenstaro/upload-release-action@v2
  129. with:
  130. repo_token: ${{ secrets.GITHUB_TOKEN }}
  131. file: target/${{ matrix.build.TARGET }}/release/${{ env.release_name }}
  132. overwrite: true
  133. tag: "v${{ env.RELEASE_VERSION }}"
  134. release_name: "v${{ env.RELEASE_VERSION }}"
  135. asset_name: "${{ env.release_name }}"
  136. - name: Publish the NPM package
  137. shell: bash
  138. run: |
  139. cd ${{ env.node_pkg }}
  140. echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}" > ~/.npmrc
  141. npm set //registry.npmjs.org/:_authToken ${{ secrets.NPM_TOKEN }}
  142. npm publish --access public
  143. env:
  144. NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
  145. publish-wrapper-npm-package:
  146. name: Publish wrapper NPM packages
  147. runs-on: ubuntu-20.04
  148. needs: publish-npm-binaries
  149. steps:
  150. - name: Checkout
  151. uses: actions/checkout@v4
  152. - name: Publish the NPM package
  153. shell: bash
  154. run: |
  155. cd cli/npm-package
  156. npm install
  157. npm run build
  158. cd lib
  159. echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}" > ~/.npmrc
  160. npm set //registry.npmjs.org/:_authToken ${{ secrets.NPM_TOKEN }}
  161. npm publish --access public
  162. env:
  163. NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}