Publish Rust Crate #4
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Publish Rust Crate | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| package_path: | |
| description: Path to directory with package to release | |
| required: true | |
| default: 'clients/rust' | |
| type: choice | |
| options: | |
| - clients/rust | |
| - interface | |
| - program | |
| level: | |
| description: Level | |
| required: true | |
| default: patch | |
| type: choice | |
| options: | |
| - patch | |
| - minor | |
| - major | |
| - rc | |
| - beta | |
| - alpha | |
| - release | |
| - version | |
| version: | |
| description: Version | |
| required: false | |
| type: string | |
| dry_run: | |
| description: Dry run | |
| required: true | |
| default: true | |
| type: boolean | |
| create_release: | |
| description: Create a GitHub release | |
| required: true | |
| type: boolean | |
| default: true | |
| jobs: | |
| test_rust: | |
| name: Test Rust Crate | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Git Checkout | |
| uses: actions/checkout@v4 | |
| - name: Setup Environment | |
| uses: ./.github/actions/setup | |
| with: | |
| cargo-cache-key: cargo-rust-${{ inputs.package_path }} | |
| toolchain: format, lint, test | |
| solana: true | |
| - name: Convert package_path to required variables | |
| run: | | |
| PACKAGE_PATH="${{ inputs.package_path }}" | |
| RECIPE_SUFFIX="${PACKAGE_PATH//\//-}" | |
| TAG_PREFIX="$(basename "$PACKAGE_PATH")" | |
| echo "RECIPE_SUFFIX=$RECIPE_SUFFIX" >> $GITHUB_ENV | |
| echo "TAG_PREFIX=$TAG_PREFIX" >> $GITHUB_ENV | |
| - name: Format | |
| run: make format-${{ env.RECIPE_SUFFIX }} | |
| - name: Lint | |
| run: make clippy-${{ env.RECIPE_SUFFIX }} | |
| - name: Build Program | |
| run: make build-program | |
| - name: Test | |
| run: make test-${{ env.RECIPE_SUFFIX }} | |
| publish_rust: | |
| name: Publish Rust Crate | |
| runs-on: ubuntu-latest | |
| needs: test_rust | |
| permissions: | |
| contents: write | |
| steps: | |
| - name: Git Checkout | |
| uses: actions/checkout@v4 | |
| - name: Setup Environment | |
| uses: ./.github/actions/setup | |
| with: | |
| cargo-cache-key: cargo-publish-rust-${{ inputs.package_path }} | |
| cargo-cache-fallback-key: cargo-rust-${{ inputs.package_path }} | |
| clippy: true | |
| rustfmt: true | |
| - name: Install Cargo Release | |
| run: which cargo-release || cargo install cargo-release --locked --version 0.25.17 | |
| - name: Ensure CARGO_REGISTRY_TOKEN variable is set | |
| env: | |
| token: ${{ secrets.CARGO_REGISTRY_TOKEN }} | |
| if: ${{ env.token == '' }} | |
| run: | | |
| echo "The CARGO_REGISTRY_TOKEN secret variable is not set" | |
| echo "Go to \"Settings\" -> \"Secrets and variables\" -> \"Actions\" -> \"New repository secret\"." | |
| exit 1 | |
| - name: Set Git Author | |
| run: | | |
| git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com" | |
| git config --global user.name "github-actions[bot]" | |
| - name: Publish Rust Crate | |
| id: publish | |
| env: | |
| CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }} | |
| run: | | |
| if [ "${{ inputs.level }}" == "version" ]; then | |
| LEVEL=${{ inputs.version }} | |
| else | |
| LEVEL=${{ inputs.level }} | |
| fi | |
| if [ "${{ inputs.dry_run }}" == "true" ]; then | |
| OPTIONS="--dry-run" | |
| else | |
| OPTIONS="" | |
| fi | |
| ./scripts/publish-rust.sh ${{ inputs.package_path }} $LEVEL $OPTIONS | |
| - name: Create GitHub release | |
| if: inputs.create_release == 'true' && inputs.dry_run != 'true' | |
| uses: ncipollo/release-action@v1 | |
| with: | |
| tag: ${{ env.TAG_PREFIX }}@v${{ steps.publish.outputs.new_version }} |