busbar-sf-api 0.0.3

Salesforce API client library for Rust
Documentation
name: Release

on:
    push:
        tags:
            - "v*.*.*"
    workflow_dispatch:
        inputs:
            version:
                description: "Release version (e.g. 0.0.2)"
                required: true
                type: string

# Explicit permissions for security
permissions:
    contents: write # Needed for creating releases

env:
    RUST_BACKTRACE: 1
    CARGO_TERM_COLOR: always

jobs:
    # Create GitHub release
    create-release:
        name: Create Release
        runs-on: ubuntu-latest
        if: startsWith(github.ref, 'refs/tags/') || github.event_name == 'workflow_dispatch'
        outputs:
            upload_url: ${{ steps.create_release.outputs.upload_url }}
            version: ${{ steps.get_version.outputs.version }}
        steps:
            - uses: actions/checkout@v6
              with:
                  fetch-depth: 0

            - name: Get version from tag or input
              id: get_version
              run: |
                  if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
                    echo "version=${{ inputs.version }}" >> $GITHUB_OUTPUT
                  else
                    echo "version=${GITHUB_REF#refs/tags/v}" >> $GITHUB_OUTPUT
                  fi

            - name: Create and push tag (manual release)
              if: github.event_name == 'workflow_dispatch'
              env:
                  RELEASE_VERSION: ${{ steps.get_version.outputs.version }}
              run: |
                  if git rev-parse "v${RELEASE_VERSION}" >/dev/null 2>&1; then
                    echo "Tag v${RELEASE_VERSION} already exists. Aborting."
                    exit 1
                  fi
                  git config user.name "github-actions[bot]"
                  git config user.email "github-actions[bot]@users.noreply.github.com"
                  git tag "v${RELEASE_VERSION}"
                  git push origin "v${RELEASE_VERSION}"

            - name: Create Release
              id: create_release
              uses: actions/create-release@v1
              env:
                  GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
              with:
                  tag_name: v${{ steps.get_version.outputs.version }}
                  release_name: Release v${{ steps.get_version.outputs.version }}
                  draft: false
                  prerelease: false
                  body: |
                      See [CHANGELOG.md](https://github.com/${{ github.repository }}/blob/v${{ steps.get_version.outputs.version }}/CHANGELOG.md) for details.

    # Publish to crates.io
    publish:
        name: Publish to crates.io
        runs-on: ubuntu-latest
        environment: crates.io
        if: startsWith(github.ref, 'refs/tags/') || github.event_name == 'workflow_dispatch'
        steps:
            - uses: actions/checkout@v6

            - name: Install Rust
              uses: dtolnay/rust-toolchain@stable

            - name: Cache cargo registry
              uses: actions/cache@v5
              with:
                  path: ~/.cargo/registry
                  key: ${{ runner.os }}-cargo-registry-${{ hashFiles('**/Cargo.lock') }}
                  restore-keys: |
                      ${{ runner.os }}-cargo-registry-

            - name: Cache cargo index
              uses: actions/cache@v5
              with:
                  path: ~/.cargo/git
                  key: ${{ runner.os }}-cargo-git-${{ hashFiles('**/Cargo.lock') }}
                  restore-keys: |
                      ${{ runner.os }}-cargo-git-

            - name: Verify versions match
              run: |
                  if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
                    TAG_VERSION="${{ inputs.version }}"
                  else
                    TAG_VERSION="${GITHUB_REF#refs/tags/v}"
                  fi
                  CARGO_VERSION=$(grep '^version = ' Cargo.toml | head -1 | sed 's/version = "\(.*\)"/\1/')
                  if [ "$TAG_VERSION" != "$CARGO_VERSION" ]; then
                    echo "Tag version ($TAG_VERSION) does not match Cargo.toml version ($CARGO_VERSION)"
                    exit 1
                  fi
              if: startsWith(github.ref, 'refs/tags/') || github.event_name == 'workflow_dispatch'

            - name: Check formatting
              run: cargo fmt --all --check

            - name: Run clippy
              run: cargo clippy --workspace --all-targets --all-features -- -D warnings

            - name: Publish busbar-sf-client
              env:
                  CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
              run: cargo publish -p busbar-sf-client
              continue-on-error: true

            - name: Publish busbar-sf-auth
              env:
                  CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
              run: cargo publish -p busbar-sf-auth
              continue-on-error: true

            - name: Publish busbar-sf-rest
              env:
                  CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
              run: cargo publish -p busbar-sf-rest
              continue-on-error: true

            - name: Publish busbar-sf-bulk
              env:
                  CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
              run: cargo publish -p busbar-sf-bulk
              continue-on-error: true

            - name: Publish busbar-sf-metadata
              env:
                  CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
              run: cargo publish -p busbar-sf-metadata
              continue-on-error: true

            - name: Publish busbar-sf-tooling
              env:
                  CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
              run: cargo publish -p busbar-sf-tooling
              continue-on-error: true

            - name: Publish busbar-sf-api (root crate)
              env:
                  CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
              run: cargo publish -p busbar-sf-api