amber-api 2.1.0

Rust client for Amber Electric's API
Documentation
---
name: test

permissions:
  contents: read

on:
  pull_request:
    branches:
      - main
    types:
      - opened
      - synchronize
      - reopened
      - ready_for_review
  push:
    branches:
      - main

concurrency:
  group: ${{ github.workflow }}-${{ github.ref }}
  cancel-in-progress: true

env:
  # Generic
  FORCE_COLOR: '1'
  CLICOLOR: '1'
  # Python
  PYTHONUNBUFFERED: '1'
  STABLE_PYTHON_VERSION: '3.13'
  # Rust
  RUST_BACKTRACE: '1'
  NEXTEST_PROFILE: ci

jobs:
  # This job checks if the necessary checks have been completed and is used by
  # GitHub's rules to determine if the PR can be merged. This more convenient
  # than specifying each individual check in the GitHub UI.
  complete:
    name: Test completion check
    if: always()

    permissions:
      contents: none

    runs-on: ubuntu-latest
    needs:
      - prek
      - clippy
      - format
      - coverage
      - test
      - examples

    steps:
      - name: Failed
        run: exit 1
        if: >
          contains(needs.*.result, 'failure')
          || contains(needs.*.result, 'cancelled')
          || contains(needs.*.result, 'skipped')

  ##############################################################################
  ## Checks
  ##############################################################################

  committed:
    name: Committed

    runs-on: ubuntu-latest
    if: github.event_name == 'pull_request'

    steps:
      - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd  # v6.0.2
        with:
          fetch-depth: 0

      - name: committed-action
        uses: crate-ci/committed@dc6f20ddd899fe6d6f0402807884c0a4b3176b53  # v1.1.10
        with:
          args: -vv --no-merge-commit --no-wip --no-fixup

  prek:
    name: Prek (pre-commit)

    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd  # v6.0.2

      - name: Cache prek
        uses: actions/cache@cdf6c1fa76f9f475f3d7449005a359c84ca0f306  # v5.0.3
        with:
          path: |-
            ~/.cache/prek
          key: >-
            ${{ runner.os }}-prek-${{
              hashFiles(
                '**/.pre-commit-config.yaml',
                '**/.pre-commit-config.yml'
              ) }}
          restore-keys: |-
            ${{ runner.os }}-prek-

      - name: Install Rust
        uses: dtolnay/rust-toolchain@stable
        with:
          toolchain: stable
          components: rustfmt,clippy

      - name: Set up uv
        uses: astral-sh/setup-uv@eac588ad8def6316056a12d4907a9d4d84ff7a3b  # v7.3.0
        with:
          enable-cache: true
          cache-suffix: prek
          cache-dependency-glob: |-
            **/.pre-commit-config.yaml
            **/.pre-commit-config.yml

      - name: Install prek
        run: uv tool install prek

      - name: Run prek
        run: prek run --show-diff-on-failure --color=always --all-files

  clippy:
    name: Clippy Rust ${{ matrix.rust }} on  ${{ startsWith(matrix.os, 'macos-') && 'macOS' || startsWith(matrix.os, 'windows-') && 'Windows' || 'Linux' }}

    runs-on: ${{ matrix.os }}

    strategy:
      matrix:
        os:
          - ubuntu-latest
        rust:
          - stable
    continue-on-error: ${{ matrix.rust != 'stable' }}

    steps:
      - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd  # v6.0.2

      - name: Install Rust
        uses: dtolnay/rust-toolchain@stable
        with:
          toolchain: ${{ matrix.rust }}
          components: clippy

      - name: Cache Rust
        uses: Swatinem/rust-cache@779680da715d629ac1d338a641029a2f4372abb5  # v2.8.2

      - name: Install Rust tools
        uses: taiki-e/install-action@509565405a8a987e73cf742e26b26dcc72c4b01a  # v2.67.26
        with:
          tool: cargo-hack

      - name: Clippy (no dev deps)
        run: |
          cargo hack --feature-powerset --no-dev-deps \
            clippy --workspace -- -D warnings

      - name: Clippy (with dev deps)
        run: |
          cargo hack --feature-powerset \
            clippy --workspace --all-targets -- -D warnings

  format:
    name: Format Rust ${{ matrix.rust }} on  ${{ startsWith(matrix.os, 'macos-') && 'macOS' || startsWith(matrix.os, 'windows-') && 'Windows' || 'Linux' }}

    runs-on: ${{ matrix.os }}

    strategy:
      matrix:
        os:
          - ubuntu-latest
        rust:
          - stable
    continue-on-error: ${{ matrix.rust != 'stable' }}

    steps:
      - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd  # v6.0.2

      - name: Install Rust
        uses: dtolnay/rust-toolchain@stable
        with:
          toolchain: ${{ matrix.rust }}
          components: rustfmt

      - name: Cache Rust
        uses: Swatinem/rust-cache@779680da715d629ac1d338a641029a2f4372abb5  # v2.8.2

      - name: Format
        run: cargo fmt --check

  coverage:
    name: Rust Coverage

    runs-on: ubuntu-latest
    if: github.event.pull_request.draft == false || github.event_name != 'pull_request'

    steps:
      - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd  # v6.0.2

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

      - name: Cache Rust
        uses: Swatinem/rust-cache@779680da715d629ac1d338a641029a2f4372abb5  # v2.8.2

      - name: Install Rust tools
        uses: taiki-e/install-action@509565405a8a987e73cf742e26b26dcc72c4b01a  # v2.67.26
        with:
          tool: cargo-tarpaulin

      - name: Run cargo tarpaulin
        env:
          AMBER_API_KEY: ${{ secrets.AMBER_API_KEY }}
        run: cargo tarpaulin --out Xml --timeout 600

      - name: Upload Rust coverage artifact
        uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f  # v6.0.0
        with:
          name: rust-coverage
          path: '**/cobertura.xml'
          if-no-files-found: warn

      - name: Upload coverage reports to Codecov
        uses: codecov/codecov-action@671740ac38dd9b0130fbe1cec585b89eea48d3de  # v5.5.2
        with:
          token: ${{ secrets.CODECOV_TOKEN }}

  test:
    name: Test Rust ${{ matrix.rust }} on  ${{ startsWith(matrix.os, 'macos-') && 'macOS' || startsWith(matrix.os, 'windows-') && 'Windows' || 'Linux' }}

    runs-on: ${{ matrix.os }}
    if: github.event.pull_request.draft == false || github.event_name != 'pull_request'

    strategy:
      fail-fast: false
      matrix:
        os:
          - ubuntu-latest
          - windows-latest
          - macos-latest
        rust:
          - stable
        include:
          - os: ubuntu-latest
            rust: beta
    continue-on-error: ${{ matrix.rust != 'stable' }}

    steps:
      - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd  # v6.0.2

      - name: Install Rust
        uses: dtolnay/rust-toolchain@stable
        with:
          toolchain: ${{ matrix.rust }}

      - name: Cache Rust
        uses: Swatinem/rust-cache@779680da715d629ac1d338a641029a2f4372abb5  # v2.8.2

      - name: Install Rust tools
        uses: taiki-e/install-action@509565405a8a987e73cf742e26b26dcc72c4b01a  # v2.67.26
        with:
          tool: cargo-hack,nextest

      - name: Run tests
        shell: bash
        env:
          AMBER_API_KEY: ${{ secrets.AMBER_API_KEY }}
        run: |
          cargo hack --feature-powerset \
            nextest run --workspace

  examples:
    name: Examples

    runs-on: ubuntu-latest
    if: github.event.pull_request.draft == false || github.event_name != 'pull_request'

    steps:
      - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd  # v6.0.2

      - name: Install Rust
        uses: dtolnay/rust-toolchain@stable
        with:
          components: clippy,rustfmt

      - name: Cache Rust
        uses: Swatinem/rust-cache@779680da715d629ac1d338a641029a2f4372abb5  # v2.8.2

      - name: Install Rust tools
        uses: taiki-e/install-action@509565405a8a987e73cf742e26b26dcc72c4b01a  # v2.67.26
        with:
          tool: cargo-hack

      - name: Run examples
        env:
          AMBER_API_KEY: ${{ secrets.AMBER_API_KEY }}
        run: ./scripts/ci/run-examples