|
| 1 | +name: Publish to crates.io |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + tags: |
| 6 | + - 'v*' |
| 7 | + workflow_dispatch: |
| 8 | + inputs: |
| 9 | + dry_run: |
| 10 | + description: 'Dry run (do not publish)' |
| 11 | + required: false |
| 12 | + default: 'false' |
| 13 | + |
| 14 | +env: |
| 15 | + CARGO_TERM_COLOR: always |
| 16 | + |
| 17 | +jobs: |
| 18 | + publish: |
| 19 | + name: Publish |
| 20 | + runs-on: ubuntu-latest |
| 21 | + steps: |
| 22 | + - uses: actions/checkout@v4 |
| 23 | + |
| 24 | + - name: Install Rust |
| 25 | + uses: dtolnay/rust-toolchain@stable |
| 26 | + |
| 27 | + - name: Cache cargo registry |
| 28 | + uses: actions/cache@v4 |
| 29 | + with: |
| 30 | + path: | |
| 31 | + ~/.cargo/registry |
| 32 | + ~/.cargo/git |
| 33 | + key: ${{ runner.os }}-cargo-publish-${{ hashFiles('**/Cargo.lock') }} |
| 34 | + restore-keys: | |
| 35 | + ${{ runner.os }}-cargo-publish- |
| 36 | +
|
| 37 | + - name: Verify version matches tag |
| 38 | + if: startsWith(github.ref, 'refs/tags/v') |
| 39 | + run: | |
| 40 | + TAG_VERSION=${GITHUB_REF#refs/tags/v} |
| 41 | + CARGO_VERSION=$(grep '^\s*version\s*=' Cargo.toml | head -n 1 | sed 's/.*"\(.*\)"/\1/') |
| 42 | + if [ "$TAG_VERSION" != "$CARGO_VERSION" ]; then |
| 43 | + echo "Version mismatch: tag=$TAG_VERSION, Cargo.toml=$CARGO_VERSION" |
| 44 | + exit 1 |
| 45 | + fi |
| 46 | + echo "Version verified: $TAG_VERSION" |
| 47 | +
|
| 48 | + - name: Run tests before publish |
| 49 | + run: cargo test --workspace --all-features |
| 50 | + |
| 51 | + - name: Build release |
| 52 | + run: cargo build --workspace --release |
| 53 | + |
| 54 | + # Publish crates in dependency order |
| 55 | + - name: Publish rustapi-core |
| 56 | + if: github.event.inputs.dry_run != 'true' |
| 57 | + run: cargo publish -p rustapi-core --token ${{ secrets.CRATES_IO_TOKEN }} |
| 58 | + continue-on-error: true |
| 59 | + |
| 60 | + - name: Wait for crates.io index update |
| 61 | + if: github.event.inputs.dry_run != 'true' |
| 62 | + run: sleep 30 |
| 63 | + |
| 64 | + - name: Publish rustapi-macros |
| 65 | + if: github.event.inputs.dry_run != 'true' |
| 66 | + run: cargo publish -p rustapi-macros --token ${{ secrets.CRATES_IO_TOKEN }} |
| 67 | + continue-on-error: true |
| 68 | + |
| 69 | + - name: Wait for crates.io index update |
| 70 | + if: github.event.inputs.dry_run != 'true' |
| 71 | + run: sleep 30 |
| 72 | + |
| 73 | + - name: Publish rustapi-validate |
| 74 | + if: github.event.inputs.dry_run != 'true' |
| 75 | + run: cargo publish -p rustapi-validate --token ${{ secrets.CRATES_IO_TOKEN }} |
| 76 | + continue-on-error: true |
| 77 | + |
| 78 | + - name: Wait for crates.io index update |
| 79 | + if: github.event.inputs.dry_run != 'true' |
| 80 | + run: sleep 30 |
| 81 | + |
| 82 | + - name: Publish rustapi-openapi |
| 83 | + if: github.event.inputs.dry_run != 'true' |
| 84 | + run: cargo publish -p rustapi-openapi --token ${{ secrets.CRATES_IO_TOKEN }} |
| 85 | + continue-on-error: true |
| 86 | + |
| 87 | + - name: Wait for crates.io index update |
| 88 | + if: github.event.inputs.dry_run != 'true' |
| 89 | + run: sleep 30 |
| 90 | + |
| 91 | + - name: Publish rustapi-extras |
| 92 | + if: github.event.inputs.dry_run != 'true' |
| 93 | + run: cargo publish -p rustapi-extras --token ${{ secrets.CRATES_IO_TOKEN }} |
| 94 | + continue-on-error: true |
| 95 | + |
| 96 | + - name: Wait for crates.io index update |
| 97 | + if: github.event.inputs.dry_run != 'true' |
| 98 | + run: sleep 30 |
| 99 | + |
| 100 | + - name: Publish rustapi-toon |
| 101 | + if: github.event.inputs.dry_run != 'true' |
| 102 | + run: cargo publish -p rustapi-toon --token ${{ secrets.CRATES_IO_TOKEN }} |
| 103 | + continue-on-error: true |
| 104 | + |
| 105 | + - name: Wait for crates.io index update |
| 106 | + if: github.event.inputs.dry_run != 'true' |
| 107 | + run: sleep 30 |
| 108 | + |
| 109 | + - name: Publish rustapi-view |
| 110 | + if: github.event.inputs.dry_run != 'true' |
| 111 | + run: cargo publish -p rustapi-view --token ${{ secrets.CRATES_IO_TOKEN }} |
| 112 | + continue-on-error: true |
| 113 | + |
| 114 | + - name: Wait for crates.io index update |
| 115 | + if: github.event.inputs.dry_run != 'true' |
| 116 | + run: sleep 30 |
| 117 | + |
| 118 | + - name: Publish rustapi-ws |
| 119 | + if: github.event.inputs.dry_run != 'true' |
| 120 | + run: cargo publish -p rustapi-ws --token ${{ secrets.CRATES_IO_TOKEN }} |
| 121 | + continue-on-error: true |
| 122 | + |
| 123 | + - name: Wait for crates.io index update |
| 124 | + if: github.event.inputs.dry_run != 'true' |
| 125 | + run: sleep 30 |
| 126 | + |
| 127 | + - name: Publish rustapi-rs (main crate) |
| 128 | + if: github.event.inputs.dry_run != 'true' |
| 129 | + run: cargo publish -p rustapi-rs --token ${{ secrets.CRATES_IO_TOKEN }} |
| 130 | + |
| 131 | + - name: Publish cargo-rustapi |
| 132 | + if: github.event.inputs.dry_run != 'true' |
| 133 | + run: cargo publish -p cargo-rustapi --token ${{ secrets.CRATES_IO_TOKEN }} |
| 134 | + continue-on-error: true |
| 135 | + |
| 136 | + - name: Dry run verification |
| 137 | + if: github.event.inputs.dry_run == 'true' |
| 138 | + run: | |
| 139 | + echo "Dry run mode - verifying packages can be published..." |
| 140 | + cargo publish -p rustapi-core --dry-run |
| 141 | + cargo publish -p rustapi-macros --dry-run |
| 142 | + cargo publish -p rustapi-validate --dry-run |
| 143 | + cargo publish -p rustapi-openapi --dry-run |
| 144 | + cargo publish -p rustapi-extras --dry-run |
| 145 | + cargo publish -p rustapi-toon --dry-run |
| 146 | + cargo publish -p rustapi-view --dry-run |
| 147 | + cargo publish -p rustapi-ws --dry-run |
| 148 | + cargo publish -p rustapi-rs --dry-run |
| 149 | + cargo publish -p cargo-rustapi --dry-run |
| 150 | + echo "All packages verified successfully!" |
0 commit comments