1
0

publish-rust.yml 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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. dry_run:
  25. description: Dry run
  26. required: true
  27. default: true
  28. type: boolean
  29. create_release:
  30. description: Create a GitHub release
  31. required: true
  32. type: boolean
  33. default: true
  34. jobs:
  35. test:
  36. name: Test Rust Crate
  37. runs-on: ubuntu-latest
  38. steps:
  39. - name: Git Checkout
  40. uses: actions/checkout@v4
  41. - name: Setup Environment
  42. uses: ./.github/actions/setup
  43. with:
  44. clippy: true
  45. rustfmt: true
  46. solana: true
  47. cargo-cache-key: cargo-test-publish-${{ inputs.package_path }}
  48. cargo-cache-fallback-key: cargo-test-publish
  49. - name: Install cargo-audit
  50. uses: taiki-e/install-action@v2
  51. with:
  52. tool: cargo-semver-checks
  53. - name: Format
  54. run: pnpm zx ./scripts/rust/format.mjs "${{ inputs.package_path }}"
  55. - name: Lint
  56. run: pnpm zx ./scripts/rust/lint.mjs "${{ inputs.package_path }}"
  57. - name: Build programs
  58. run: pnpm programs:build
  59. - name: Test
  60. run: pnpm zx ./scripts/rust/test.mjs "${{ inputs.package_path }}"
  61. - name: Check semver
  62. run: pnpm rust:semver ${{ inputs.package_path }} --release-type ${{ inputs.level }}
  63. publish:
  64. name: Publish Rust Crate
  65. runs-on: ubuntu-latest
  66. needs: test
  67. permissions:
  68. contents: write
  69. steps:
  70. - name: Git Checkout
  71. uses: actions/checkout@v4
  72. with:
  73. token: ${{ secrets.ANZA_TEAM_PAT }}
  74. fetch-depth: 0 # get the whole history for git-cliff
  75. - name: Setup Environment
  76. uses: ./.github/actions/setup
  77. with:
  78. cargo-cache-key: cargo-publish-${{ inputs.package_path }}
  79. cargo-cache-fallback-key: cargo-publish
  80. - name: Install Cargo Release
  81. run: which cargo-release || cargo install cargo-release
  82. - name: Ensure CARGO_REGISTRY_TOKEN variable is set
  83. env:
  84. CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
  85. if: ${{ env.CARGO_REGISTRY_TOKEN == '' }}
  86. run: |
  87. echo "The CARGO_REGISTRY_TOKEN secret variable is not set"
  88. echo "Go to \"Settings\" -> \"Secrets and variables\" -> \"Actions\" -> \"New repository secret\"."
  89. exit 1
  90. - name: Set Git Author
  91. run: |
  92. git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"
  93. git config --global user.name "github-actions[bot]"
  94. - name: Publish Crate
  95. id: publish
  96. env:
  97. CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
  98. run: |
  99. if [ "${{ inputs.dry_run }}" == "true" ]; then
  100. OPTIONS="--dry-run"
  101. else
  102. OPTIONS=""
  103. fi
  104. pnpm rust:publish "${{ inputs.package_path }}" "${{ inputs.level }}" $OPTIONS
  105. - name: Generate a changelog
  106. if: github.event.inputs.create_release == 'true'
  107. uses: orhun/git-cliff-action@v3
  108. with:
  109. config: "scripts/cliff.toml"
  110. args: |
  111. "${{ steps.publish.outputs.old_git_tag }}"..main
  112. --include-path "${{ inputs.package_path }}/**"
  113. --github-repo "${{ github.repository }}"
  114. env:
  115. OUTPUT: TEMP_CHANGELOG.md
  116. GITHUB_REPO: ${{ github.repository }}
  117. - name: Create GitHub release
  118. if: github.event.inputs.create_release == 'true' && github.event.inputs.dry_run != 'true'
  119. uses: ncipollo/release-action@v1
  120. with:
  121. tag: ${{ steps.publish.outputs.new_git_tag }}
  122. bodyFile: TEMP_CHANGELOG.md