|
| 1 | +name: Publish 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 | + type: string |
| 10 | + level: |
| 11 | + description: Level |
| 12 | + required: true |
| 13 | + default: patch |
| 14 | + type: choice |
| 15 | + options: |
| 16 | + - patch |
| 17 | + - minor |
| 18 | + - major |
| 19 | + - version |
| 20 | + version: |
| 21 | + description: Version (used with level "version") |
| 22 | + required: false |
| 23 | + type: string |
| 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 | + |
| 35 | +jobs: |
| 36 | + sanity: |
| 37 | + name: Sanity checks |
| 38 | + runs-on: ubuntu-latest |
| 39 | + steps: |
| 40 | + - name: Git Checkout |
| 41 | + uses: actions/checkout@v4 |
| 42 | + with: |
| 43 | + fetch-depth: 0 # full history to check for whitespace / conflict markers |
| 44 | + |
| 45 | + - name: Setup Environment |
| 46 | + uses: ./.github/actions/setup |
| 47 | + with: |
| 48 | + stable-toolchain: true |
| 49 | + cargo-cache-key: cargo-stable-sanity |
| 50 | + cargo-cache-fallback-key: cargo-stable |
| 51 | + |
| 52 | + - name: Check repo is in porcelain state |
| 53 | + run: ./scripts/check-porcelain.sh |
| 54 | + |
| 55 | + - name: Check code nits |
| 56 | + run: ./scripts/check-nits.sh |
| 57 | + |
| 58 | + format: |
| 59 | + name: Format |
| 60 | + runs-on: ubuntu-latest |
| 61 | + needs: [sanity] |
| 62 | + steps: |
| 63 | + - name: Git Checkout |
| 64 | + uses: actions/checkout@v4 |
| 65 | + |
| 66 | + - name: Setup Environment |
| 67 | + uses: ./.github/actions/setup |
| 68 | + with: |
| 69 | + rustfmt: true |
| 70 | + cargo-cache-key: cargo-nightly-fmt |
| 71 | + cargo-cache-fallback-key: cargo-nightly |
| 72 | + |
| 73 | + - name: Check formatting |
| 74 | + run: ./scripts/check-fmt.sh |
| 75 | + |
| 76 | + clippy: |
| 77 | + name: Clippy |
| 78 | + needs: [sanity] |
| 79 | + runs-on: ubuntu-latest |
| 80 | + steps: |
| 81 | + - name: Git Checkout |
| 82 | + uses: actions/checkout@v4 |
| 83 | + |
| 84 | + - name: Setup Environment |
| 85 | + uses: ./.github/actions/setup |
| 86 | + with: |
| 87 | + clippy: true |
| 88 | + cargo-cache-key: cargo-nightly-clippy |
| 89 | + cargo-cache-fallback-key: cargo-nightly |
| 90 | + |
| 91 | + - name: Run clippy |
| 92 | + run: ./scripts/check-clippy.sh |
| 93 | + |
| 94 | + publish-crate: |
| 95 | + name: Publish crate |
| 96 | + runs-on: ubuntu-latest |
| 97 | + needs: [format, clippy] |
| 98 | + permissions: |
| 99 | + contents: write |
| 100 | + steps: |
| 101 | + - name: Git Checkout |
| 102 | + uses: actions/checkout@v4 |
| 103 | + with: |
| 104 | + token: ${{ secrets.ANZA_TEAM_PAT }} |
| 105 | + fetch-depth: 0 # get the whole history for git-cliff |
| 106 | + |
| 107 | + - name: Setup Environment |
| 108 | + uses: ./.github/actions/setup |
| 109 | + with: |
| 110 | + stable-toolchain: true |
| 111 | + cargo-cache-key: cargo-stable-publish |
| 112 | + cargo-cache-fallback-key: cargo-stable |
| 113 | + |
| 114 | + - name: Install cargo-release |
| 115 | + uses: taiki-e/cache-cargo-install-action@v2 |
| 116 | + with: |
| 117 | + tool: cargo-release |
| 118 | + |
| 119 | + - name: Ensure CARGO_REGISTRY_TOKEN variable is set |
| 120 | + env: |
| 121 | + token: ${{ secrets.CARGO_REGISTRY_TOKEN }} |
| 122 | + if: ${{ env.token == '' }} |
| 123 | + run: | |
| 124 | + echo "The CARGO_REGISTRY_TOKEN secret variable is not set" |
| 125 | + echo "Go to \"Settings\" -> \"Secrets and variables\" -> \"Actions\" -> \"New repository secret\"." |
| 126 | + exit 1 |
| 127 | +
|
| 128 | + - name: Set Git Author |
| 129 | + run: | |
| 130 | + git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com" |
| 131 | + git config --global user.name "github-actions[bot]" |
| 132 | +
|
| 133 | + - name: Publish Crate |
| 134 | + id: publish |
| 135 | + env: |
| 136 | + CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }} |
| 137 | + run: | |
| 138 | + if [ "${{ inputs.level }}" == "version" ]; then |
| 139 | + LEVEL=${{ inputs.version }} |
| 140 | + else |
| 141 | + LEVEL=${{ inputs.level }} |
| 142 | + fi |
| 143 | +
|
| 144 | + if [ "${{ inputs.dry_run }}" == "true" ]; then |
| 145 | + OPTIONS="--dry-run" |
| 146 | + else |
| 147 | + OPTIONS="" |
| 148 | + fi |
| 149 | +
|
| 150 | + ./scripts/publish-rust.sh "${{ inputs.package_path }}" $LEVEL $OPTIONS |
| 151 | +
|
| 152 | + - name: Generate a changelog |
| 153 | + if: github.event.inputs.create_release == 'true' |
| 154 | + uses: orhun/git-cliff-action@v3 |
| 155 | + with: |
| 156 | + config: "scripts/cliff.toml" |
| 157 | + args: | |
| 158 | + "${{ steps.publish.outputs.old_git_tag }}"..master |
| 159 | + --include-path "${{ inputs.package_path }}/**" |
| 160 | + --github-repo "${{ github.repository }}" |
| 161 | + env: |
| 162 | + OUTPUT: TEMP_CHANGELOG.md |
| 163 | + GITHUB_REPO: ${{ github.repository }} |
| 164 | + |
| 165 | + - name: Create GitHub release |
| 166 | + if: github.event.inputs.create_release == 'true' && github.event.inputs.dry_run != 'true' |
| 167 | + uses: ncipollo/release-action@v1 |
| 168 | + with: |
| 169 | + tag: ${{ steps.publish.outputs.new_git_tag }} |
| 170 | + bodyFile: TEMP_CHANGELOG.md |
0 commit comments