publish-packages.yml 9.0 KB

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