publish-rust.yml 5.3 KB

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