|
| 1 | +name: Run tests and check version on crates.io |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + branches: |
| 6 | + - stable |
| 7 | + |
| 8 | + |
| 9 | +jobs: |
| 10 | + test: |
| 11 | + name: Run tests on PR into stable |
| 12 | + runs-on: ubuntu-latest |
| 13 | + |
| 14 | + steps: |
| 15 | + - name: Checkout repository |
| 16 | + uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 |
| 17 | + |
| 18 | + - name: Setup Rust toolchain |
| 19 | + uses: actions-rust-lang/setup-rust-toolchain@2fcdc490d667999e01ddbbf0f2823181beef6b39 |
| 20 | + with: |
| 21 | + components: rustfmt, clippy |
| 22 | + |
| 23 | + - name: Run RustFMT |
| 24 | + uses: actions-rust-lang/rustfmt@559aa3035a47390ba96088dffa783b5d26da9326 |
| 25 | + |
| 26 | + - name: Run Clippy |
| 27 | + run: cargo clippy --all-targets --all-features |
| 28 | + |
| 29 | + - name: Run tests |
| 30 | + run: cargo test --verbose --all-targets --all-features |
| 31 | + |
| 32 | + - name: Run documentation tests |
| 33 | + run: cargo test --verbose --doc --all-features |
| 34 | + |
| 35 | + |
| 36 | + check-version: |
| 37 | + name: Check version on crates.io |
| 38 | + runs-on: ubuntu-latest |
| 39 | + |
| 40 | + steps: |
| 41 | + - name: Checkout repository |
| 42 | + uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 |
| 43 | + |
| 44 | + - name: Get crate version |
| 45 | + id: get_crate_info |
| 46 | + run: | |
| 47 | + CRATE_VERSION=$(grep '^version = ' Cargo.toml | head -n 1 | cut -d '"' -f 2) |
| 48 | + echo "Crate error-stack-macros2" |
| 49 | + echo "Crate Version: $CRATE_VERSION" |
| 50 | + echo "crate_version=$CRATE_VERSION" >> "$GITHUB_OUTPUT" |
| 51 | +
|
| 52 | + - name: Check if version already exists on crates.io |
| 53 | + run: | |
| 54 | + CRATE_VERSION="${{ steps.get_crate_info.outputs.crate_version }}" |
| 55 | + API_URL="https://crates.io/api/v1/crates/error-stack-macros2/$CRATE_VERSION" |
| 56 | +
|
| 57 | + echo "Checking $API_URL" |
| 58 | +
|
| 59 | + if curl --head -f "$API_URL"; then |
| 60 | + echo "Error: Version $CRATE_VERSION already exists on crates.io!" |
| 61 | + echo "Please increment the version in Cargo.toml." |
| 62 | + exit 1 |
| 63 | + else |
| 64 | + echo "Version $CRATE_VERSION does not exist on crates.io. You're good to go!" |
| 65 | + fi |
0 commit comments