publish-rust.yml 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  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 Version
  82. run: |
  83. if [ "${{ inputs.level }}" == "version" ]; then
  84. LEVEL=${{ inputs.version }}
  85. else
  86. LEVEL=${{ inputs.level }}
  87. fi
  88. cargo release $LEVEL --manifest-path " ${{ inputs.package_path }}/Cargo.toml" --no-tag --no-publish --no-push --no-confirm --execute
  89. - name: Check semver
  90. run: pnpm rust:semver --manifest-path "${{ inputs.package_path }}/Cargo.toml"
  91. publish:
  92. name: Publish Rust Crate
  93. runs-on: ubuntu-latest
  94. needs: [test, semver]
  95. permissions:
  96. contents: write
  97. steps:
  98. - name: Git Checkout
  99. uses: actions/checkout@v4
  100. with:
  101. token: ${{ secrets.ANZA_TEAM_PAT }}
  102. fetch-depth: 0 # get the whole history for git-cliff
  103. - name: Setup Environment
  104. uses: ./.github/actions/setup
  105. with:
  106. cargo-cache-key: cargo-publish-${{ inputs.package_path }}
  107. cargo-cache-fallback-key: cargo-publish
  108. - name: Install cargo-release
  109. uses: taiki-e/install-action@v2
  110. with:
  111. tool: cargo-release
  112. - name: Ensure CARGO_REGISTRY_TOKEN variable is set
  113. env:
  114. CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
  115. if: ${{ env.CARGO_REGISTRY_TOKEN == '' }}
  116. run: |
  117. echo "The CARGO_REGISTRY_TOKEN secret variable is not set"
  118. echo "Go to \"Settings\" -> \"Secrets and variables\" -> \"Actions\" -> \"New repository secret\"."
  119. exit 1
  120. - name: Set Git Author
  121. run: |
  122. git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"
  123. git config --global user.name "github-actions[bot]"
  124. - name: Publish Crate
  125. id: publish
  126. env:
  127. CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
  128. run: |
  129. if [ "${{ inputs.level }}" == "version" ]; then
  130. LEVEL=${{ inputs.version }}
  131. else
  132. LEVEL=${{ inputs.level }}
  133. fi
  134. if [ "${{ inputs.dry_run }}" == "true" ]; then
  135. OPTIONS="--dry-run"
  136. else
  137. OPTIONS=""
  138. fi
  139. pnpm rust:publish "${{ inputs.package_path }}" $LEVEL $OPTIONS
  140. - name: Generate a changelog
  141. if: github.event.inputs.create_release == 'true'
  142. uses: orhun/git-cliff-action@v3
  143. with:
  144. config: "scripts/cliff.toml"
  145. args: |
  146. "${{ steps.publish.outputs.old_git_tag }}"..main
  147. --include-path "${{ inputs.package_path }}/**"
  148. --github-repo "${{ github.repository }}"
  149. env:
  150. OUTPUT: TEMP_CHANGELOG.md
  151. GITHUB_REPO: ${{ github.repository }}
  152. - name: Create GitHub release
  153. if: github.event.inputs.create_release == 'true' && github.event.inputs.dry_run != 'true'
  154. uses: ncipollo/release-action@v1
  155. with:
  156. tag: ${{ steps.publish.outputs.new_git_tag }}
  157. bodyFile: TEMP_CHANGELOG.md