vrchatapi 1.20.9

VRChat API Client for Rust
Documentation
on:
  push:
    branches:
      - '**'
  pull_request:
  repository_dispatch:
    types: [release]
  workflow_dispatch:
    inputs:
      json:
        description: Passed json from repository_dispatch
        required: true
        type: string
      version_postfix:
        description: Additional string to concatenate onto the existing version before release
        required: false
        type: string
        default: ''
  workflow_call:
    inputs:
      ref:
        description: Ref of this repository to build.
        required: false
        type: string
        default: main

name: CI

env:
  PASSED_VERSION: ${{ (github.event_name == 'repository_dispatch' && github.event.client_payload || fromJSON(inputs.json || '{}'))['version'] }}
  URL: ${{ (github.event_name == 'repository_dispatch' && github.event.client_payload || fromJSON(inputs.json || '{}'))['artifacts']['openapi.json'] }}
  VERSION_POSTPEND: ${{ github.event_name == 'workflow_dispatch' && inputs.version_postfix || '' }}

jobs:
  generate:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v7
        with:
          repository: vrchatapi/vrchatapi-rust
          ref: ${{ inputs.ref || github.ref }}

      - uses: vrchatapi/specification/.github/actions/setup-generator@main

      - uses: vrchatapi/specification/.github/actions/download@main
        with:
          url: ${{ env.URL }}

      - if: env.PASSED_VERSION != ''
        run: |
          set -euo pipefail

          if [ "$(yq '--unwrapScalar' '.info.version' openapi.json)" != "${PASSED_VERSION}" ]; then
            echo "Mismatch between actual and expected version" >&2
            exit 1
          fi

      - if: env.VERSION_POSTPEND != ''
        run: yq '--inplace' ".info.version |= \"${PASSED_VERSION}${VERSION_POSTPEND}\"" openapi.json

      - run: bash ./generate.sh openapi.json

      - if: env.PASSED_VERSION != ''
        run: |
          set -euo pipefail

          if [ "$(yq '--unwrapScalar' '--input-format=toml' '--output-format=toml' '.package.version' Cargo.toml)" != "${PASSED_VERSION}${VERSION_POSTPEND}" ]; then
            echo "Mismatch between actual and expected version" >&2
            exit 1
          fi

      - uses: actions/upload-artifact@v7
        with:
          name: rust-generated
          path: |
            .
            !.git/**
          include-hidden-files: true

  format:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v7
        with:
          repository: vrchatapi/vrchatapi-rust
          ref: ${{ inputs.ref || github.ref }}

      - uses: moonrepo/setup-rust@v1.3.0
        with:
          components: rustfmt

      - run: cargo fmt --all -- --check

      - run: rustfmt --edition 2021 --check patches/*.rs

  test:
    needs: generate
    runs-on: ubuntu-latest
    steps:
      - uses: actions/download-artifact@v8
        with:
          name: rust-generated

      - uses: moonrepo/setup-rust@v1.3.0

      - run: cargo test --all

  publish:
    needs:
      - generate
      - format
      - test
    if: github.repository == 'vrchatapi/vrchatapi-rust'
      && (github.event_name == 'repository_dispatch' || github.event_name == 'workflow_dispatch')
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v7
        with:
          repository: vrchatapi/vrchatapi-rust

      - uses: actions/download-artifact@v8
        with:
          name: rust-generated

      - run: rm -f openapi.json

      - uses: JamesIves/github-pages-deploy-action@v4.9.0
        with:
          branch: main
          folder: .
          commit-message: Upgrade Rust SDK to spec ${{ env.PASSED_VERSION }}${{ env.VERSION_POSTPEND }}

      - uses: moonrepo/setup-rust@v1.3.0

      # Cargo.toml always reads as dirty, though the change was pushed above.
      - run: cargo publish --allow-dirty
        env:
          CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}