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