wuapi 0.17.0

Rust SDK for wuapi, a WhatsApp API for developers. Link numbers by QR or pairing code, send and receive messages, manage chats, contacts, groups and channels, split them into projects and verify webhooks.
Documentation
# Publishes the `wuapi` crate to crates.io when main has a version crates.io
# does not have yet.
#
# - Pushes to main (the monorepo sync pushes here): format check, clippy and
#   tests, then `cargo publish` unless crates.io already has Cargo.toml's
#   version, so re-runs and syncs that do not bump the version publish nothing.
#   Then it creates the `v<version>` tag and a GitHub Release with generated
#   notes (skipped when the release exists).
# - workflow_dispatch: the same job by hand, a dry run by default.
#
# Auth is crates.io trusted publishing (OIDC), with no stored token: crates.io
# must list this repository and this workflow file as the crate's trusted
# publisher. Setup: RELEASING.md.
name: Release

on:
  push:
    branches: [main]
  workflow_dispatch:
    inputs:
      dry-run:
        description: Check, test and `cargo publish --dry-run` only. Nothing is published, tagged or released.
        type: boolean
        default: true

permissions:
  contents: read

# One release at a time, never cancelled halfway through a publish.
concurrency:
  group: ${{ github.workflow }}
  cancel-in-progress: false

jobs:
  release:
    name: Publish to crates.io
    # Never from a fork or a copy of this repository.
    if: github.repository == 'wuapidev/wuapi-rust'
    runs-on: ubuntu-latest
    timeout-minutes: 20
    permissions:
      contents: write # the v<version> tag and the GitHub Release
      id-token: write # crates.io trusted publishing (OIDC)
    env:
      DRY_RUN: ${{ github.event_name == 'workflow_dispatch' && inputs.dry-run }}
    steps:
      - name: Refuse to publish from a ref other than main
        if: github.ref != 'refs/heads/main' && env.DRY_RUN != 'true'
        run: |
          echo "::error::Publishing runs from main only (this run is on ${GITHUB_REF}). Re-run on main, or tick dry-run."
          exit 1

      - uses: actions/checkout@v5
        with:
          # Tags, to start the release notes at the previous v<version> tag.
          fetch-depth: 0

      - uses: dtolnay/rust-toolchain@stable
        with:
          components: rustfmt, clippy
      - uses: Swatinem/rust-cache@v2

      - name: Plan
        id: plan
        run: |
          meta="$(cargo metadata --no-deps --format-version 1)"
          name="$(jq -r '.packages[0].name' <<< "$meta")"
          version="$(jq -r '.packages[0].version' <<< "$meta")"
          # 200: crates.io has this version. 404: it does not. Anything else
          # (rate limit, outage) stops the run instead of guessing.
          status="$(curl -sS -o /dev/null -w '%{http_code}' -A "wuapi-rust release (github.com/${GITHUB_REPOSITORY})" "https://crates.io/api/v1/crates/${name}/${version}")"
          case "$status" in
            200) published=true ;;
            404) published=false ;;
            *) echo "::error::crates.io answered ${status} for ${name} ${version}."; exit 1 ;;
          esac
          case "$version" in *-*) prerelease=true ;; *) prerelease=false ;; esac
          {
            echo "name=${name}"
            echo "version=${version}"
            echo "tag=v${version}"
            echo "published=${published}"
            echo "prerelease=${prerelease}"
          } | tee -a "$GITHUB_OUTPUT"

      - name: Format, lint, test
        run: cargo fmt --check && cargo clippy --all-targets -- -D warnings && cargo test

      - name: Package (dry run)
        if: steps.plan.outputs.published == 'false'
        run: cargo publish --dry-run

      # Exchanges this job's OIDC token (id-token: write) for a short-lived
      # crates.io token, revoked when the job ends.
      - name: Authenticate to crates.io
        id: auth
        if: steps.plan.outputs.published == 'false' && env.DRY_RUN != 'true'
        uses: rust-lang/crates-io-auth-action@v1

      - name: Publish ${{ steps.plan.outputs.name }} ${{ steps.plan.outputs.version }}
        if: steps.plan.outputs.published == 'false' && env.DRY_RUN != 'true'
        env:
          CARGO_REGISTRY_TOKEN: ${{ steps.auth.outputs.token }}
        run: cargo publish

      - name: Already on crates.io
        if: steps.plan.outputs.published == 'true'
        run: echo "::notice::${{ steps.plan.outputs.name }} ${{ steps.plan.outputs.version }} is already on crates.io; nothing to publish."

      - name: Tag and GitHub Release
        if: env.DRY_RUN != 'true'
        env:
          GH_TOKEN: ${{ github.token }}
          TAG: ${{ steps.plan.outputs.tag }}
          PRERELEASE: ${{ steps.plan.outputs.prerelease }}
        run: |
          if gh release view "$TAG" > /dev/null 2>&1; then
            echo "Release $TAG exists; nothing to do."
            exit 0
          fi
          args=(--target "$GITHUB_SHA" --title "$TAG" --generate-notes)
          previous="$(git tag --list 'v*' --sort=-v:refname | grep -vx "$TAG" | head -n 1 || true)"
          if [ -n "$previous" ]; then args+=(--notes-start-tag "$previous"); fi
          if [ "$PRERELEASE" = "true" ]; then args+=(--prerelease); fi
          gh release create "$TAG" "${args[@]}"