|
| 1 | +name: Release |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + tags: |
| 6 | + - '[0-9]+.[0-9]+.[0-9]+' |
| 7 | + - '[0-9]+.[0-9]+.[0-9]+-*' |
| 8 | + workflow_dispatch: |
| 9 | + inputs: |
| 10 | + version: |
| 11 | + description: 'Version to publish (e.g., 0.2.0)' |
| 12 | + required: true |
| 13 | + type: string |
| 14 | + dry_run: |
| 15 | + description: 'Perform dry run only (do not publish)' |
| 16 | + required: false |
| 17 | + type: boolean |
| 18 | + default: false |
| 19 | + |
| 20 | +env: |
| 21 | + CARGO_TERM_COLOR: always |
| 22 | + RUST_BACKTRACE: 1 |
| 23 | + |
| 24 | +jobs: |
| 25 | + # Pre-release validation |
| 26 | + validate: |
| 27 | + name: Pre-release Validation |
| 28 | + runs-on: ubuntu-latest |
| 29 | + steps: |
| 30 | + - name: Checkout code |
| 31 | + uses: actions/checkout@v4 |
| 32 | + |
| 33 | + - name: Install Rust |
| 34 | + uses: dtolnay/rust-toolchain@stable |
| 35 | + with: |
| 36 | + components: rustfmt, clippy |
| 37 | + |
| 38 | + - name: Cache cargo registry |
| 39 | + uses: actions/cache@v4 |
| 40 | + with: |
| 41 | + path: ~/.cargo/registry/index |
| 42 | + key: ${{ runner.os }}-cargo-registry-${{ hashFiles('**/Cargo.lock') }} |
| 43 | + restore-keys: ${{ runner.os }}-cargo-registry- |
| 44 | + |
| 45 | + - name: Cache cargo build |
| 46 | + uses: actions/cache@v4 |
| 47 | + with: |
| 48 | + path: target |
| 49 | + key: ${{ runner.os }}-cargo-release-${{ hashFiles('**/Cargo.lock') }} |
| 50 | + restore-keys: ${{ runner.os }}-cargo-release- |
| 51 | + |
| 52 | + - name: Run tests |
| 53 | + run: cargo test --all-features |
| 54 | + |
| 55 | + - name: Run clippy |
| 56 | + run: cargo clippy --all-targets --all-features -- -D warnings |
| 57 | + |
| 58 | + - name: Check formatting |
| 59 | + run: cargo fmt --all -- --check |
| 60 | + |
| 61 | + - name: Build documentation |
| 62 | + run: cargo doc --no-deps --all-features |
| 63 | + env: |
| 64 | + RUSTDOCFLAGS: -D warnings |
| 65 | + |
| 66 | + - name: Verify package can be built |
| 67 | + run: cargo package --allow-dirty |
| 68 | + |
| 69 | + - name: Verify version matches |
| 70 | + if: github.event_name == 'push' |
| 71 | + run: | |
| 72 | + CARGO_VERSION=$(cargo metadata --format-version 1 --no-deps | jq -r '.packages[0].version') |
| 73 | + RELEASE_TAG="${GITHUB_REF#refs/tags/}" |
| 74 | +
|
| 75 | + echo "Cargo.toml version: $CARGO_VERSION" |
| 76 | + echo "Git tag: $RELEASE_TAG" |
| 77 | +
|
| 78 | + if [ "$CARGO_VERSION" != "$RELEASE_TAG" ]; then |
| 79 | + echo "β Error: Version mismatch!" |
| 80 | + echo "Cargo.toml version ($CARGO_VERSION) does not match git tag ($RELEASE_TAG)" |
| 81 | + echo "" |
| 82 | + echo "To fix this:" |
| 83 | + echo "1. Update version in Cargo.toml to $RELEASE_TAG" |
| 84 | + echo "2. Commit the change" |
| 85 | + echo "3. Re-tag with: git tag -f $RELEASE_TAG" |
| 86 | + exit 1 |
| 87 | + fi |
| 88 | +
|
| 89 | + echo "β
Version check passed" |
| 90 | +
|
| 91 | + # Publish to crates.io |
| 92 | + publish: |
| 93 | + name: Publish to crates.io |
| 94 | + needs: validate |
| 95 | + runs-on: ubuntu-latest |
| 96 | + if: | |
| 97 | + github.event_name == 'push' || |
| 98 | + (github.event_name == 'workflow_dispatch' && !inputs.dry_run) |
| 99 | + steps: |
| 100 | + - name: Checkout code |
| 101 | + uses: actions/checkout@v4 |
| 102 | + |
| 103 | + - name: Install Rust |
| 104 | + uses: dtolnay/rust-toolchain@stable |
| 105 | + |
| 106 | + - name: Cache cargo registry |
| 107 | + uses: actions/cache@v4 |
| 108 | + with: |
| 109 | + path: ~/.cargo/registry/index |
| 110 | + key: ${{ runner.os }}-cargo-registry-${{ hashFiles('**/Cargo.lock') }} |
| 111 | + restore-keys: ${{ runner.os }}-cargo-registry- |
| 112 | + |
| 113 | + - name: Publish to crates.io |
| 114 | + run: cargo publish --token ${{ secrets.CARGO_REGISTRY_TOKEN }} |
| 115 | + env: |
| 116 | + CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }} |
| 117 | + |
| 118 | + - name: Create publish summary |
| 119 | + run: | |
| 120 | + VERSION="${GITHUB_REF#refs/tags/}" |
| 121 | +
|
| 122 | + echo "## π Published to crates.io" >> $GITHUB_STEP_SUMMARY |
| 123 | + echo "" >> $GITHUB_STEP_SUMMARY |
| 124 | + echo "**Version ${VERSION}** has been successfully published!" >> $GITHUB_STEP_SUMMARY |
| 125 | + echo "" >> $GITHUB_STEP_SUMMARY |
| 126 | + echo "### Installation" >> $GITHUB_STEP_SUMMARY |
| 127 | + echo "\`\`\`toml" >> $GITHUB_STEP_SUMMARY |
| 128 | + echo "[dependencies]" >> $GITHUB_STEP_SUMMARY |
| 129 | + echo "github_app = \"${VERSION}\"" >> $GITHUB_STEP_SUMMARY |
| 130 | + echo "\`\`\`" >> $GITHUB_STEP_SUMMARY |
| 131 | + echo "" >> $GITHUB_STEP_SUMMARY |
| 132 | + echo "### Links" >> $GITHUB_STEP_SUMMARY |
| 133 | + echo "- π¦ [crates.io/crates/github_app](https://crates.io/crates/github_app)" >> $GITHUB_STEP_SUMMARY |
| 134 | + echo "- π [docs.rs/github_app/${VERSION}](https://docs.rs/github_app/${VERSION})" >> $GITHUB_STEP_SUMMARY |
| 135 | +
|
| 136 | + # Dry run for testing |
| 137 | + dry-run: |
| 138 | + name: Publish Dry Run |
| 139 | + needs: validate |
| 140 | + runs-on: ubuntu-latest |
| 141 | + if: github.event_name == 'workflow_dispatch' && inputs.dry_run |
| 142 | + steps: |
| 143 | + - name: Checkout code |
| 144 | + uses: actions/checkout@v4 |
| 145 | + |
| 146 | + - name: Install Rust |
| 147 | + uses: dtolnay/rust-toolchain@stable |
| 148 | + |
| 149 | + - name: Cache cargo registry |
| 150 | + uses: actions/cache@v4 |
| 151 | + with: |
| 152 | + path: ~/.cargo/registry/index |
| 153 | + key: ${{ runner.os }}-cargo-registry-${{ hashFiles('**/Cargo.lock') }} |
| 154 | + restore-keys: ${{ runner.os }}-cargo-registry- |
| 155 | + |
| 156 | + - name: Run dry-run publish |
| 157 | + run: cargo publish --dry-run --allow-dirty |
| 158 | + |
| 159 | + - name: Display package contents |
| 160 | + run: | |
| 161 | + echo "## π¦ Package Contents" >> $GITHUB_STEP_SUMMARY |
| 162 | + echo "" >> $GITHUB_STEP_SUMMARY |
| 163 | + echo "\`\`\`" >> $GITHUB_STEP_SUMMARY |
| 164 | + cargo package --list --allow-dirty >> $GITHUB_STEP_SUMMARY |
| 165 | + echo "\`\`\`" >> $GITHUB_STEP_SUMMARY |
| 166 | +
|
| 167 | + # Update documentation |
| 168 | + update-docs: |
| 169 | + name: Update Documentation |
| 170 | + needs: publish |
| 171 | + runs-on: ubuntu-latest |
| 172 | + if: github.event_name == 'push' |
| 173 | + steps: |
| 174 | + - name: Documentation summary |
| 175 | + run: | |
| 176 | + VERSION="${GITHUB_REF#refs/tags/}" |
| 177 | +
|
| 178 | + echo "## π Documentation Updated" >> $GITHUB_STEP_SUMMARY |
| 179 | + echo "" >> $GITHUB_STEP_SUMMARY |
| 180 | + echo "Documentation for version ${VERSION} is being built on docs.rs." >> $GITHUB_STEP_SUMMARY |
| 181 | + echo "" >> $GITHUB_STEP_SUMMARY |
| 182 | + echo "It should be available at https://docs.rs/github_app/${VERSION} within a few minutes." >> $GITHUB_STEP_SUMMARY |
| 183 | +
|
| 184 | + # Post-release checks |
| 185 | + verify-published: |
| 186 | + name: Verify Published Package |
| 187 | + needs: publish |
| 188 | + runs-on: ubuntu-latest |
| 189 | + if: github.event_name == 'push' |
| 190 | + steps: |
| 191 | + - name: Wait for crates.io to sync |
| 192 | + run: sleep 60 |
| 193 | + |
| 194 | + - name: Install Rust |
| 195 | + uses: dtolnay/rust-toolchain@stable |
| 196 | + |
| 197 | + - name: Verify package is available |
| 198 | + run: | |
| 199 | + VERSION="${GITHUB_REF#refs/tags/}" |
| 200 | +
|
| 201 | + echo "Checking if github_app ${VERSION} is available on crates.io..." |
| 202 | +
|
| 203 | + # Try to fetch the package info |
| 204 | + if cargo search github_app --limit 10 | grep -q "github_app.*${VERSION}"; then |
| 205 | + echo "β
Package successfully published and indexed on crates.io!" |
| 206 | + else |
| 207 | + echo "β οΈ Package may still be indexing. Please check manually." |
| 208 | + fi |
| 209 | +
|
| 210 | + - name: Test installation |
| 211 | + run: | |
| 212 | + VERSION="${GITHUB_REF#refs/tags/}" |
| 213 | +
|
| 214 | + # Create a test project and try to install the new version |
| 215 | + cargo init --lib test-install |
| 216 | + cd test-install |
| 217 | + cargo add github_app@${VERSION} || echo "Package may still be syncing" |
| 218 | +
|
| 219 | + # Announce release |
| 220 | + announce: |
| 221 | + name: Announce Release |
| 222 | + needs: [publish, verify-published] |
| 223 | + runs-on: ubuntu-latest |
| 224 | + if: github.event_name == 'push' && success() |
| 225 | + steps: |
| 226 | + - name: Create release summary |
| 227 | + run: | |
| 228 | + VERSION="${GITHUB_REF#refs/tags/}" |
| 229 | +
|
| 230 | + echo "## π Release ${VERSION} Complete!" >> $GITHUB_STEP_SUMMARY |
| 231 | + echo "" >> $GITHUB_STEP_SUMMARY |
| 232 | + echo "### β
Published Successfully" >> $GITHUB_STEP_SUMMARY |
| 233 | + echo "- π¦ [crates.io/crates/github_app](https://crates.io/crates/github_app)" >> $GITHUB_STEP_SUMMARY |
| 234 | + echo "- π [docs.rs/github_app/${VERSION}](https://docs.rs/github_app/${VERSION})" >> $GITHUB_STEP_SUMMARY |
| 235 | + echo "" >> $GITHUB_STEP_SUMMARY |
| 236 | + echo "### Installation" >> $GITHUB_STEP_SUMMARY |
| 237 | + echo "\`\`\`toml" >> $GITHUB_STEP_SUMMARY |
| 238 | + echo "[dependencies]" >> $GITHUB_STEP_SUMMARY |
| 239 | + echo "github_app = \"${VERSION}\"" >> $GITHUB_STEP_SUMMARY |
| 240 | + echo "\`\`\`" >> $GITHUB_STEP_SUMMARY |
| 241 | + echo "" >> $GITHUB_STEP_SUMMARY |
| 242 | + echo "### What's Next?" >> $GITHUB_STEP_SUMMARY |
| 243 | + echo "- Documentation will be available on docs.rs within a few minutes" >> $GITHUB_STEP_SUMMARY |
| 244 | + echo "- All CI checks passed β
" >> $GITHUB_STEP_SUMMARY |
| 245 | + echo "" >> $GITHUB_STEP_SUMMARY |
| 246 | + echo "Thank you for using github_app! π" >> $GITHUB_STEP_SUMMARY |
0 commit comments