waterui 0.5.1

A modern UI framework for Rust
name: Release

on:
  # crates.io trusted publishing rejects OIDC tokens minted under
  # `workflow_run`, so publishing runs on the `main` push itself — which
  # can only come from a merged pull request (conventionally the dev ->
  # main release PR) whose required checks already passed on the same
  # tree. `release-pr` still waits for CI via `workflow_run`.
  push:
    branches: [main]
  workflow_run:
    workflows: ["CI"]
    branches: [main]
    types: [completed]

permissions:
  contents: write
  pull-requests: write
  id-token: write

jobs:
  release:
    name: Release unpublished packages
    runs-on: ubuntu-latest
    if: github.event_name == 'push'
    concurrency:
      group: release-${{ github.ref_name }}
      cancel-in-progress: false
    steps:
      - uses: actions/checkout@v4
        with:
          ref: main
          fetch-depth: 0
      - uses: ./.github/actions/setup-rust
        with:
          cache: "false"
      # `cargo publish` verifies each package by building it with its default
      # features, so the native libraries the workspace links have to be here
      # as they are in the test workflow: without them the Linux-only
      # `cros-libva` build script, reached through `waterkit-codec`, fails the
      # `waterui-image` verify build on the missing `libva-dev`.
      - uses: ./.github/actions/setup-linux-deps
      # Mint a short-lived crates.io token from the GitHub OIDC identity
      # instead of a stored CARGO_REGISTRY_TOKEN (trusted publishing is
      # configured per crate on crates.io).
      - uses: rust-lang/crates-io-auth-action@v1
        id: crates-io-auth
      - uses: ./.github/actions/release-plz
        id: release_plz
        with:
          command: release
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          CARGO_REGISTRY_TOKEN: ${{ steps.crates-io-auth.outputs.token }}
      # Read the tag out of release-plz's own report rather than looking for
      # one on this job's HEAD. The tags do not land there: releasing 0.4.1
      # created `v0.4.1` on the release branch's tip, while this
      # job had the merge commit checked out, so `git tag --points-at HEAD`
      # finds nothing even when a release published perfectly well (#540).
      # The `v<version>` tag release-plz published for the `waterui` facade
      # names the framework release `water create --channel stable` resolves.
      # No facade release this run means no framework manifest to publish.
      - name: Detect framework release tag
        id: framework_tag
        shell: bash
        env:
          REPORT: ${{ steps.release_plz.outputs.report }}
        run: |
          set -euo pipefail

          FRAMEWORK_TAG="$(jq -r '[.releases[]? | select(.package_name == "waterui") | .tag] | last // ""' <<< "$REPORT")"

          echo "framework_tag=${FRAMEWORK_TAG}" >> "$GITHUB_OUTPUT"
          if [[ -n "${FRAMEWORK_TAG}" ]]; then
            echo "release-plz released the framework as ${FRAMEWORK_TAG}."
          else
            echo "release-plz released no waterui facade this run."
          fi

      # The manifest is built from the tagged tree itself: the script checks
      # the tag out and records that revision's scaffold table and lock.
      - name: Publish the stable framework manifest
        if: steps.framework_tag.outputs.framework_tag != ''
        env:
          GH_TOKEN: ${{ github.token }}
          FRAMEWORK_TAG: ${{ steps.framework_tag.outputs.framework_tag }}
        run: |
          set -euo pipefail
          python3 .github/scripts/framework_manifest.py stable --tag "$FRAMEWORK_TAG"
          gh release upload "$FRAMEWORK_TAG" framework.json --clobber

  release-pr:
    name: Prepare the next release
    runs-on: ubuntu-latest
    if: github.event_name == 'workflow_run' && github.event.workflow_run.conclusion == 'success' && github.event.workflow_run.head_branch == 'main'
    concurrency:
      group: release-plz-${{ github.event.workflow_run.head_branch }}
      cancel-in-progress: false
    steps:
      - uses: actions/checkout@v4
        with:
          ref: main
          fetch-depth: 0
      - uses: ./.github/actions/setup-rust
        with:
          cache: "false"
      # The same native libraries as above: computing the next versions also
      # builds the workspace's metadata against every crate's dependencies.
      - uses: ./.github/actions/setup-linux-deps
      - uses: ./.github/actions/release-plz
        with:
          command: release-pr
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}