ci: Automate version bump to v1.1.1 #47
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: Create Release Tag & Publish | |
| env: | |
| CARGO_INCREMENTAL: 0 | |
| CARGO_TERM_COLOR: always | |
| on: | |
| pull_request: | |
| types: [closed] | |
| branches: | |
| - main | |
| jobs: | |
| create-tag: | |
| name: Create Release Tag | |
| if: github.event.pull_request.merged == true && contains(github.event.pull_request.labels.*.name, 'release-proposal') | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| outputs: | |
| version: ${{ steps.extract_version.outputs.version }} | |
| is_draft: ${{ steps.extract_version.outputs.is_draft }} | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Extract version from PR title | |
| id: extract_version | |
| run: | | |
| # Extract version from PR title (format: "ci: Automate version bump to vX.Y.Z") | |
| VERSION=$(echo "${{ github.event.pull_request.title }}" | grep -o 'v[0-9]\+\.[0-9]\+\.[0-9]\+') | |
| if [ -z "$VERSION" ]; then | |
| echo "Error: Could not extract version from PR title: ${{ github.event.pull_request.title }}" | |
| exit 1 | |
| fi | |
| echo "version=$VERSION" >> $GITHUB_OUTPUT | |
| # Check if this is a draft release | |
| if [[ "${{ contains(github.event.pull_request.labels.*.name, 'draft-release') }}" == "true" ]]; then | |
| echo "is_draft=true" >> $GITHUB_OUTPUT | |
| else | |
| echo "is_draft=false" >> $GITHUB_OUTPUT | |
| fi | |
| echo "Extracted version: $VERSION" | |
| - name: Create and push tag | |
| run: | | |
| git config user.name "${{ github.actor }}" | |
| git config user.email "${{ github.actor }}@users.noreply.github.com" | |
| git tag -a "${{ steps.extract_version.outputs.version }}" -m "Release ${{ steps.extract_version.outputs.version }}" | |
| git push origin "${{ steps.extract_version.outputs.version }}" | |
| format-checks: | |
| name: 🏁 Format Checks | |
| needs: create-tag | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code at tag | |
| uses: actions/checkout@v4 | |
| with: | |
| ref: ${{ needs.create-tag.outputs.version }} | |
| - name: Install required components | |
| run: rustup component add rustfmt --toolchain nightly | |
| - name: Install taplo | |
| run: cargo install taplo-cli --locked | |
| - name: Run format checks | |
| run: | | |
| taplo format --check --config taplo.toml | |
| cargo +nightly fmt --all -- --check | |
| build-and-test: | |
| name: 🛠️ Build & Test Release | |
| needs: [create-tag, format-checks] | |
| runs-on: ${{ matrix.os }} | |
| strategy: | |
| fail-fast: true | |
| matrix: | |
| os: | |
| - ubuntu-latest | |
| - macos-latest | |
| steps: | |
| - name: Checkout code at tag | |
| uses: actions/checkout@v4 | |
| with: | |
| ref: ${{ needs.create-tag.outputs.version }} | |
| - name: Install Rust stable | |
| uses: dtolnay/rust-toolchain@stable | |
| with: | |
| components: clippy, rust-src | |
| - name: Cache cargo registry | |
| uses: actions/cache@v3 | |
| with: | |
| path: | | |
| ~/.cargo/registry | |
| ~/.cargo/git | |
| target | |
| key: ${{ runner.os }}-release-cargo-${{ hashFiles('**/Cargo.lock') }} | |
| - name: Install dependencies (Ubuntu) | |
| if: matrix.os == 'ubuntu-latest' | |
| run: | | |
| sudo apt-get update -yqq | |
| sudo apt-get install -yqq --no-install-recommends \ | |
| libclang-dev \ | |
| protobuf-compiler | |
| - name: Install dependencies (macOS) | |
| if: matrix.os == 'macos-latest' | |
| run: | | |
| brew install protobuf | |
| - name: Build release (all targets) | |
| run: cargo build --locked --release | |
| - name: Build release (library only) | |
| run: cargo build --lib --locked --release | |
| - name: Test release | |
| run: cargo test --locked --release | |
| - name: Run clippy | |
| run: cargo clippy --all-targets --locked -- -D warnings | |
| - name: Generate documentation | |
| run: cargo doc --locked --no-deps | |
| - name: Check documentation | |
| run: cargo doc --locked --no-deps --document-private-items | |
| - name: Build examples | |
| run: cargo build --examples --locked --release | |
| security-audit: | |
| name: 🔒 Security Audit | |
| needs: [create-tag, format-checks] | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code at tag | |
| uses: actions/checkout@v4 | |
| with: | |
| ref: ${{ needs.create-tag.outputs.version }} | |
| - name: Install cargo-audit | |
| run: cargo install cargo-audit --locked | |
| - name: Run security audit | |
| run: cargo audit | |
| create-github-release: | |
| name: 🚀 Create GitHub Release | |
| needs: [create-tag, build-and-test, security-audit] | |
| if: always() && needs.build-and-test.result == 'success' && needs.security-audit.result == 'success' | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| ref: ${{ needs.create-tag.outputs.version }} | |
| fetch-depth: 0 | |
| fetch-tags: true | |
| - name: Create GitHub Release | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| NEW_VERSION: ${{ needs.create-tag.outputs.version }} | |
| run: | | |
| release_notes="Automated release for quantus-cli version $NEW_VERSION." | |
| printf "%s" "$release_notes" > release_notes.txt | |
| # Add draft flag if this is a draft release | |
| if [[ "${{ needs.create-tag.outputs.is_draft }}" == "true" ]]; then | |
| DRAFT_FLAG="--draft" | |
| else | |
| DRAFT_FLAG="" | |
| fi | |
| echo "Creating release with DRAFT_FLAG: $DRAFT_FLAG" | |
| gh release create "$NEW_VERSION" \ | |
| --repo "$GITHUB_REPOSITORY" \ | |
| --title "Quantus quantus-cli - $NEW_VERSION" \ | |
| --notes-file release_notes.txt \ | |
| --target main \ | |
| $DRAFT_FLAG | |
| publish-to-crates: | |
| name: 📦 Publish to crates.io | |
| needs: [create-tag, build-and-test, security-audit, create-github-release] | |
| if: always() && needs.build-and-test.result == 'success' && needs.security-audit.result == 'success' && needs.create-github-release.result == 'success' && needs.create-tag.outputs.is_draft == 'false' | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code at tag | |
| uses: actions/checkout@v4 | |
| with: | |
| ref: ${{ needs.create-tag.outputs.version }} | |
| - name: Install Rust stable | |
| uses: dtolnay/rust-toolchain@stable | |
| - name: Install dependencies | |
| run: | | |
| sudo apt-get update -yqq | |
| sudo apt-get install -yqq --no-install-recommends \ | |
| libclang-dev \ | |
| protobuf-compiler | |
| - name: Publish to crates.io | |
| run: | | |
| cargo publish --token ${{ secrets.CARGO_REGISTRY_TOKEN }} --allow-dirty | |
| env: | |
| CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }} |