|
| 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 | + 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 | + |
| 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 | + |
| 52 | + - name: Setup Environment |
| 53 | + uses: ./.github/actions/setup |
| 54 | + with: |
| 55 | + clippy: true |
| 56 | + rustfmt: true |
| 57 | + solana: true |
| 58 | + cargo-cache-key: cargo-test-publish-${{ inputs.package_path }} |
| 59 | + cargo-cache-fallback-key: cargo-test-publish |
| 60 | + |
| 61 | + - name: Format |
| 62 | + run: pnpm zx ./scripts/rust/format.mjs "${{ inputs.package_path }}" |
| 63 | + |
| 64 | + - name: Lint |
| 65 | + run: pnpm zx ./scripts/rust/lint.mjs "${{ inputs.package_path }}" |
| 66 | + |
| 67 | + - name: Build |
| 68 | + run: pnpm programs:build |
| 69 | + |
| 70 | + - name: Test |
| 71 | + run: pnpm zx ./scripts/rust/test.mjs "${{ inputs.package_path }}" |
| 72 | + |
| 73 | + semver: |
| 74 | + name: Check Semver |
| 75 | + runs-on: ubuntu-latest |
| 76 | + steps: |
| 77 | + - name: Git checkout |
| 78 | + uses: actions/checkout@v4 |
| 79 | + |
| 80 | + - name: Setup Environment |
| 81 | + uses: ./.github/actions/setup |
| 82 | + with: |
| 83 | + cargo-cache-key: cargo-publish-semver-${{ inputs.package_path }} |
| 84 | + cargo-cache-fallback-key: cargo-publish-semver |
| 85 | + |
| 86 | + - name: Install cargo-semver-checks |
| 87 | + uses: taiki-e/install-action@v2 |
| 88 | + with: |
| 89 | + |
| 90 | + |
| 91 | + - name: Set Git Author (required for cargo-release) |
| 92 | + run: | |
| 93 | + git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com" |
| 94 | + git config --global user.name "github-actions[bot]" |
| 95 | +
|
| 96 | + - name: Set Version |
| 97 | + run: | |
| 98 | + if [ "${{ inputs.level }}" == "version" ]; then |
| 99 | + LEVEL=${{ inputs.version }} |
| 100 | + else |
| 101 | + LEVEL=${{ inputs.level }} |
| 102 | + fi |
| 103 | + cargo release $LEVEL --manifest-path "${{ inputs.package_path }}/Cargo.toml" --no-tag --no-publish --no-push --no-confirm --execute |
| 104 | +
|
| 105 | + - name: Check semver |
| 106 | + run: pnpm rust:semver --manifest-path "${{ inputs.package_path }}/Cargo.toml" |
| 107 | + |
| 108 | + publish: |
| 109 | + name: Publish Rust Crate |
| 110 | + runs-on: ubuntu-latest |
| 111 | + needs: [test, semver] |
| 112 | + permissions: |
| 113 | + contents: write |
| 114 | + steps: |
| 115 | + - name: Git Checkout |
| 116 | + uses: actions/checkout@v4 |
| 117 | + with: |
| 118 | + token: ${{ secrets.ANZA_TEAM_PAT }} |
| 119 | + fetch-depth: 0 # get the whole history for git-cliff |
| 120 | + |
| 121 | + - name: Setup Environment |
| 122 | + uses: ./.github/actions/setup |
| 123 | + with: |
| 124 | + cli: true |
| 125 | + cargo-cache-key: cargo-publish-${{ inputs.package_path }} |
| 126 | + cargo-cache-fallback-key: cargo-publish |
| 127 | + |
| 128 | + - name: Install cargo-release |
| 129 | + uses: taiki-e/install-action@v2 |
| 130 | + with: |
| 131 | + |
| 132 | + |
| 133 | + - name: Ensure CARGO_REGISTRY_TOKEN variable is set |
| 134 | + env: |
| 135 | + CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }} |
| 136 | + if: ${{ env.CARGO_REGISTRY_TOKEN == '' }} |
| 137 | + run: | |
| 138 | + echo "The CARGO_REGISTRY_TOKEN secret variable is not set" |
| 139 | + echo "Go to \"Settings\" -> \"Secrets and variables\" -> \"Actions\" -> \"New repository secret\"." |
| 140 | + exit 1 |
| 141 | +
|
| 142 | + - name: Set Git Author |
| 143 | + run: | |
| 144 | + git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com" |
| 145 | + git config --global user.name "github-actions[bot]" |
| 146 | +
|
| 147 | + - name: Publish Crate |
| 148 | + id: publish |
| 149 | + env: |
| 150 | + CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }} |
| 151 | + run: | |
| 152 | + if [ "${{ inputs.level }}" == "version" ]; then |
| 153 | + LEVEL=${{ inputs.version }} |
| 154 | + else |
| 155 | + LEVEL=${{ inputs.level }} |
| 156 | + fi |
| 157 | +
|
| 158 | + if [ "${{ inputs.dry_run }}" == "true" ]; then |
| 159 | + OPTIONS="--dry-run" |
| 160 | + else |
| 161 | + OPTIONS="" |
| 162 | + fi |
| 163 | +
|
| 164 | + pnpm rust:publish "${{ inputs.package_path }}" $LEVEL $OPTIONS |
| 165 | +
|
| 166 | + - name: Generate a changelog |
| 167 | + if: github.event.inputs.create_release == 'true' |
| 168 | + uses: orhun/git-cliff-action@v4 |
| 169 | + with: |
| 170 | + config: "scripts/cliff.toml" |
| 171 | + args: ${{ steps.publish.outputs.old_git_tag }}..HEAD --include-path "${{ inputs.package_path }}/**" --github-repo ${{ github.repository }} |
| 172 | + env: |
| 173 | + OUTPUT: TEMP_CHANGELOG.md |
| 174 | + GITHUB_REPO: ${{ github.repository }} |
| 175 | + |
| 176 | + - name: Create GitHub release |
| 177 | + if: github.event.inputs.create_release == 'true' && github.event.inputs.dry_run != 'true' |
| 178 | + uses: ncipollo/release-action@v1 |
| 179 | + with: |
| 180 | + tag: ${{ steps.publish.outputs.new_git_tag }} |
| 181 | + bodyFile: TEMP_CHANGELOG.md |
0 commit comments