name: "Update Rust versions"

sources:
  rust_stable_version:
    kind: shell
    spec:
      shell: bash
      command: |
        set -e
        # Check that we have latest stable.
        if rustup check | grep '^stable-.*[uU]pdate available'; then
            echo >&2 "Rust toolchain 'stable' is stale, please update it"
            exit 1
        fi
        stable_rust_version=$("$(rustup +stable which rustc)" --version | cut -d' ' -f2)
        echo "${stable_rust_version%.*}"
  debian_stable_rust_version:
    kind: shell
    spec:
      command: |
        build_tools/version-available-in-debian.sh stable rustc

targets:
  update_rust_stable:
    name: "Update Rust stable"
    sourceid: rust_stable_version
    kind: file
    spec:
      file: .github/actions/rust-toolchain/action.yml
      matchpattern: '\(stable\) echo \d+\.\d+ ;;.*'
      replacepattern: '(stable) echo {{ source "rust_stable_version" }} ;; # updatecli.d/rust.yml'
  update_rust_stable2:
    name: "Update Rust stable #2"
    sourceid: rust_stable_version
    kind: file
    spec:
      file: .github/workflows/lint-dependencies.yml
      matchpattern: 'rust-version: \d+\.\d+\b.*'
      replacepattern: 'rust-version: {{ source "rust_stable_version" }} # updatecli.d/rust.yml'
  update_msrv:
    name: "Update MSRV"
    sourceid: debian_stable_rust_version
    kind: file
    spec:
      file: .github/actions/rust-toolchain/action.yml
      matchpattern: '\(msrv\)   echo \d+\.\d+ ;;.*'
      replacepattern: '(msrv)   echo {{ source "debian_stable_rust_version" }} ;; # updatecli.d/rust.yml'
