publish-rust.yml 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. name: Publish Rust Crate
  2. on:
  3. workflow_dispatch:
  4. inputs:
  5. package_path:
  6. description: Path to directory with package to release
  7. required: true
  8. default: 'clients/rust'
  9. type: choice
  10. options:
  11. - clients/rust
  12. - interface
  13. - program
  14. - p-token
  15. level:
  16. description: Level
  17. required: true
  18. default: patch
  19. type: choice
  20. options:
  21. - patch
  22. - minor
  23. - major
  24. - rc
  25. - beta
  26. - alpha
  27. - release
  28. - version
  29. version:
  30. description: Version (used with level "version")
  31. required: false
  32. type: string
  33. dry_run:
  34. description: Dry run
  35. required: true
  36. default: true
  37. type: boolean
  38. create_release:
  39. description: Create a GitHub release
  40. required: true
  41. type: boolean
  42. default: true
  43. jobs:
  44. test:
  45. name: Test Rust Crate
  46. runs-on: ubuntu-latest
  47. steps:
  48. - name: Git Checkout
  49. uses: actions/checkout@v4
  50. - name: Setup Environment
  51. uses: ./.github/actions/setup
  52. with:
  53. clippy: true
  54. rustfmt: true
  55. solana: true
  56. cargo-cache-key: cargo-test-publish-${{ inputs.package_path }}
  57. cargo-cache-fallback-key: cargo-test-publish
  58. - name: Format
  59. run: pnpm zx ./scripts/rust/format.mjs "${{ inputs.package_path }}"
  60. - name: Lint
  61. run: pnpm zx ./scripts/rust/lint.mjs "${{ inputs.package_path }}"
  62. - name: Build programs
  63. run: pnpm programs:build
  64. - name: Test
  65. run: pnpm zx ./scripts/rust/test.mjs "${{ inputs.package_path }}"
  66. semver:
  67. name: Check Semver
  68. runs-on: ubuntu-latest
  69. steps:
  70. - name: Git checkout
  71. uses: actions/checkout@v4
  72. - name: Setup Environment
  73. uses: ./.github/actions/setup
  74. with:
  75. cargo-cache-key: cargo-publish-semver-${{ inputs.package_path }}
  76. cargo-cache-fallback-key: cargo-publish-semver
  77. - name: Install cargo-semver-checks
  78. uses: taiki-e/install-action@v2
  79. with:
  80. tool: cargo-semver-checks,cargo-release
  81. - name: Set Git Author (required for cargo-release)
  82. run: |
  83. git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"
  84. git config --global user.name "github-actions[bot]"
  85. - name: Set Version
  86. run: |
  87. if [ "${{ inputs.level }}" == "version" ]; then
  88. LEVEL=${{ inputs.version }}
  89. else
  90. LEVEL=${{ inputs.level }}
  91. fi
  92. cargo release $LEVEL --manifest-path "${{ inputs.package_path }}/Cargo.toml" --no-tag --no-publish --no-push --no-confirm --execute
  93. - name: Check semver
  94. run: pnpm rust:semver --manifest-path "${{ inputs.package_path }}/Cargo.toml"
  95. publish:
  96. name: Publish Rust Crate
  97. runs-on: ubuntu-latest
  98. needs: [test, semver]
  99. permissions:
  100. contents: write
  101. steps:
  102. - name: Git Checkout
  103. uses: actions/checkout@v4
  104. with:
  105. token: ${{ secrets.ANZA_TEAM_PAT }}
  106. fetch-depth: 0 # get the whole history for git-cliff
  107. - name: Setup Environment
  108. uses: ./.github/actions/setup
  109. with:
  110. cargo-cache-key: cargo-publish-${{ inputs.package_path }}
  111. cargo-cache-fallback-key: cargo-publish
  112. - name: Install cargo-release
  113. uses: taiki-e/install-action@v2
  114. with:
  115. tool: cargo-release
  116. - name: Ensure CARGO_REGISTRY_TOKEN variable is set
  117. env:
  118. CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
  119. if: ${{ env.CARGO_REGISTRY_TOKEN == '' }}
  120. run: |
  121. echo "The CARGO_REGISTRY_TOKEN secret variable is not set"
  122. echo "Go to \"Settings\" -> \"Secrets and variables\" -> \"Actions\" -> \"New repository secret\"."
  123. exit 1
  124. - name: Set Git Author
  125. run: |
  126. git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"
  127. git config --global user.name "github-actions[bot]"
  128. - name: Publish Crate
  129. id: publish
  130. env:
  131. CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
  132. run: |
  133. if [ "${{ inputs.level }}" == "version" ]; then
  134. LEVEL=${{ inputs.version }}
  135. else
  136. LEVEL=${{ inputs.level }}
  137. fi
  138. if [ "${{ inputs.dry_run }}" == "true" ]; then
  139. OPTIONS="--dry-run"
  140. else
  141. OPTIONS=""
  142. fi
  143. pnpm rust:publish "${{ inputs.package_path }}" $LEVEL $OPTIONS
  144. - name: Generate a changelog
  145. if: github.event.inputs.create_release == 'true'
  146. uses: orhun/git-cliff-action@v3
  147. with:
  148. config: "scripts/cliff.toml"
  149. args: |
  150. "${{ steps.publish.outputs.old_git_tag }}"..main
  151. --include-path "${{ inputs.package_path }}/**"
  152. --github-repo "${{ github.repository }}"
  153. env:
  154. OUTPUT: TEMP_CHANGELOG.md
  155. GITHUB_REPO: ${{ github.repository }}
  156. - name: Create GitHub release
  157. if: github.event.inputs.create_release == 'true' && github.event.inputs.dry_run != 'true'
  158. uses: ncipollo/release-action@v1
  159. with:
  160. tag: ${{ steps.publish.outputs.new_git_tag }}
  161. bodyFile: TEMP_CHANGELOG.md