struson 0.7.2

A low-level streaming JSON reader and writer
Documentation
name: Publish

on:
  # Only run when manually triggered
  workflow_dispatch:
    inputs:
      versionBump:
        description: 'Part of the SemVer project version to bump for release (<major>.<minor>.<patch>)'
        required: true
        type: choice
        options:
        - major
        - minor
        - patch

env:
  # Enable colored terminal output, see https://doc.rust-lang.org/cargo/reference/config.html#termcolor
  CARGO_TERM_COLOR: always

# TODO: Maybe switch to https://github.com/crate-ci/cargo-release in the future, and if possible
# let it check API SemVer compliance, see also https://github.com/crate-ci/cargo-release/issues/62

jobs:
  # Build the documentation similar (but not completely identical) to how docs.rs would do it,
  # to notice any potential configuration issues in advance; see https://github.com/dtolnay/cargo-docs-rs
  # Run this as separate job with minimal permissions because the used actions cannot be pinned
  # easily, and to avoid that the Nightly toolchain somehow affects publishing
  check-docs-rs-build:
    runs-on: ubuntu-latest
    permissions:
      contents: read
    env:
      RUSTDOCFLAGS: --deny warnings
    steps:
      - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd  # v6.0.2
      - uses: dtolnay/rust-toolchain@nightly
      - uses: dtolnay/install@cargo-docs-rs
      - run: cargo +nightly docs-rs

  publish:
    needs: check-docs-rs-build
    runs-on: ubuntu-latest
    environment: publishing
    permissions:
      contents: write  # read repository content and push updated version and tag
      id-token: write  # Required for OIDC token exchange for trusted publishing, see below
    steps:
      - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd  # v6.0.2

      - name: Update project version
        shell: bash
        # https://github.com/killercup/cargo-edit
        run: |
          cargo install --no-default-features --features set-version cargo-edit@0.13.8
          cargo set-version --bump ${{ inputs.versionBump }}

      # There is currently no easy way to get the new version number (see also https://github.com/killercup/cargo-edit/issues/524),
      # so have to get it by other means
      - name: Get new version
        id: get-new-version
        shell: bash
        # See https://stackoverflow.com/a/75023425
        # and https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#setting-an-output-parameter
        run: |
          VERSION=$(cargo metadata --format-version=1 --no-deps | jq --compact-output --raw-output --exit-status '.packages[0].version')
          echo "New version: $VERSION"
          echo "VERSION=$VERSION" >> $GITHUB_OUTPUT

      - name: Commit version update
        shell: bash
        run: |
          git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
          git config user.name "github-actions[bot]"
          git add .
          git commit -m "Release version ${{ steps.get-new-version.outputs.VERSION }}"
          git tag -a "v${{ steps.get-new-version.outputs.VERSION }}" -m "Release ${{ steps.get-new-version.outputs.VERSION }}"

      - name: Install cargo-make
        uses: taiki-e/install-action@7fe7b8c79a3c5569643cf27dfc32456883a4cd4d  #v2.62.16
        with:
          tool: cargo-make@0.37.24

      # Perform full build to make sure there are no issues
      - name: Build project
        shell: bash
        run: cargo make

      # TODO: Once this project is more stable, maybe include SemVer checks, e.g.
      # https://github.com/rust-lang/rust-semverver or https://github.com/obi1kenobi/cargo-semver-checks

      # Push changes before trying to publish them; otherwise if pushing fails the version might have been published
      # already but the corresponding project version change and Git tag will be missing
      - name: Push Git changes
        shell: bash
        run: git push --follow-tags

      # Clean up results from build to not affect publish in any way
      - name: Clean
        shell: bash
        run: cargo clean

      # Uses trusted publishing, see https://crates.io/docs/trusted-publishing
      - name: crates.io auth
        uses: rust-lang/crates-io-auth-action@b7e9a28eded4986ec6b1fa40eeee8f8f165559ec  #v1.0.3
        id: auth
      - name: Publish
        shell: bash
        # TODO: Fail on any warnings (e.g. incorrect Cargo.toml values); not yet available, see https://github.com/rust-lang/cargo/issues/8424
        run: cargo publish --all-features
        env:
          CARGO_REGISTRY_TOKEN: ${{ steps.auth.outputs.token }}