Linting

name: Linting

on: [push, pull_request]

jobs:
  build:

    runs-on: ubuntu-latest
    strategy:
      matrix:
        python-version: [3.8, 3.9]

    steps:
    - uses: actions/checkout@v1
    - name: Set up Python ${{ matrix.python-version }}
      uses: actions/setup-python@v1
      with:
        python-version: ${{ matrix.python-version }}
    - name: Run pre-commit hook
      uses: pre-commit/action@v2.0.3


Test Array API Strict

name: Test Array API Strict

on: [push, pull_request]

jobs:
  build:

    runs-on: ubuntu-latest
    strategy:
      matrix:
        python-version: ["3.10", "3.11"]

    steps:
    - name: Checkout array-api-tests
      uses: actions/checkout@v1
      with:
        submodules: 'true'
    - name: Set up Python ${{ matrix.python-version }}
      uses: actions/setup-python@v1
      with:
        python-version: ${{ matrix.python-version }}
    - name: Install dependencies
      run: |
        python -m pip install --upgrade pip
        python -m pip install array-api-strict
        python -m pip install -r requirements.txt
    - name: Run the test suite
      env:
        ARRAY_API_TESTS_MODULE: array_api_strict
      run: |
        pytest -v -rxXfE --skips-file array-api-strict-skips.txt array_api_tests/
        # We also have internal tests that isn't really necessary for adopters
        pytest -v -rxXfE meta_tests/


Build wheels and deploy

# A single CI script with github workflow
name: Build wheels and deploy

on:
  workflow_dispatch:
  push:
  merge_group:
  release:
    types:
      - published

jobs:
  build:
    strategy:
      matrix:
        os: [ubuntu-latest, macos-latest, windows-latest]
        python-version: [ 3.9, '3.10', '3.11', '3.12']
    uses: qiboteam/workflows/.github/workflows/deploy-pip-poetry.yml@main
    with:
      os: ${{ matrix.os }}
      python-version: ${{ matrix.python-version }}
      publish: ${{ github.event_name == 'release' && github.event.action == 'published' && matrix.os == 'ubuntu-latest' && matrix.python-version == '3.10' }}
      poetry-extras: "--with tests,docs"
    secrets: inherit


docs

name: docs

on:
  workflow_dispatch:
  push:
    branches: [master]
    tags:
      - "*"

jobs:
  evaluate-label:
    runs-on: ubuntu-latest
    outputs:
      label: ${{ steps.label_step.outputs.version}}
    steps:
      - name: checks for the label
        id: label_step
        run: |
          if [[ "${{ github.ref  }}" == "refs/heads/master" ]]; then
                echo "version=latest" >> $GITHUB_OUTPUT
          fi
          if [[ "${{ github.ref_type }}" == "branch" ]] && [[ "${{ github.ref  }}" != "refs/heads/master" ]]; then
                exit 1
          fi
          if [[ "${{ github.ref_type }}" == "tag" ]]; then
                echo "version=stable" >> $GITHUB_OUTPUT
          fi

  deploy-docs:
    needs: [evaluate-label]
    uses: qiboteam/workflows/.github/workflows/deploy-ghpages-latest-stable.yml@main
    with:
      python-version: "3.10"
      package-manager: "poetry"
      dependency-path: "**/poetry.lock"
      trigger-label: "${{needs.evaluate-label.outputs.label}}"
      project: qibo
      poetry-extras: --with docs


Tests

# A single CI script with github workflow
name: Tests

on:
  workflow_dispatch:
  push:
  merge_group:
  pull_request:
    types: [labeled, opened] # opened is required to allow external contributors

jobs:
  build:
    if: contains(github.event.pull_request.labels.*.name, 'run-workflow') || github.event_name == 'push'
    strategy:
      matrix:
        os: [ubuntu-latest, macos-latest, windows-latest]
        python-version: [ 3.9, '3.10', '3.11', '3.12']
    uses: qiboteam/workflows/.github/workflows/rules-poetry.yml@main
    with:
      os: ${{ matrix.os }}
      python-version: ${{ matrix.python-version }}
      doctests: ${{ matrix.os == 'ubuntu-latest'}}
      poetry-extras: "--with tests,docs"
    secrets: inherit


Tests with gpu

# CI workflow that runs on selfhosted GPU
name: Tests with gpu

on:
  pull_request:
    types: [labeled]

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

jobs:
  build:
    if: contains(join(github.event.pull_request.labels.*.name), 'run-on')
    uses: qiboteam/workflows/.github/workflows/selfhosted.yml@main
    with:
      used-labels: ${{ toJSON(github.event.pull_request.labels.*.name) }}
      python-version: "3.10"
      artifact-url: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
      poetry-extras: "--with cuda11,tests"

    secrets:
      repo_token: ${{ secrets.GITHUB_TOKEN }}


Bazel test

name: Bazel test
on:
  push:
    branches:
      - main
    paths:
      - 'WORKSPACE'
      - 'src/**'
      - '!src/**.md'
  pull_request:
    paths:
      - 'WORKSPACE'
      - 'src/**'
      - '!src/**.md'
jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
      - name: Set up JDK 8
        uses: actions/setup-java@99b8673ff64fbf99d8d325f52d9a5bdedb8483e9 # v4.2.1
        with:
          distribution: temurin
          java-version: '8'
      - name: Setup Bazel
        uses: bazelbuild/setup-bazelisk@b39c379c82683a5f25d34f0d062761f62693e0b2 # v3.0.0
      - name: Cache Bazel outputs
        uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4.0.2
        with:
          path: "~/.cache/bazel"
          key: bazel
      - name: Run Bazel test
        run: |
          bazel test //...


name: e2e

on:
  push:
    branches: [main]
  workflow_dispatch:

env:
  LAUNCHABLE_DEBUG: 1
  LAUNCHABLE_REPORT_ERROR: 1

jobs:
  tests:
    runs-on: ubuntu-20.04
    strategy:
      matrix:
        python-version: [3.6, 3.7, 3.8, 3.9, "3.10"]
    steps:
      - uses: actions/checkout@v4
      - uses: actions/checkout@v4
        with:
          repository: launchableinc/examples
          path: examples
      - name: Set up JDK 1.8
        uses: actions/setup-java@v4
        with:
          java-version: 8
          distribution: 'temurin'
      - uses: actions/setup-go@v5
        with:
          go-version: 1.17
      - uses: actions/setup-python@v5
        with:
          python-version: ${{ matrix.python-version }}
      - name: Install dependencies
        run: |
          python -m pip install --upgrade pip
          pip install .
      # bazel
      - name: Install Bazelisk
        run: |
          go install github.com/bazelbuild/bazelisk@latest
      - name: "bazel: verify"
        run: "launchable verify"
        env:
          LAUNCHABLE_TOKEN: ${{ secrets.LAUNCHABLE_TOKEN_BAZEL }}
      - name: "bazel: Record build"
        run: 'launchable record build --name "$GITHUB_RUN_ID" --source main=../.. --source cli=../../..'
        env:
          LAUNCHABLE_TOKEN: ${{ secrets.LAUNCHABLE_TOKEN_BAZEL }}
        working-directory: examples/bazel/java
      - name: "bazel: Subset"
        run: bazelisk query 'tests(//...)' | launchable subset --target 30% bazel > subset.txt
        env:
          LAUNCHABLE_TOKEN: ${{ secrets.LAUNCHABLE_TOKEN_BAZEL }}
        working-directory: examples/bazel/java
      - name: "bazel: Run test"
        run: bazelisk test $(cat subset.txt)
        working-directory: examples/bazel/java
      - name: "bazel: Record test results"
        run: launchable record tests bazel .
        if: always()
        env:
          LAUNCHABLE_TOKEN: ${{ secrets.LAUNCHABLE_TOKEN_BAZEL }}
        working-directory: examples/bazel/java
      # go
      - name: Install go-junit-report
        run: |
          go install github.com/jstemmer/go-junit-report@latest
        working-directory: examples/go
      - name: "go: verify"
        run: "launchable verify"
        env:
          LAUNCHABLE_TOKEN: ${{ secrets.LAUNCHABLE_TOKEN_GO }}
      - name: "go: Record build"
        run: 'launchable record build --name "$GITHUB_RUN_ID" --source main=.. --source cli=../..'
        env:
          LAUNCHABLE_TOKEN: ${{ secrets.LAUNCHABLE_TOKEN_GO }}
        working-directory: examples/go
      - name: "go: Subset"
        run: go test -list="Test|Example" ./... | launchable subset --confidence 80%  go-test > launchable-subset.txt
        env:
          LAUNCHABLE_TOKEN: ${{ secrets.LAUNCHABLE_TOKEN_GO }}
        working-directory: examples/go
      - name: "go: Run test"
        run: go test -run $(cat launchable-subset.txt) ./... -v 2>&1 | go-junit-report -set-exit-code > report.xml
        working-directory: examples/go
      - name: "go: Record test results"
        run: launchable record tests go-test report.xml
        if: always()
        env:
          LAUNCHABLE_TOKEN: ${{ secrets.LAUNCHABLE_TOKEN_GO }}
        working-directory: examples/go
        # gradle
      - name: "gradle: verify"
        run: "launchable verify"
        env:
          LAUNCHABLE_TOKEN: ${{ secrets.LAUNCHABLE_TOKEN_GRADLE }}
      - name: "gradle: Record build"
        run: 'launchable record build --name "$GITHUB_RUN_ID" --source main=.. --source cli=../..'
        env:
          LAUNCHABLE_TOKEN: ${{ secrets.LAUNCHABLE_TOKEN_GRADLE }}
        working-directory: examples/gradle
      - name: "gradle: Subset"
        run: launchable subset --target 80%  gradle src/test/java > launchable-subset.txt
        env:
          LAUNCHABLE_TOKEN: ${{ secrets.LAUNCHABLE_TOKEN_GRADLE }}
        working-directory: examples/gradle
      - name: "gradle: Run test"
        run: ./gradlew test $(cat launchable-subset.txt)
        working-directory: examples/gradle
      - name: "gradle: Record test results"
        run: launchable record tests gradle build/test-results/test
        if: always()
        env:
          LAUNCHABLE_TOKEN: ${{ secrets.LAUNCHABLE_TOKEN_GRADLE }}
        working-directory: examples/gradle


Python package

# This workflow will install Python dependencies, run tests and lint with a variety of Python versions
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions

name: Python package

on:
  workflow_dispatch:
  push:
    branches: [ main ]
    paths-ignore:
      - 'WORKSPACE'
      - 'src/**'
  pull_request:
    branches: [ main ]
    paths-ignore:
      - 'WORKSPACE'
      - 'src/**'
  schedule:
    # This job runs at 00:00 JST every day.
    - cron: '0 9 * * *'

env:
  LAUNCHABLE_ORGANIZATION: "launchableinc"
  LAUNCHABLE_WORKSPACE: "cli"
  GITHUB_PULL_REQUEST_URL: ${{ github.event.pull_request.html_url }}
  GITHUB_PR_HEAD_SHA: ${{ github.event.pull_request.head.sha }}

permissions:
  id-token: write
  contents: read

jobs:
  build:

    runs-on: ${{ matrix.os }}
    strategy:
      matrix:
        os: [ubuntu-20.04, windows-latest]
        python-version: [3.6, 3.7, 3.8, 3.9, "3.10", "3.11", "3.12"]

    steps:
    - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
      with:
        fetch-depth: 0
    - name: Set up Python ${{ matrix.python-version }}
      uses: actions/setup-python@v5
      with:
        python-version: ${{ matrix.python-version }}
    - name: Set up JDK 1.8
      uses: actions/setup-java@99b8673ff64fbf99d8d325f52d9a5bdedb8483e9 # v4.2.1
      with:
        java-version: 8
        distribution: 'temurin'
    - name: Install specific dependencies in 3.6
      if: matrix.python-version == '3.6'
      uses: nick-fields/retry@7152eba30c6575329ac0576536151aca5a72780e # v3.0.0
      with:
        max_attempts: 3
        timeout_minutes: 5
        retry_on: error
        command: |
          python -m pip install --upgrade pip
          pip install pipenv==2021.11.5
          pipenv install --dev --python ${{ matrix.python-version }}
    - name: Install dependencies
      if: matrix.python-version != '3.6'
      uses: nick-fields/retry@7152eba30c6575329ac0576536151aca5a72780e # v3.0.0
      with:
        max_attempts: 3
        timeout_minutes: 5
        retry_on: error
        command: |
          python -m pip install --upgrade pip
          pip install pipenv
          pipenv install --dev --python ${{ matrix.python-version }}
    - name: Build
      run: |
        pipenv run build
        pipenv run install
    - name: Type check
      run: pipenv run type
    - name: Lint with flake8
      run: |
        # stop the build if there are Python syntax errors or undefined names
        pipenv run lint
    - name: Pull request validation
      run: |
        # Install Launchable CLI from this repos's code
        pip3 install . > /dev/null

        set -x

        launchable verify

        # Tell Launchable about the build you are producing and testing
        launchable record build --name ${GITHUB_RUN_ID}

        launchable record session --build ${GITHUB_RUN_ID} --flavor os=${{ matrix.os }} --flavor python=${{ matrix.python-version }} > session.txt

        # Find 25% of the relevant tests to run for this change
        find tests -name test_*.py | grep -v tests/data | launchable subset --target 25% --session $(cat session.txt) --rest launchable-remainder.txt file > subset.txt

        function record() {
          # Record test results
          LAUNCHABLE_SLACK_NOTIFICATION=true launchable record tests --session $(cat session.txt) file test-results/*.xml
        }

        trap record EXIT

        # Test subset of tests
        pipenv run test-xml $(tr '\r\n' '\n' < subset.txt)

        # Test rest of tests
        pipenv run test-xml $(tr '\r\n' '\n' < launchable-remainder.txt)
      shell: bash


Upload Python Package

# This workflows will upload a Python Package
# For more information see: https://github.com/marketplace/actions/pypi-publish

name: Upload Python Package

on:
  workflow_dispatch:
  push:
    branches:
    - main

jobs:
  tagpr:
    permissions:
      actions: write
      contents: write
      pull-requests: write
    runs-on: ubuntu-latest
    outputs:
      tag: ${{ steps.run-tagpr.outputs.tag }}
    steps:
    - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
    - id: run-tagpr
      uses: Songmu/tagpr@0a9b8e6634db66e773516828c1359dc6e9e8b484 # v1.3.0
      env:
        GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

  deploy:
    needs: tagpr
    if: needs.tagpr.outputs.tag != '' || github.event_name == 'workflow_dispatch'

    runs-on: ubuntu-20.04

    steps:
    - uses: actions/checkout@v4
      with:
        fetch-depth: 0
    - name: Set up Python
      uses: actions/setup-python@v5
      with:
        python-version: '3.x'
    # build and publish package using GitHub Actions workflow
    # https://packaging.python.org/en/latest/guides/publishing-package-distribution-releases-using-github-actions-ci-cd-workflows/
    - name: Install pypa/build
      run: >-
        python -m
        pip install
        build
        --user
    - name: Build a binary wheel and a source tarball
      run: >-
        python -m
        build
        --sdist
        --wheel
        --outdir dist/
        .
    # actual publish
    - name: Publish to PyPI
      uses: pypa/gh-action-pypi-publish@master
      with:
        user: __token__
        password: ${{ secrets.PYPI_API_TOKEN }}
    - name: Actions for Discord
      uses: Ilshidur/action-discord@0.3.2
      env:
        DISCORD_WEBHOOK: ${{ secrets.DISCORD_WEBHOOK }}
      with:
        args: 'Launchable CLI ${{ needs.tagpr.outputs.tag }} is released! https://github.com/launchableinc/cli/releases/tag/${{ needs.tagpr.outputs.tag }}'


Update maven_install.json

name: Update maven_install.json
on:
  pull_request:
    paths:
      - 'WORKSPACE'
jobs:
  update:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
        with:
          ref: ${{ github.event.pull_request.head.ref }}
          # Bot token is needed to ensure that git-push triggers relevant workflows
          # See https://github.com/orgs/community/discussions/27146
          token: ${{ secrets.LAUNCHABLEINC_CI_GITHUB_TOKEN }}
      - name: Set up JDK 17
        uses: actions/setup-java@v4
        with:
          distribution: temurin
          java-version: '17'
      - name: Setup Bazel
        uses: bazelbuild/setup-bazelisk@b39c379c82683a5f25d34f0d062761f62693e0b2 # v3.0.0
      - name: Cache Bazel outputs
        uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4.0.2
        with:
          path: "~/.cache/bazel"
          key: bazel
      - name: Update maven_install.json
        run: |
          bazel run @unpinned_maven//:pin
      - name: Commit updated files
        run: |
          if ! git diff --exit-code --quiet
          then
            git add src/maven_install.json
            git config --local user.email "nobody@launchableinc.com"
            git config --local user.name "File Update GitHub Workflow"
            git commit -m "Update maven_install.json"
            git push
          fi


Build Android APK & Binary

name: Build Android APK & Binary

on:
  workflow_dispatch:
    inputs:
      modelURL:
        description: 'Model URL'
        required: true
        default: https://wenet-1256283475.cos.ap-shanghai.myqcloud.com/models/aishell/20210601_u2%2B%2B_conformer_libtorch.tar.gz

env:
  ANDROID_DIR: runtime/android
  RELEASE_DIR: app/build/outputs/apk/release

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v3
    - name: set up JDK 11
      uses: actions/setup-java@v3
      with:
        java-version: '11'
        distribution: 'temurin'
        cache: gradle

    - name: Prepare model
      run: |
        wget ${{ github.event.inputs.modelURL}}
        tar -xf *.tar.gz
        find . \( -name "final.zip" -o -name "units.txt" \) |\
          xargs -I  {} cp {} ${{ env.ANDROID_DIR }}/app/src/main/assets

    - name: Build with Gradle
      run: |
        cd ${{ env.ANDROID_DIR }}
        chmod +x gradlew
        ./gradlew assembleRelease

    - name: Upload APK
      uses: actions/upload-artifact@v3
      with:
        name: release-apk
        path: ${{ env.ANDROID_DIR }}/${{ env.RELEASE_DIR }}

    - name: Prepare Release Binary
      run: |
        cd ${{ env.ANDROID_DIR }}
        for arch in arm64-v8a x86_64; do
          mkdir $arch
          cp app/.cxx/cmake/release/$arch/decoder_main $arch
          cp `find . -name "pytorch_android-*.aar"`/jni/$arch/* $arch
        done

    - name: Upload arm64-v8a Binary
      uses: actions/upload-artifact@v3
      with:
        name: release-arm64-v8a-binary
        path: ${{ env.ANDROID_DIR }}/arm64-v8a

    - name: Upload x86_64 Binary
      uses: actions/upload-artifact@v3
      with:
        name: release-x86_64-binary
        path: ${{ env.ANDROID_DIR }}/x86_64


Check and Publish Docs

name: "Check and Publish Docs"
on:
  workflow_dispatch:
  pull_request:
    paths:
      - 'docs/**'
      - 'wenet/**.py'
  push:
    branches:
      - main
    paths:
      - 'docs/**'
      - 'wenet/**.py'

jobs:
  docs:
    runs-on: ubuntu-latest
    strategy:
      fail-fast: false
      matrix:
        os: [ubuntu-latest]
        torch: ["2.2.2"]
        python-version: ["3.10"]
    steps:
      - uses: actions/checkout@v1

      - name: Setup Python ${{ matrix.python-version }}
        uses: actions/setup-python@v2
        with:
          python-version: ${{ matrix.python-version }}

      - name: Build doc
        shell: bash
        run: |
          cd docs
          python3 -m pip install -r ./requirements.txt
          make api
          make html

      # add .nojekyll to notice Pages use the _* dirs
      - name: copy the generated site
        if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }}
        run: |
          mkdir public
          touch public/.nojekyll
          cp -r docs/_build/html/* public/

      # push to gh-pages branch
      - name: github pages deploy
        if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }}
        uses: peaceiris/actions-gh-pages@v2.3.1
        env:
          PERSONAL_TOKEN: ${{ secrets.GITHUB_TOKEN  }}
          PUBLISH_BRANCH: gh-pages
          PUBLISH_DIR: public


Build Docker Image

name: Build Docker Image

on:
  workflow_dispatch:

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v3
    - name: Login to DockerHub
      uses: docker/login-action@v1
      with:
        username: ${{ secrets.DOCKERHUB_USERNAME }}
        password: ${{ secrets.DOCKERHUB_TOKEN }}

    - name: Build the wenet docker image
      run: |
        cd runtime/libtorch/docker
        docker build -t wenet:latest .
        docker image tag wenet:latest ${{ secrets.DOCKERHUB_USERNAME }}/wenet:latest
        docker push ${{ secrets.DOCKERHUB_USERNAME }}/wenet:latest

    - name: Build the wenet-mini docker image
      run: |
        rm -rf wenet/*
        mkdir wenet/lib
        root_dir=/home/wenet/runtime/libtorch
        torch_lib=$root_dir/fc_base/libtorch-src/lib
        fst_lib=$root_dir/fc_base/openfst-build/src/lib/.libs
        id=$(docker run -d -it ${{ secrets.DOCKERHUB_USERNAME }}/wenet:latest)
        docker cp $id:$root_dir/build/bin/websocket_server_main wenet
        docker cp $id:$torch_lib/libc10.so wenet/lib
        docker cp $id:$torch_lib/libtorch.so wenet/lib
        docker cp $id:$torch_lib/libtorch_cpu.so wenet/lib
        docker cp $id:$(docker exec $id sh -c "ls ${torch_lib}/libgomp-*") wenet/lib

        ls -al wenet/lib
        cat << EOF > run.sh
        #!/bin/bash
        export LD_LIBRARY_PATH=/home/wenet/lib
        export GLOG_logtostderr=1
        export GLOG_v=2

        model=/home/wenet/model
        /home/wenet/websocket_server_main \
          --port 10086 \
          --chunk_size 16 \
          --model_path \$model/final.zip \
          --unit_path \$model/units.txt 2>&1 | tee server.log
        EOF

        id=$(docker create ubuntu:latest)
        docker cp run.sh $id:/home
        docker cp wenet $id:/home
        docker commit $id wenet-mini:latest
        docker rm -v $id
        docker image tag wenet-mini:latest ${{ secrets.DOCKERHUB_USERNAME }}/wenet-mini:latest
        docker push ${{ secrets.DOCKERHUB_USERNAME }}/wenet-mini:latest


Lint

name: Lint

on:
  pull_request:

jobs:
  quick-checks:
    runs-on: ubuntu-latest
    steps:
      - name: Fetch Wenet
        uses: actions/checkout@v1
      - name: Checkout PR tip
        run: |
          set -eux
          if [[ "${{ github.event_name }}" == "pull_request" ]]; then
            # We are on a PR, so actions/checkout leaves us on a merge commit.
            # Check out the actual tip of the branch.
            git checkout ${{ github.event.pull_request.head.sha }}
          fi
          echo ::set-output name=commit_sha::$(git rev-parse HEAD)
        id: get_pr_tip
      - name: Ensure no tabs
        run: |
          (! git grep -I -l $'\t' -- . ':(exclude)*.txt' ':(exclude)*.svg' ':(exclude)**Makefile' ':(exclude)**/contrib/**' ':(exclude)third_party' ':(exclude).gitattributes' ':(exclude).gitmodules' || (echo "The above files have tabs; please convert them to spaces"; false))
      - name: Ensure no trailing whitespace
        run: |
          (! git grep -I -n $' $' -- . ':(exclude)*.txt' ':(exclude)third_party' ':(exclude).gitattributes' ':(exclude).gitmodules' || (echo "The above files have trailing whitespace; please remove them"; false))

  flake8-py3:
    runs-on: ubuntu-latest
    steps:
      - name: Setup Python
        uses: actions/setup-python@v1
        with:
          python-version: 3.10.14
          architecture: x64
      - name: Fetch Wenet
        uses: actions/checkout@v1
      - name: Checkout PR tip
        run: |
          set -eux
          if [[ "${{ github.event_name }}" == "pull_request" ]]; then
            # We are on a PR, so actions/checkout leaves us on a merge commit.
            # Check out the actual tip of the branch.
            git checkout ${{ github.event.pull_request.head.sha }}
          fi
          echo ::set-output name=commit_sha::$(git rev-parse HEAD)
        id: get_pr_tip
      - name: Run flake8
        run: |
          set -eux
          pip install flake8==3.8.2 flake8-bugbear flake8-comprehensions flake8-executable flake8-pyi==20.5.0 mccabe pycodestyle==2.6.0 pyflakes==2.2.0
          flake8 --version
          flake8
          if [ $? != 0 ]; then exit 1; fi

  cpplint:
    runs-on: ubuntu-latest
    steps:
      - name: Setup Python
        uses: actions/setup-python@v1
        with:
          python-version: 3.10.14
          architecture: x64
      - name: Fetch Wenet
        uses: actions/checkout@v1
      - name: Checkout PR tip
        run: |
          set -eux
          if [[ "${{ github.event_name }}" == "pull_request" ]]; then
            # We are on a PR, so actions/checkout leaves us on a merge commit.
            # Check out the actual tip of the branch.
            git checkout ${{ github.event.pull_request.head.sha }}
          fi
          echo ::set-output name=commit_sha::$(git rev-parse HEAD)
        id: get_pr_tip
      - name: Run cpplint
        run: |
          set -eux
          pip install cpplint==1.6.1
          cpplint --version
          cpplint --recursive .
          if [ $? != 0 ]; then exit 1; fi

  clang-format:
    runs-on: ubuntu-latest
    steps:
      - name: Setup Python
        uses: actions/setup-python@v1
        with:
          python-version: 3.10.14
          architecture: x64
      - name: Fetch Wenet
        uses: actions/checkout@v1
      - name: Checkout PR tip
        run: |
          set -eux
          if [[ "${{ github.event_name }}" == "pull_request" ]]; then
            # We are on a PR, so actions/checkout leaves us on a merge commit.
            # Check out the actual tip of the branch.
            git checkout ${{ github.event.pull_request.head.sha }}
          fi
          echo ::set-output name=commit_sha::$(git rev-parse HEAD)
        id: get_pr_tip
      - name: Run clang-format
        run: |
          set -eux
          pip install clang-format==17.0.6
          clang-format --version
          # find all cxx files in runtime/core (exclude kaldi & path) and dry-run clang-format
          find runtime/core \( -name "*.h" -o -name "*.hpp" -o -name "*.cpp" -o -name "*.cc" \) ! -path "runtime/core/kaldi/*" ! -path "runtime/core/patch/*"  -exec clang-format -style=file --dry-run --Werror --verbose {} +
          if [ $? != 0 ]; then echo "use `clang-format -style=file -i <file>` to inplace edit your files which didn't pass the lint" && exit 1; fi


Build Runtime

name: Build Runtime

on:
  workflow_dispatch:
  pull_request:
    paths:
      - 'runtime/**'

env:
  RUNTIME_DIR: runtime/libtorch
  FC_BASE_DIR: runtime/libtorch/fc_base

jobs:
  build:
    runs-on: ${{ matrix.os }}
    strategy:
      matrix:
        os: [macos-latest, ubuntu-latest]

    steps:
      - uses: actions/checkout@v3
      - name: Cache FC Base
        uses: actions/cache@v3
        with:
          path: ${{ env.FC_BASE_DIR }}
          key: ${{ runner.os }}-fc-base

      - uses: hendrikmuhs/ccache-action@v1.2
        with:
          key: ${{ runner.os }}-build

      - name: Build
        run: |
          export PATH="/usr/lib/ccache:/usr/local/opt/ccache/libexec:$PATH"
          cd ${{ env.RUNTIME_DIR }}
          cmake -B build -DCMAKE_BUILD_TYPE=Release
          cmake --build build -j$(nproc)


Close Stale Issues

name: Close Stale Issues
on:
  schedule:
    - cron: '0 0 * * *'

jobs:
  close-stale-issues:
    if: github.repository == 'wenet-e2e/wenet'
    runs-on: ubuntu-latest
    permissions:
      issues: write
    steps:
      - name: Check for Stale Issues
        uses: actions/stale@v5

      - name: Close Stale Issues
        uses: actions/stale@v5
        with:
          stale-issue-message: 'This issue has been automatically closed due to inactivity.'
          close-issue-message: "This issue was closed because it has been inactive for 7 days
            since being marked as stale. Please reopen if you'd like to work on this further."
          days-before-stale: 60
          days-before-close: 7
          stale-issue-label: stale
          repo-token: ${{ secrets.GITHUB_TOKEN }}


UnitTest

name: UnitTest

on:
  pull_request:
    paths:
      - '**.py'

jobs:
  unit-test:
    runs-on: ${{ matrix.os }}
    strategy:
      max-parallel: 20
      matrix:
        os: [ubuntu-latest]
        python-version: [3.10.14]
    steps:
      - name: Cache Python Packages
        uses: actions/cache@v1
        with:
          path: ~/.cache/pip
          key: ${{ runner.os }}-pip-${{ matrix.python-version }}-${{ hashFiles('**/setup.py') }}
      - name: Setup Python
        uses: actions/setup-python@v1
        with:
          python-version: ${{ matrix.python-version }}
          architecture: x64
      - name: Fetch Wenet
        uses: actions/checkout@v1
      - name: Checkout PR tip
        run: |
          set -eux
          if [[ "${{ github.event_name }}" == "pull_request" ]]; then
            # We are on a PR, so actions/checkout leaves us on a merge commit.
            # Check out the actual tip of the branch.
            git checkout ${{ github.event.pull_request.head.sha }}
          fi
          echo ::set-output name=commit_sha::$(git rev-parse HEAD)
        id: get_pr_tip
      - name: Install Wenet Dependencies
        run: |
          set -eux
          pip install -r requirements.txt
          sudo apt update && sudo apt install -y ffmpeg  libsox-dev libsndfile1
      - name: Run Pytest
        run: |
          set -eux
          pytest --version
          PYTHONPATH="${PYTHONPATH:-}:$(pwd)" pytest -q
          if [ $? != 0 ]; then exit 1; fi


Build Wheels

name: Build Wheels

on:
  workflow_dispatch:

env:
  BINDING_DIR: runtime/binding/python
  FC_BASE_DIR: runtime/binding/python/fc_base

jobs:
  build_wheels:
    name: Build wheels on ${{ matrix.os }}
    runs-on: ${{ matrix.os }}
    strategy:
      matrix:
        os: [ubuntu-20.04, macos-latest, windows-latest]

    steps:
      - uses: actions/checkout@v2

      # Used to host cibuildwheel
      - uses: actions/setup-python@v3
        with:
          python-version: '3.10'

      - name: Build wheels
        uses: pypa/cibuildwheel@v2.11.2
        env:
          CIBW_BUILD_VERBOSITY: 1
          CIBW_BUILD: "cp36-* cp37-* cp38-* cp39-* cp310-*"
          # Disable building PyPy wheels on all platforms
          # Skip 32-bit builds
          CIBW_SKIP: "pp* *-win32 *-manylinux_i686 *-musllinux_*"

          CIBW_REPAIR_WHEEL_COMMAND_LINUX: >
            auditwheel repair --exclude libc10.so --exclude libtorch.so --exclude libtorch_cpu.so -w {dest_dir} {wheel}
          # For MacOS, please see: https://github.com/pypa/cibuildwheel/issues/816
          CIBW_REPAIR_WHEEL_COMMAND_MACOS: >
            REPAIR_LIBRARY_PATH=$FC_BASE_DIR/libtorch-src/lib &&
            DYLD_LIBRARY_PATH=$REPAIR_LIBRARY_PATH delocate-listdeps {wheel} &&
            DYLD_LIBRARY_PATH=$REPAIR_LIBRARY_PATH delocate-wheel --require-archs {delocate_archs} -w {dest_dir} {wheel}
        with:
          package-dir: ${{ env.BINDING_DIR }}
          output-dir: wheelhouse

      - uses: actions/upload-artifact@v2
        with:
          path: ./wheelhouse/*.whl

      - name: Publish on pypi.org
        env:
          TWINE_USERNAME: __token__
          TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }}
        run: |
          python -m pip install -U twine
          python -m twine upload --skip-existing ./wheelhouse/*


Build Windows Runtime

name: Build Windows Runtime

on:
  workflow_dispatch:

env:
  RUNTIME_DIR: runtime/libtorch

jobs:
  build:
    runs-on: windows-latest
    defaults:
      run:
        shell: bash
    steps:
      - uses: actions/checkout@v3
      - name: Build
        run: |
          cd ${{ env.RUNTIME_DIR }}
          cmake -B build -DGRAPH_TOOLS=ON -DCMAKE_BUILD_TYPE=Release -DBUILD_TESTING=OFF
          cmake --build build --config Release -j$(nproc)

      - name: Prepare Release Binary
        run: |
          cd ${{ env.RUNTIME_DIR }}
          mkdir -p wenet/kaldi
          cp build/*.dll wenet
          cp build/api/Release/*.dll wenet
          cp build/bin/Release/*.exe wenet
          cp build/kaldi/Release/*.exe wenet/kaldi

      - name: Upload WeNet Binary
        uses: actions/upload-artifact@v3
        with:
          name: release-wenet-binary
          path: ${{ env.RUNTIME_DIR }}/wenet


build

# Copyright 2021 United Kingdom Research and Innovation
# Copyright 2021 The University of Manchester
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#     http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# Authors:
# CIL Developers, listed at: https://github.com/TomographicImaging/CIL/blob/master/NOTICE.txt
name: build
on:
  release:
    types: [published]
  push:
    branches: [master]
    tags: ['**']
    paths-ignore:
    - 'CHANGELOG.md'
    - 'CITATION.cff'
    - 'LICENSE'
    - 'scripts/**'
    - 'NOTICE.txt'
    - 'README.md'
  pull_request:
    branches: [master]
    paths-ignore:
    - 'CHANGELOG.md'
    - 'CITATION.cff'
    - 'LICENSE'
    - 'scripts/**'
    - 'NOTICE.txt'
    - 'README.md'
jobs:
  test-cuda:
    defaults: {run: {shell: 'bash -el {0}'}}
    runs-on: [self-hosted, python, cuda]
    strategy:
      matrix:
        python-version: [3.11]
        numpy-version: [1.25]
    steps:
    - uses: actions/checkout@v4
      with: {fetch-depth: 0, submodules: recursive}
    - id: reqs
      name: set requirements
      run: |
        envname="${GITHUB_REPOSITORY##*/}-${GITHUB_RUN_ID}.${GITHUB_RUN_NUMBER}"
        echo "envname=$envname" >> $GITHUB_OUTPUT
        sed -ri -e 's/^(name: ).*/\1$envname/' -e '/ python /d' -e 's/(.* numpy) .*/\1=${{ matrix.numpy-version }}/' scripts/requirements-test.yml
    - uses: conda-incubator/setup-miniconda@v3
      with:
        python-version: ${{ matrix.python-version }}
        environment-file: scripts/requirements-test.yml
        activate-environment: ${{ steps.reqs.outputs.envname }}
        run-post: false
    - id: build
      name: build
      run: |
        conda activate "${{ steps.reqs.outputs.envname }}"
        cmake -S . -B ./build -DCMAKE_BUILD_TYPE=RelWithDebInfo -DCONDA_BUILD=ON -DCMAKE_INSTALL_PREFIX="$CONDA_PREFIX"
        cmake --build ./build --target install
    - name: test
      run: |
        conda activate "${{ steps.reqs.outputs.envname }}"
        TESTS_FORCE_GPU=1 python -m unittest discover -v -k tigre -k TIGRE -k astra -k ASTRA -k gpu -k GPU ./Wrappers/Python/test
    - if: always()
      name: Post Run conda-incubator/setup-miniconda@v3
      shell: bash
      run: |
        sed -i '/${{ steps.reqs.outputs.envname }}/d' ~/.profile
        source ~/.profile
        conda env remove -n "${{ steps.reqs.outputs.envname }}"
  test:
    defaults: {run: {shell: 'bash -el {0}'}}
    runs-on: ubuntu-latest
    strategy:
      matrix:
        include:
        - python-version: '3.10'
          numpy-version: 1.23
        - python-version: 3.12
          numpy-version: 1.26
    steps:
    - uses: actions/checkout@v4
      with: {fetch-depth: 0, submodules: recursive}
    - name: set requirements
      run: sed -ri -e '/ python /d' -e 's/(.* numpy) .*/\1=${{ matrix.numpy-version }}/' -e 's/=cuda*//' -e '/tigre/d' scripts/requirements-test.yml
    - uses: conda-incubator/setup-miniconda@v3
      with:
        python-version: ${{ matrix.python-version }}
        environment-file: scripts/requirements-test.yml
        activate-environment: cil_dev
    - name: build
      run: |
        cmake -S . -B ./build -DCMAKE_BUILD_TYPE=RelWithDebInfo -DCONDA_BUILD=ON -DCMAKE_INSTALL_PREFIX="$CONDA_PREFIX"
        cmake --build ./build --target install
    - name: test
      run: python -m unittest discover -v ./Wrappers/Python/test
  conda:
    defaults: {run: {shell: 'bash -el {0}'}}
    runs-on: ubuntu-latest
    strategy:
      matrix:
        python-version: [3.11]
        numpy-version: [1.25]
    steps:
    - uses: actions/checkout@v4
      with:
        fetch-depth: 0
        submodules: recursive
        ref: ${{ github.event.pull_request.head.sha || github.ref }} # fix SHA
    - uses: conda-incubator/setup-miniconda@v3
      with:
        python-version: ${{ matrix.python-version }}
        mamba-version: "*"
        channels: conda-forge
    - name: conda build & test
      working-directory: recipe
      run: |
        conda install boa
        conda mambabuild . -c conda-forge -c intel -c ccpi --python=${{ matrix.python-version }} --numpy=${{ matrix.numpy-version }} --output-folder .
    - name: Upload artifact of the conda package
      uses: actions/upload-artifact@v4
      with:
        name: cil-package
        path: recipe/linux-64/cil*
  docs:
    defaults: {run: {shell: 'bash -el {0}', working-directory: docs}}
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v4
      with:
        fetch-depth: 0
        submodules: recursive
        ref: ${{ github.event.pull_request.head.sha || github.ref }} # fix SHA
    - uses: conda-incubator/setup-miniconda@v3
      with: {python-version: 3.11}
    - uses: ruby/setup-ruby@v1
      with:
        ruby-version: '3.2'
        bundler-cache: true
        cache-version: 0
    - name: install dependencies
      run: |
        conda install -c conda-forge -yq conda-merge
        conda-merge ../scripts/requirements-test.yml docs_environment.yml > environment.yml
        conda env update -n test
        conda list
    - name: build cil
      working-directory: .
      run: |
        cmake -S . -B ./build -DCMAKE_BUILD_TYPE=RelWithDebInfo -DCONDA_BUILD=ON -DCMAKE_INSTALL_PREFIX="$CONDA_PREFIX"
        cmake --build ./build --target install
    - name: checkout docs
      uses: actions/checkout@v4
      with:
        path: docs/build
        ref: gh-pages
    - id: pages
      uses: actions/configure-pages@v5
    - name: update web pages (jekyll)
      run: make JEKYLLOPTS="--baseurl ${{ steps.pages.outputs.base_path }}" web-deps web
      env: {JEKYLL_ENV: production}
    - name: update docs pages (sphinx)
      run: |
        docs_dir="${{ github.ref_name }}"
        docs_dir="${docs_dir//\//_}"
        if test "$docs_dir" = master; then docs_dir=nightly; fi
        make BUILDSUBDIR="$docs_dir" dirhtml
    - uses: actions/upload-artifact@v4
      with:
        name: DocumentationHTML
        path: docs/build
    - name: Push changes
      if: github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags')
      uses: casperdcl/push-dir@v1
      with:
        message: Update documentation
        branch: gh-pages
        dir: docs/build
        nojekyll: true
  docker:
    runs-on: ubuntu-latest
    permissions:
      contents: read
      packages: write
    steps:
    - uses: actions/checkout@v4
      with:
        fetch-depth: 0
        submodules: recursive
        ref: ${{ github.event.pull_request.head.sha || github.ref }} # fix SHA
    - uses: jlumbroso/free-disk-space@v1.3.1
      with:
        docker-images: false
        large-packages: false
    - uses: docker/setup-buildx-action@v3
    - uses: docker/metadata-action@v5
      id: meta
      with:
        images: ghcr.io/${{ github.repository }}
        tags: |
          type=ref,event=branch
          type=semver,pattern={{version}}
          type=semver,pattern={{major}}.{{minor}}
        labels: |
          org.opencontainers.image.licenses=Apache-2.0 AND BSD-3-Clause AND GPL-3.0
    - uses: docker/login-action@v3
      if: github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags')
      with:
        registry: ghcr.io
        username: ${{ github.actor }}
        password: ${{ secrets.GITHUB_TOKEN }}
    - uses: docker/build-push-action@v5
      with:
        cache-from: type=gha
        cache-to: type=gha,mode=max
        context: .
        load: true
        tags: tomographicimaging/cil:test
    - name: test
      run: >
        docker run --rm -v .:/CIL tomographicimaging/cil:test /bin/bash -c
        'python -m unittest discover -v /CIL/Wrappers/Python/test'
    - uses: docker/build-push-action@v5
      with:
        cache-from: type=gha
        cache-to: type=gha,mode=max
        context: .
        push: ${{ github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags') }}
        tags: ${{ steps.meta.outputs.tags }}
        labels: ${{ steps.meta.outputs.labels }}
  pass:
    needs: [test-cuda, test, conda, docs, docker]
    runs-on: ubuntu-latest
    steps: [{run: echo success}]


skip

# https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/collaborating-on-repositories-with-code-quality-features/troubleshooting-required-status-checks#handling-skipped-but-required-checks
name: skip
on:
  pull_request:
    branches: [master]
    paths: # same list as build.yml:on.pull_request.paths-ignore
    - 'CHANGELOG.md'
    - 'CITATION.cff'
    - 'LICENSE'
    - 'scripts/**'
    - 'NOTICE.txt'
    - 'README.md'
jobs:
  pass:
    runs-on: ubuntu-latest
    steps: [{run: echo success}]


common PR

name: common PR
on:
  pull_request:
    paths:
      - "common/**"
      - "requirements*txt"
jobs:
  test-unit-python:
    runs-on: ubuntu-22.04
    strategy:
      matrix:
        python-version: ['3.8.x', '3.9.x', '3.10.x']
    steps:
      - name: Checkout
        uses: actions/checkout@v1
      - name: Setup python ${{ matrix.python-version }}
        uses: actions/setup-python@v1
        with:
          python-version: ${{ matrix.python-version }}
      - name: Install dependencies
        run: make install_deps && pip3 uninstall -y amundsen-common
        working-directory: ./common
      - name: Run python unit tests
        run: make test
        working-directory: ./common


databuilder PR

name: databuilder PR
on:
  pull_request:
    paths:
      - "databuilder/**"
      - "common/**"
      - "requirements-dev.txt"
jobs:
  test-unit-python:
    runs-on: ubuntu-22.04
    strategy:
      matrix:
        python-version: ['3.8.x', '3.9.x', '3.10.x']
    steps:
      - name: Checkout
        uses: actions/checkout@v1
      - name: Setup python ${{ matrix.python-version }}
        uses: actions/setup-python@v1
        with:
          python-version: ${{ matrix.python-version }}
      - name: Install dependencies
        run: make install_deps && pip3 uninstall -y amundsen-common && pip3 install -e ../common
        working-directory: ./databuilder
      - name: Run python unit tests
        run: make test
        working-directory: ./databuilder


Publish docs via GitHub Pages

name: Publish docs via GitHub Pages
on:
  push:
    branches:
      - main

jobs:
  build:
    name: Deploy docs
    runs-on: ubuntu-latest
    steps:
      - name: Checkout main
        uses: actions/checkout@v1
      - name: Checkout submodules using a PAT
        run: |
          git config --file .gitmodules --get-regexp url | while read url; do
            git config --file=.gitmodules $(echo "$url" | sed -E "s/git@github.com:|https:\/\/github.com\//https:\/\/${{ secrets.CI_PAT }}:${{ secrets.CI_PAT }}@github.com\//")
          done
          git submodule sync
          git submodule update --init --recursive
      - name: Deploy docs
        uses: mhausenblas/mkdocs-deploy-gh-pages@master
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}


Publish Release to PyPi

name: Publish Release to PyPi
on:
  release:
    types: [published]
jobs:
  gather-info:
    runs-on: ubuntu-latest
    steps:
      - name: Get module for release
        id: module_folder
        run: echo "::set-output name=module_folder::$(awk '{print $1}' <<< "${{ github.event.release.name }}")"
    outputs:
      module_folder: ${{ steps.module_folder.outputs.module_folder }}
  push-to-pypi:
    runs-on: ubuntu-latest
    needs: gather-info
    steps:
      - name: Checkout code
        uses: actions/checkout@v2
      - name: Setup python 3.8
        uses: actions/setup-python@v1
        with:
          python-version: 3.8
      - name: Add wheel dependency
        run: pip install wheel
      - name: Generate dist
        run: python setup.py sdist bdist_wheel
        working-directory: ${{ needs.gather-info.outputs.module_folder }}
      - name: Publish to PyPI
        uses: pypa/gh-action-pypi-publish@master
        with:
          user: __token__
          password: ${{ secrets.pypi_password }}
          packages_dir: ${{ needs.gather-info.outputs.module_folder }}/dist
  build-and-publish-docker-image:
    name: Build and publish docker image
    needs: gather-info
    runs-on: ubuntu-22.04
    steps:
      - name: Checkout
        uses: actions/checkout@v1
      - name: Login with docker
        run: docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }}
      - name: Publish to Registry for latest
        if: success()
        run: make build-push-image-latest
        working-directory: ${{ needs.gather-info.outputs.module_folder }}
      - name: Publish to Registry for version
        run: make build-push-image-version
        working-directory: ${{ needs.gather-info.outputs.module_folder }}


frontend PR

name: frontend PR
on:
  pull_request:
    paths:
      - "frontend/**"
      - "common/**"
      - "requirements*txt"
jobs:
  test-unit-python:
    runs-on: ubuntu-22.04
    strategy:
      matrix:
        python-version: ['3.8.x', '3.9.x', '3.10.x']
    steps:
      - name: Checkout
        uses: actions/checkout@v1
      - name: Setup python ${{ matrix.python-version }}
        uses: actions/setup-python@v1
        with:
          python-version: ${{ matrix.python-version }}
      - name: Install dependencies
        run: make install_deps && pip3 uninstall -y amundsen-common && pip3 install -e ../common
        working-directory: ./frontend
      - name: Run python unit tests
        run: make test
        working-directory: ./frontend
  test-unit-frontend:
    runs-on: ubuntu-latest
    strategy:
      matrix:
        node-version: [12.x]
    steps:
      - uses: actions/checkout@v2
      - name: Use Node.js ${{ matrix.node-version }}
        uses: actions/setup-node@v1
        with:
          node-version: ${{ matrix.node-version }}
      - name: Install and Lint
        working-directory: ./frontend/amundsen_application/static
        run: |
          npm install
          npm install codecov -g
          npm run lint
      - name: Check and build
        working-directory: ./frontend/amundsen_application/static
        run: |
          npm run betterer
          npm run build --if-present
      - name: Test
        working-directory: ./frontend/amundsen_application/static
        run: npm run test
        env:
          CI: true


license

name: license

on:
  push:
    branches:
      - main
  pull_request:
    branches:
      - main

jobs:
  build:
    runs-on: ubuntu-latest

    steps:
    - uses: actions/checkout@v3
    - name: Set up Go 1.17
      uses: actions/setup-go@v3
      with:
        go-version: 1.17
      id: go
    - name: Install addlicense
      run: |
        export PATH=${PATH}:`go env GOPATH`/bin
        go get -v -u github.com/google/addlicense
    - name: Check license python
      run: |
        export PATH=${PATH}:`go env GOPATH`/bin
        addlicense -check -l mit -c "Amundsen" $(find $PWD -type f -name '*.py')
    - name: Check license tsx
      run: |
        export PATH=${PATH}:`go env GOPATH`/bin
        addlicense -check -l mit -c "Amundsen" $(find $PWD -type f -name '*.tsx')


metadata PR

name: metadata PR
on:
  pull_request:
    paths:
      - "metadata/**"
      - "common/**"
      - "requirements*txt"
jobs:
  test-unit-python:
    runs-on: ubuntu-22.04
    strategy:
      matrix:
        python-version: ['3.8.x', '3.9.x']
    steps:
      - name: Checkout
        uses: actions/checkout@v1
      - name: Setup python ${{ matrix.python-version }}
        uses: actions/setup-python@v1
        with:
          python-version: ${{ matrix.python-version }}
      - name: Install dependencies
        run: make install_deps && pip3 uninstall -y amundsen-common && pip3 install -e ../common
        working-directory: ./metadata
      - name: Run python unit tests
        run: make test
        working-directory: ./metadata
      - name: Codecov
        uses: codecov/codecov-action@v1
        with:
          directory: ./metadata


Monthly Release

name: Monthly Release
on:
  schedule:
    - cron: 0 0 1 * *
  workflow_dispatch:
    logLevel:
      description: "Log level"
      required: true
      default: "warning"
jobs:
  release:
    runs-on: ubuntu-latest
    strategy:
      matrix:
        library: ['common', 'databuilder', 'frontend', 'metadata', 'search']
    env:
      BRANCH_NAME: new-release-${{ matrix.library }}-${{ github.run_id }}
    steps:
      - uses: actions/setup-python@v2
        with:
          python-version: 3.8
      - name: Checkout master
        uses: actions/checkout@v2
        with:
          fetch-depth: "0"
      - name: Semantic release
        id: semantic-release
        run: |
          pip install python-semantic-release
          git config user.name github-actions
          git config user.email github-actions@github.com
          semantic-release version
          echo ::set-output name=version::$(semantic-release print-version --current)
          semantic-release changelog > './CHANGELOG.md'
        working-directory: ./${{ matrix.library }}
      - name: Create release pull request
        uses: peter-evans/create-pull-request@v3
        with:
          token: ${{ secrets.GITHUB_TOKEN }}
          commit-message: Bumped ${{ matrix.library }} version to ${{ steps.semantic-release.outputs.version }}
          committer: github-actions <github-actions@github.com>
          author: github-actions <github-actions@github.com>
          signoff: true
          branch: ${{ env.BRANCH_NAME }}
          delete-branch: true
          title: |
            chore: Bumped ${{ matrix.library }} version for release ${{ steps.semantic-release.outputs.version }}
          body: |
            Bumped ${{ matrix.library }} version to ${{ steps.semantic-release.outputs.version }}
          team-reviewers: amundsen-io/amundsen-committers


no-op

# Because the mono-repo has different test suites for each sub-project,
# it is challenging to use Github's required status checks. For example,
# the front-end specifies node tests, and we'd like to gate PR on their passing.
# However, none of the other projects have those tests. Thus, if you require
# the front-end tests to pass, it will be impossible to land non-frontend PRs.
# However, Github helpfully has the behavior where if there are multiple test
# runners with a single name, if any of them fail, the whole PR will fail. Thus
# this file specifies dummy tests that will always pass.

# The matrix specified here must be a superset of the actual tests run. This
# has the unfortunate side effect of making PRs appear like they have more
# coverage than they actually do, but I think it's relatively minor

# See also:
# * https://github.community/t/github-actions-and-required-checks-in-a-monorepo-using-paths-to-limit-execution/16586/4
# * https://github.community/t/feature-request-conditional-required-checks/16761/2

name: no-op
on: pull_request
jobs:
  test-unit-frontend:
    runs-on: ubuntu-latest
    strategy:
      matrix:
        node-version: [12.x]
    steps:
      - name: Do nothing
        run: exit 0
  test-unit-python:
    runs-on: ubuntu-latest
    strategy:
      matrix:
        python-version: ['3.8.x', '3.9.x', '3.10.x']
    steps:
      - name: Do nothing
        run: exit 0


search PR

name: search PR
on:
  pull_request:
    paths:
      - "search/**"
      - "common/**"
      - "requirements*txt"
jobs:
  test-unit-python:
    runs-on: ubuntu-22.04
    strategy:
      matrix:
        python-version: ['3.8.x', '3.9.x', '3.10.x']
    steps:
      - name: Checkout
        uses: actions/checkout@v1
      - name: Setup python ${{ matrix.python-version }}
        uses: actions/setup-python@v1
        with:
          python-version: ${{ matrix.python-version }}
      - name: Install dependencies
        run: make install_deps && pip3 uninstall -y amundsen-common && pip3 install -e ../common
        working-directory: ./search
      - name: Run python unit tests
        run: make test
        working-directory: ./search


CodeQL

name: "CodeQL"

on:
  push:
    branches: [ "main" ]
  pull_request:
    branches: [ "main" ]

jobs:
  analyze:
    name: Analyze
    runs-on: ubuntu-latest
    permissions:
      actions: read
      contents: read
      security-events: write

    strategy:
      fail-fast: false

    steps:
    - name: Checkout repository
      uses: actions/checkout@v4

    - name: Initialize CodeQL
      uses: github/codeql-action/init@v3
      with:
        languages: python

    - name: Autobuild
      uses: github/codeql-action/autobuild@v3

    - name: Perform CodeQL Analysis
      uses: github/codeql-action/analyze@v3


Commit Message

on: push

name: Commit Message

# NOTE: Skip check on PR so as not to confuse contributors
# NOTE: Also install a PR title checker so we don't mess up merges
jobs:
    commit-msg:

        runs-on: ubuntu-latest

        steps:
        - uses: actions/checkout@v4
          with:
              fetch-depth: 0

        - name: Setup Python
          uses: actions/setup-python@v5
          with:
              python-version: "3.10"

        - name: Install Dependencies
          run: |
            python -m pip install --upgrade pip
            pip install -r cz-requirement.txt

        - name: Check commit history
          run: cz check --rev-range $(git rev-list --all --reverse | head -1)..HEAD


Docs

name: Docs

on:
    push:
        branches: [main]
    release:
        types: [released]
    pull_request:
        types: [opened, synchronize]

jobs:
    docs:
        runs-on: ubuntu-latest

        permissions:
          contents: write

        steps:
        - uses: actions/checkout@v4

        - name: Setup Python
          uses: actions/setup-python@v5
          with:
              python-version: "3.10"

        - name: Install Dependencies
          run: |
            python -m pip install --upgrade pip
            pip install .[doc]

        - name: Build HTML artifact
          run: python build_docs.py

        - name: Upload HTML artifact
          uses: actions/upload-artifact@v4
          with:
              name: DocumentationHTML
              path: docs/_build/ape

        - name: Doctesting
          run: |
            sphinx-build -b doctest docs docs/_build/doctest
            if grep -q '0 failed' docs/_build/doctest/output.txt; then
              echo "All doctests passed!"
            else
              echo "Some doctests failed. See the output below."
              cat docs/_build/doctest/output.txt
              exit 1
            fi

        - name: Commit and publish documentation changes to gh-pages branch
          run: |
              if [[ "${GITHUB_EVENT_NAME}" =~ "pull_request" ]]; then
                echo "skipping 'git commit' step for PR"
              else
                git clone https://github.com/${GITHUB_REPOSITORY} --branch gh-pages --single-branch gh-pages
                cp -r docs/_build/ape/* gh-pages/
                cd gh-pages
                touch .nojekyll
                git config --local user.email "action@github.com"
                git config --local user.name "GitHub Action"
                git add .
                git commit -m "Update documentation" -a || true
              fi
        - name: Push changes
          uses: ad-m/github-push-action@master
          if: ${{ github.event_name != 'pull_request' }}
          with:
              branch: gh-pages
              directory: gh-pages
              github_token: ${{ secrets.GITHUB_TOKEN }}


Release Drafter

name: Release Drafter

on:
  push:
    branches:
      - main

jobs:
  update-draft:
    runs-on: ubuntu-latest
    permissions:
      contents: write
    steps:
      # Drafts your next Release notes as Pull Requests are merged into "main"
      - uses: release-drafter/release-drafter@v5
        with:
          disable-autolabeler: true
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}


PR Title

name: PR Title

on:
  pull_request_target:
    types:
      - opened
      - edited
      - synchronize

jobs:
    pr-title:
        runs-on: ubuntu-latest

        steps:
        - uses: actions/checkout@v4

        - name: Setup Python
          uses: actions/setup-python@v5
          with:
              python-version: "3.10"

        - name: Install Dependencies
          run: |
            python -m pip install --upgrade pip
            pip install -r cz-requirement.txt

        - name: Check PR Title
          env:
              TITLE: ${{ github.event.pull_request.title }}
          run: cz check --message "$TITLE"


Release

name: Release

on:
  release:
    types: [released]

jobs:
  deploy:

    runs-on: ubuntu-latest

    steps:
    - uses: actions/checkout@v4

    - name: Set up Python
      uses: actions/setup-python@v5
      with:
        python-version: "3.10"

    - name: Install dependencies
      run: |
        python -m pip install --upgrade pip
        pip install -e .[release]

    - name: Build
      run: python setup.py sdist bdist_wheel

    - name: Publish
      env:
        TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }}
        TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
      run: twine upload dist/*


Close stale PRs

name: "Close stale PRs"
on:
  schedule:
    - cron: '30 1 * * *'

jobs:
  stale:
    runs-on: ubuntu-latest
    permissions:
      pull-requests: write
    steps:
      - uses: actions/stale@v9
        with:
          stale-pr-message: 'This pull request is considered stale because it has been open 30 days with no activity. Remove stale label, add a comment, or make a new commit, otherwise this PR will be closed in 5 days.'
          close-pr-message: 'This PR was closed because it has been inactive for 35 days.'
          stale-pr-label: "stale"
          close-pr-label: "inactive"
          days-before-pr-stale: 30
          days-before-pr-close: 5
          repo-token: ${{ secrets.GITHUB_TOKEN }}


Test

on: ["push", "pull_request"]

name: Test

concurrency:
  # Cancel older, in-progress jobs from the same PR, same workflow.
  # use run_id if the job is triggered by a push to ensure
  # push-triggered jobs to not get canceled.
  group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
  cancel-in-progress: true

jobs:
    linting:
        runs-on: ubuntu-latest

        steps:
        - uses: actions/checkout@v4

        - name: Setup Python
          uses: actions/setup-python@v5
          with:
              python-version: "3.10"

        - name: Install Dependencies
          run: |
            python -m pip install --upgrade pip
            pip install .[lint]

        - name: Run Black
          run: black --check .

        - name: Run isort
          run: isort --check-only .

        - name: Run flake8
          run: flake8 .

        - name: Run mdformat
          run: mdformat . --check

    type-check:
        runs-on: ubuntu-latest

        steps:
        - uses: actions/checkout@v4

        - name: Setup Python
          uses: actions/setup-python@v5
          with:
              python-version: "3.10"

        - name: Install Dependencies
          run: |
            python -m pip install --upgrade pip
            pip install .[lint,test]

        - name: Run MyPy
          run: mypy .

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

        strategy:
            matrix:
                os: [ubuntu-latest, macos-latest]   # eventually add `windows-latest`
                python-version: [3.9, "3.10", "3.11", "3.12"]

        env:
          GITHUB_ACCESS_TOKEN: ${{ secrets.GITHUB_TOKEN }}

        steps:
        - uses: actions/checkout@v4
          with:
            fetch-depth: 0

        - name: Setup Python
          uses: actions/setup-python@v5
          with:
              python-version: ${{ matrix.python-version }}

        - name: Setup Go
          uses: actions/setup-go@v5
          with:
            go-version: '^1.20.7'

        - name: Install Geth
          uses: gacts/install-geth-tools@v1
          with:
            version: 1.13.11

        - name: Install Dependencies
          run: |
            python -m pip install --upgrade pip
            pip uninstall eth-ape --yes
            pip install .[test]

        - name: Run Functional Tests
          run: pytest tests/functional -m "not fuzzing" -s --cov=src --cov-append -n auto --dist loadgroup

        - name: Run Integration Tests
          run: pytest tests/integration -m "not fuzzing" -s --cov=src --cov-append -n auto --dist loadgroup

    fuzzing:
        runs-on: ubuntu-latest

        strategy:
            fail-fast: true

        steps:
        - uses: actions/checkout@v4

        - name: Setup Python
          uses: actions/setup-python@v5
          with:
              python-version: "3.10"

        - name: Install Dependencies
          run: |
            python -m pip install --upgrade pip
            pip install .[test]

        - name: Run Tests
          run: pytest -m "fuzzing" --no-cov -s


deploy / spaces

name: "deploy / spaces"

on:
  workflow_dispatch:
  workflow_run:
    workflows: ["trigger"]
    types:
      - requested

permissions:
  statuses: write
concurrency:
  group: "${{ github.event.workflow_run.head_repository.full_name }}-${{ github.event.workflow_run.head_branch }}-${{ github.workflow_ref }}"
  cancel-in-progress: true

jobs:
  changes:
    name: "changes"
    runs-on: ubuntu-latest
    outputs:
      should_run: ${{ steps.changes.outputs.should_run }}
      sha: ${{ steps.changes.outputs.sha }}
      pr_number: ${{ steps.changes.outputs.pr_number }}
      source_branch: ${{ steps.changes.outputs.source_branch }}
      source_repo: ${{ steps.changes.outputs.source_repo }}
      merge_sha: ${{ steps.changes.outputs.merge_sha }}
      mergeable: ${{ steps.changes.outputs.mergeable }}
      found_pr: ${{ steps.changes.outputs.found_pr }}
    steps:
      - uses: actions/checkout@v4
      - uses: "gradio-app/gradio/.github/actions/changes@main"
        id: changes
        with:
          type: "functional"
          name: "deploy / spaces"
          token: ${{ secrets.GITHUB_TOKEN }}
          commit_status: false

  comment-spaces-start:
    needs: changes
    uses: "./.github/workflows/comment-queue.yml"
    if: ${{ needs.changes.outputs.should_run == 'true' }}
    secrets:
      gh_token: ${{ secrets.COMMENT_TOKEN }}
    with:
      pr_number: ${{ needs.changes.outputs.pr_number }}
      message: spaces~pending~null
  deploy-spaces:
    outputs:
      space_url: ${{ steps.upload-demo.outputs.SPACE_URL }}
      gradio_version: ${{ steps.get_gradio_version.outputs.gradio_version }}
      js_tarball_url: ${{ steps.upload_js_tarball.outputs.js_tarball_url }}
    needs: changes
    if: ${{ needs.changes.outputs.should_run == 'true' }}
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v4
      with:
        ref: ${{ needs.changes.outputs.merge_sha }}
        repository: ${{ needs.changes.outputs.mergeable == 'true' &&  github.repository || needs.changes.outputs.source_repo }}

    - name: install dependencies
      uses: "gradio-app/gradio/.github/actions/install-all-deps@main"
      with:
        always_install_pnpm: true
        python_version: '3.9'
        build_lite: 'true'

    - name: Package Lite NPM package
      working-directory: js/lite
      run: pnpm pack --pack-destination .
    - name: Upload Lite NPM package
      uses: actions/upload-artifact@v4
      with:
        name: gradio-lite-${{ github.sha }}
        path: js/lite/gradio-lite-*.tgz

    - name: Install pip
      run: python -m pip install build requests
    - name: Get Gradio Version
      id: get_gradio_version
      run: |
        if ${{ github.event_name == 'pull_request' || github.event.workflow_run.event == 'pull_request' }}; then
          echo "GRADIO_VERSION=$(python -c 'import requests;print(requests.get("https://pypi.org/pypi/gradio/json").json()["info"]["version"])')" >> $GITHUB_OUTPUT
          python -c "import os;print(os.environ['GITHUB_REF'].split('/')[2])" > pr_number.txt
        else
          echo "GRADIO_VERSION=$(python -c 'import json; print(json.load(open("gradio/package.json"))["version"])')" >> $GITHUB_OUTPUT
        fi
    - name: Build pr package
      run: |
        python -c 'import json; j = json.load(open("gradio/package.json")); j["version"] = "${{ steps.get_gradio_version.outputs.GRADIO_VERSION }}"; json.dump(j, open("gradio/package.json", "w"))'
        python3 -m build -w

    - name: Set up Demos
      run: |
        python scripts/copy_demos.py https://gradio-builds.s3.amazonaws.com/${{ needs.changes.outputs.sha }}/gradio-${{ steps.get_gradio_version.outputs.GRADIO_VERSION }}-py3-none-any.whl \
        "gradio-client @ git+https://github.com/gradio-app/gradio@${{ needs.changes.outputs.sha }}#subdirectory=client/python"
    - name: Upload wheel
      run: |
        export AWS_ACCESS_KEY_ID=${{ secrets.PR_DEPLOY_KEY }}
        export AWS_SECRET_ACCESS_KEY=${{ secrets.PR_DEPLOY_SECRET }}
        export AWS_DEFAULT_REGION=us-east-1
        aws s3 cp dist/gradio-${{ steps.get_gradio_version.outputs.GRADIO_VERSION }}-py3-none-any.whl s3://gradio-builds/${{ needs.changes.outputs.sha  }}/
    - name: Create and Upload JS Client Tarball to S3
      id: upload_js_tarball
      continue-on-error: true
      run: |
        cd client/js
        tarball_name=$(npm pack)
        export AWS_ACCESS_KEY_ID=${{ secrets.PR_DEPLOY_KEY }}
        export AWS_SECRET_ACCESS_KEY=${{ secrets.PR_DEPLOY_SECRET }}
        export AWS_DEFAULT_REGION=us-east-1
        aws s3 cp $tarball_name s3://gradio-builds/${{ needs.changes.outputs.sha }}/$tarball_name
        echo "js_tarball_url=https://gradio-builds.s3.amazonaws.com/${{ needs.changes.outputs.sha }}/$tarball_name" >> $GITHUB_OUTPUT
    - name: Install Hub Client Library
      run: pip install huggingface-hub==0.23.2
    - name: Upload demo to spaces
      if: github.event.workflow_run.event == 'pull_request'
      id: upload-demo
      run: |
        python scripts/upload_demo_to_space.py all_demos \
        gradio-pr-deploys/pr-${{ needs.changes.outputs.pr_number }}-all-demos \
        ${{ secrets.SPACES_DEPLOY_TOKEN }} \
        --gradio-version ${{ steps.get_gradio_version.outputs.GRADIO_VERSION }} > url.txt
        echo "SPACE_URL=$(cat url.txt)" >> $GITHUB_OUTPUT
    - name: Upload Website Demos
      if: github.event_name == 'workflow_dispatch'
      id: upload-website-demos
      run: |
        python scripts/upload_website_demos.py --AUTH_TOKEN ${{ secrets.WEBSITE_SPACES_DEPLOY_TOKEN }} \
        --WHEEL_URL https://gradio-builds.s3.amazonaws.com/${{ needs.changes.outputs.sha }}/ \
        --CLIENT_URL "gradio-client @ git+https://github.com/gradio-app/gradio@${{ needs.changes.outputs.sha }}#subdirectory=client/python" \
        --GRADIO_VERSION ${{ steps.get_gradio_version.outputs.GRADIO_VERSION }}
    - name: log
      run: |
        echo ${{github.event.workflow_run.event }}
        echo ${{ github.event.workflow_run.conclusion }}

  comment-spaces-success:
    uses: "./.github/workflows/comment-queue.yml"
    needs: [deploy-spaces, changes]
    if: needs.deploy-spaces.result == 'success' && needs.changes.outputs.found_pr == 'true'
    secrets:
      gh_token: ${{ secrets.COMMENT_TOKEN }}
    with:
      pr_number: ${{ needs.changes.outputs.pr_number }}
      message: spaces~success~${{ needs.deploy-spaces.outputs.space_url }}
      additional_text: |
        **Install Gradio from this PR**
        ```bash
        pip install https://gradio-builds.s3.amazonaws.com/${{ needs.changes.outputs.sha }}/gradio-${{ needs.deploy-spaces.outputs.gradio_version }}-py3-none-any.whl
        ```

        **Install Gradio Python Client from this PR**
        ```bash
        pip install "gradio-client @ git+https://github.com/gradio-app/gradio@${{ needs.changes.outputs.sha }}#subdirectory=client/python"
        ```

        **Install Gradio JS Client from this PR**
        ```bash
        npm install ${{ needs.deploy-spaces.outputs.js_tarball_url }}
        ```
  comment-spaces-failure:
    uses: "./.github/workflows/comment-queue.yml"
    needs: [deploy-spaces, changes]
    if: always() && needs.deploy-spaces == 'failure' && needs.changes.outputs.found_pr == 'true'
    secrets:
      gh_token: ${{ secrets.COMMENT_TOKEN }}
    with:
      pr_number: ${{ needs.changes.outputs.pr_number }}
      message: spaces~failure~https://github.com/gradio-app/gradio/actions/runs/${{github.run_id}}/


Delete Stale Spaces

name: Delete Stale Spaces

on:
  schedule:
    - cron: '0 0 * * *'
  workflow_dispatch:
    inputs:
      daysStale:
        description: 'How stale a space needs to be to be deleted (days)'
        required: true
        default: '7'

jobs:
  delete-old-spaces:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v4
    - name: Install Python
      uses: actions/setup-python@v5
      with:
        python-version: '3.9'
    - name: Install pip
      run: python -m pip install pip wheel requests
    - name: Install Hub Client Library
      run: pip install huggingface-hub==0.9.1
    - name: Set daysStale
      env:
        DEFAULT_DAYS_STALE: '7'
      run: echo "DAYS_STALE=${{ github.event.inputs.daysStale || env.DEFAULT_DAYS_STALE }}" >> $GITHUB_ENV
    - name: Find and delete stale spaces
      run: |
        python scripts/delete_old_spaces.py $DAYS_STALE \
        gradio-pr-deploys \
        ${{ secrets.SPACES_DEPLOY_TOKEN }}


trigger-changeset

name: trigger-changeset
on:
  pull_request:
    types: [opened, synchronize, reopened, edited, labeled, unlabeled]
    branches:
      - main
  issue_comment:
    types: [edited]

jobs:
  changeset:
    permissions: write-all
    runs-on: ubuntu-22.04
    if: github.event.sender.login != 'gradio-pr-bot'
    steps:
      - run: echo "Requesting changeset"


Generate changeset

name: Generate changeset
on:
  workflow_run:
    workflows: ["trigger-changeset"]
    types:
      - completed

env:
  CI: true
  NODE_OPTIONS: "--max-old-space-size=4096"

concurrency:
  group: "${{ github.event.workflow_run.head_repository.full_name }}-${{ github.event.workflow_run.head_branch }}-${{ github.workflow_ref }}"
  cancel-in-progress: true

jobs:
  get-pr:
    runs-on: ubuntu-latest
    if: github.event.workflow_run.conclusion == 'success'
    outputs:
      found_pr: ${{ steps.pr_details.outputs.found_pr }}
      pr_number: ${{ steps.pr_details.outputs.pr_number }}
      source_repo: ${{ steps.pr_details.outputs.source_repo }}
      source_branch: ${{ steps.pr_details.outputs.source_branch }}
    steps:
    - name: get pr details
      id: pr_details
      uses: gradio-app/github/actions/find-pr@main
      with:
        github_token: ${{ secrets.GITHUB_TOKEN }}
  comment-changes-start:
    uses: "./.github/workflows/comment-queue.yml"
    needs: get-pr
    secrets:
      gh_token: ${{ secrets.COMMENT_TOKEN }}
    with:
      pr_number: ${{ needs.get-pr.outputs.pr_number }}
      message: changes~pending~null
  version:
    permissions: write-all
    name: static checks
    needs: get-pr
    runs-on: ubuntu-22.04
    if: needs.get-pr.outputs.found_pr == 'true'
    outputs:
      skipped: ${{ steps.version.outputs.skipped }}
      comment_url: ${{ steps.version.outputs.comment_url }}
    steps:
      - uses: actions/checkout@v4
        with:
          repository: ${{ needs.get-pr.outputs.source_repo }}
          ref: ${{ needs.get-pr.outputs.source_branch }}
          fetch-depth: 0
          token: ${{ secrets.COMMENT_TOKEN }}
      - name: generate changeset
        id: version
        uses: "gradio-app/github/actions/generate-changeset@main"
        with:
          github_token: ${{ secrets.COMMENT_TOKEN }}
          main_pkg: gradio
          pr_number: ${{ needs.get-pr.outputs.pr_number }}
          branch_name: ${{ needs.get-pr.outputs.source_branch }}
  comment-changes-skipped:
    uses: "./.github/workflows/comment-queue.yml"
    needs: [get-pr, version]
    if: needs.version.result == 'success' && needs.version.outputs.skipped == 'true'
    secrets:
      gh_token: ${{ secrets.COMMENT_TOKEN }}
    with:
      pr_number: ${{ needs.get-pr.outputs.pr_number }}
      message: changes~warning~https://github.com/gradio-app/gradio/actions/runs/${{github.run_id}}/
  comment-changes-success:
    uses: "./.github/workflows/comment-queue.yml"
    needs: [get-pr, version]
    if: needs.version.result == 'success' && needs.version.outputs.skipped == 'false'
    secrets:
      gh_token: ${{ secrets.COMMENT_TOKEN }}
    with:
      pr_number: ${{ needs.get-pr.outputs.pr_number }}
      message: changes~success~${{ needs.version.outputs.comment_url }}
  comment-changes-failure:
    uses: "./.github/workflows/comment-queue.yml"
    needs: [get-pr, version]
    if: always() && needs.version.result == 'failure'
    secrets:
      gh_token: ${{ secrets.COMMENT_TOKEN }}
    with:
      pr_number: ${{ needs.get-pr.outputs.pr_number }}
      message: changes~failure~https://github.com/gradio-app/gradio/actions/runs/${{github.run_id}}/


name: Comment on pull request without race conditions

on:
  workflow_call:
    inputs:
      pr_number:
        type: string
      message:
        required: true
        type: string
      tag:
        required: false
        type: string
        default: "previews"
      additional_text:
        required: false
        type: string
        default: ""
    secrets:
      gh_token:
        required: true

jobs:
  comment:
    concurrency:
      group: ${{inputs.pr_number || inputs.tag}}
    runs-on: ubuntu-latest
    steps:
      - name: comment on pr
        uses: "gradio-app/github/actions/comment-pr@main"
        with:
          gh_token: ${{ secrets.gh_token }}
          tag: ${{ inputs.tag }}
          pr_number: ${{ inputs.pr_number}}
          message: ${{ inputs.message }}
          additional_text: ${{ inputs.additional_text }}


deploy / website

name: "deploy / website"

on:
  workflow_run:
    workflows: ["trigger"]
    types:
      - requested

permissions:
  statuses: write

concurrency:
  group: "${{ github.event.workflow_run.head_repository.full_name }}-${{ github.event.workflow_run.head_branch }}-${{ github.workflow_ref }}"
  cancel-in-progress: true

env:
  VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }}
  VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }}

jobs:
  changes:
    name: "changes"
    runs-on: ubuntu-latest
    outputs:
      should_run: ${{ steps.changes.outputs.should_run }}
      sha: ${{ steps.changes.outputs.sha }}
      merge_sha: ${{ steps.changes.outputs.merge_sha }}
      pr_number: ${{ steps.changes.outputs.pr_number }}
      source_branch: ${{ steps.changes.outputs.source_branch }}
      source_repo: ${{ steps.changes.outputs.source_repo }}
      found_pr: ${{ steps.changes.outputs.found_pr }}
      mergeable: ${{ steps.changes.outputs.mergeable }}
    steps:
      - uses: actions/checkout@v4
      - uses: "gradio-app/gradio/.github/actions/changes@main"
        id: changes
        with:
          type: "website"
          token: ${{ secrets.GITHUB_TOKEN }}
          commit_status: false
  comment-deploy-start:
    needs: changes
    uses: "./.github/workflows/comment-queue.yml"
    secrets:
      gh_token: ${{ secrets.COMMENT_TOKEN }}
    with:
      pr_number: ${{ needs.changes.outputs.pr_number }}
      message: website~pending~null
  deploy-website:
    name: "deploy-website"
    runs-on: ubuntu-latest
    needs: changes
    if: needs.changes.outputs.should_run == 'true'
    outputs:
      vercel_url: ${{ steps.output_url.outputs.vercel_url }}
    steps:
      - uses: actions/checkout@v4
        with:
          ref: ${{ needs.changes.outputs.merge_sha }}
          repository: ${{ needs.changes.outputs.mergeable == 'true' &&  github.repository || needs.changes.outputs.source_repo }}
      - name: install dependencies
        uses: "gradio-app/gradio/.github/actions/install-all-deps@main"
        with:
          always_install_pnpm: true
          skip_build: true
      - name: build client
        run: pnpm --filter @gradio/client build
      - name: deploy json to aws
        if: needs.changes.outputs.source_branch == 'changeset-release/main' && needs.changes.outputs.source_repo == 'gradio-app/gradio'
        run: |
          export AWS_ACCESS_KEY_ID=${{ secrets.AWSACCESSKEYID }}
          export AWS_SECRET_ACCESS_KEY=${{ secrets.AWSSECRETKEY }}
          export AWS_DEFAULT_REGION=us-west-2
          version=$(jq -r .version js/_website/src/lib/json/version.json)
          aws s3 cp ./js/_website/src/lib/json/ s3://gradio-docs-json/$version/ --recursive
          aws s3 cp ./js/_website/src/lib/templates/ s3://gradio-docs-json/$version/templates/ --recursive
      - name: Install Vercel CLI
        run: pnpm install --global vercel@latest
      # preview
      - name: Pull Vercel Environment Information
        shell: bash
        if: needs.changes.outputs.found_pr == 'true'
        run: vercel pull --yes --environment=preview --token=${{ secrets.VERCEL_TOKEN }}
      - name: Build Project Artifacts
        if: needs.changes.outputs.found_pr == 'true'
        shell: bash
        run: vercel build --token=${{ secrets.VERCEL_TOKEN }}
      - name: Deploy Project Artifacts to Vercel
        if: needs.changes.outputs.found_pr == 'true'
        id: output_url
        shell: bash
        run: echo "vercel_url=$(vercel deploy --prebuilt --token=${{ secrets.VERCEL_TOKEN }})" >> $GITHUB_OUTPUT
      # production
      - name: Pull Vercel Environment Information
        if: needs.changes.outputs.source_repo == 'gradio-app/gradio' && needs.changes.outputs.source_branch == 'main'
        shell: bash
        run: vercel pull --yes --environment=production --token=${{ secrets.VERCEL_TOKEN }}
      - name: Build Project Artifacts
        if: needs.changes.outputs.source_repo == 'gradio-app/gradio' && needs.changes.outputs.source_branch == 'main'
        shell: bash
        run: vercel build --prod --token=${{ secrets.VERCEL_TOKEN }}
      - name: Deploy Project Artifacts to Vercel
        if: needs.changes.outputs.source_repo == 'gradio-app/gradio' && needs.changes.outputs.source_branch == 'main'
        shell: bash
        run: echo "VERCEL_URL=$(vercel deploy --prebuilt --prod --token=${{ secrets.VERCEL_TOKEN }})" >> $GITHUB_ENV

  comment-deploy-success:
    uses: "./.github/workflows/comment-queue.yml"
    needs: [deploy-website, changes]
    if: needs.deploy-website.result == 'success' && needs.changes.outputs.found_pr == 'true'
    secrets:
      gh_token: ${{ secrets.COMMENT_TOKEN }}
    with:
      pr_number: ${{ needs.changes.outputs.pr_number }}
      message: website~success~${{needs.deploy-website.outputs.vercel_url}}
  comment-deploy-failure:
    uses: "./.github/workflows/comment-queue.yml"
    needs: [deploy-website, changes]
    if: always() && needs.deploy-website.result == 'failure' && needs.changes.outputs.found_pr == 'true'
    secrets:
      gh_token: ${{ secrets.COMMENT_TOKEN }}
    with:
      pr_number: ${{ needs.changes.outputs.pr_number }}
      message: website~failure~https://github.com/gradio-app/gradio/actions/runs/${{github.run_id}}/


test / python

name: "test / python"

on:
  workflow_run:
    workflows: ["trigger"]
    types:
      - requested

permissions:
  statuses: write

concurrency:
  group: "${{ github.event.workflow_run.head_repository.full_name }}-${{ github.event.workflow_run.head_branch }}-${{ github.workflow_ref }}"
  cancel-in-progress: true

env:
  NODE_OPTIONS: "--max-old-space-size=4096"
  HF_TOKEN: ${{ secrets.HF_TOKEN }}

jobs:
  changes:
    name: "changes"
    runs-on: ubuntu-latest
    continue-on-error: true
    outputs:
      should_run: ${{ steps.changes.outputs.should_run }}
      sha: ${{ steps.changes.outputs.sha }}
      pr_number: ${{ steps.changes.outputs.pr_number }}
      source_branch: ${{ steps.changes.outputs.source_branch }}
      source_repo: ${{ steps.changes.outputs.source_repo }}
      merge_sha: ${{ steps.changes.outputs.merge_sha }}
      labels: ${{ steps.changes.outputs.labels }}
      mergeable: ${{ steps.changes.outputs.mergeable }}
    steps:
      - uses: actions/checkout@v4
      - uses: "gradio-app/gradio/.github/actions/changes@main"
        id: changes
        with:
          type: "gradio"
          name: "test / python / linux"
          token: ${{ secrets.GITHUB_TOKEN }}
  test-python:
    needs: [changes]
    if: needs.changes.outputs.should_run == 'true'
    name: "test-python-${{ matrix.os }}-${{ matrix.test-type == 'flaky' && 'flaky' || 'not-flaky'}}"
    strategy:
      matrix:
        os: ["ubuntu-latest", "windows-latest"]
        test-type: ["not flaky", "flaky"]
        exclude:
          - os: ${{ github.event.workflow_run.event == 'pull_request' && contains( needs.changes.outputs.labels, 'windows-tests') && 'dummy' || 'windows-latest' }}
          - test-type: ${{ github.event.workflow_run.event == 'pull_request' && contains( needs.changes.outputs.labels, 'flaky-tests') && 'dummy' || 'flaky' }}
    runs-on: ${{ matrix.os }}
    continue-on-error: true
    steps:
    - uses: actions/checkout@v4
      with:
        ref: ${{ needs.changes.outputs.merge_sha }}
        repository: ${{ needs.changes.outputs.mergeable == 'true' &&  github.repository || needs.changes.outputs.source_repo }}
    - name: install dependencies
      id: install_deps
      uses: "gradio-app/gradio/.github/actions/install-all-deps@main"
      with:
        python_version: "3.8"
        os: ${{ matrix.os }}
        test: true
    - name: Lint
      if: runner.os == 'Linux'
      run: |
        . venv/bin/activate
        ./scripts/lint_backend.sh
    - name: Typecheck
      if: runner.os == 'Linux'
      run: |
        . venv/bin/activate
        ./scripts/type_check_backend.sh
    - name: Run tests
      run: |
        . ${{steps.install_deps.outputs.venv_activate}}
        python -m pytest -m "${{ matrix.test-type }}"
    - name: do check
      if: always()
      uses: "gradio-app/github/actions/commit-status@main"
      with:
        type: "gradio"
        token: ${{ secrets.GITHUB_TOKEN }}
        pr: ${{ needs.changes.outputs.pr_number }}
        sha: ${{ needs.changes.outputs.sha }}
        name: "test / python / ${{ matrix.os == 'ubuntu-latest' && 'linux' || 'windows'}}"
        result: ${{ job.status }}
        job_id: "test-python-${{ matrix.os }}-${{ matrix.test-type == 'flaky' && 'flaky' || 'not-flaky'}}"


test / js

name: "test / js"

on:
  workflow_run:
    workflows: ["trigger"]
    types:
      - requested

permissions:
  statuses: write

env:
  CI: true
  PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD: "1"
  NODE_OPTIONS: "--max-old-space-size=4096"
  VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }}
  VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }}

concurrency:
  group: "${{ github.event.workflow_run.head_repository.full_name }}-${{ github.event.workflow_run.head_branch }}-${{ github.workflow_ref }}"
  cancel-in-progress: true

jobs:
  changes:
    name: "changes"
    runs-on: ubuntu-latest
    outputs:
      should_run: ${{ steps.changes.outputs.should_run }}
      sha: ${{ steps.changes.outputs.sha }}
      merge_sha: ${{ steps.changes.outputs.merge_sha }}
      pr_number: ${{ steps.changes.outputs.pr_number }}
      source_branch: ${{ steps.changes.outputs.source_branch }}
      source_repo: ${{ steps.changes.outputs.source_repo }}
      mergeable: ${{ steps.changes.outputs.mergeable }}
    steps:
      - uses: actions/checkout@v4
      - uses: "gradio-app/gradio/.github/actions/changes@main"
        id: changes
        with:
          type: "js"
          token: ${{ secrets.GITHUB_TOKEN }}
  test-js:
    needs: changes
    if: needs.changes.outputs.should_run == 'true'
    name: test-js
    runs-on: ubuntu-22.04
    steps:
      - uses: actions/checkout@v4
        with:
          ref: ${{ needs.changes.outputs.merge_sha }}
          repository: ${{ needs.changes.outputs.mergeable == 'true' &&  github.repository || needs.changes.outputs.source_repo }}
      - name: install dependencies
        uses: "gradio-app/gradio/.github/actions/install-frontend-deps@main"
        with:
          always_install_pnpm: true
      - name: build client
        run: pnpm --filter @gradio/client build
      - name: build the wasm module
        run: pnpm --filter @gradio/wasm build
      - name: format check
        run: pnpm format:check
      - name: lint
        run: pnpm lint
      - name: typecheck
        run: pnpm ts:check
      - name: unit tests
        run: pnpm test:run
      - name: client tests
        run: pnpm --filter @gradio/client test
      - name: do check
        if: always()
        uses: "gradio-app/github/actions/commit-status@main"
        with:
          type: "js"
          token: ${{ secrets.GITHUB_TOKEN }}
          pr: ${{ needs.changes.outputs.pr_number }}
          sha: ${{ needs.changes.outputs.sha }}
          name: "test / js"
          result: ${{ job.status }}
          job_id: "test-js"


test / hygiene

name: "test / hygiene"

on:
  workflow_run:
    workflows: ["trigger"]
    types:
      - requested

permissions:
  statuses: write

concurrency:
  group: "${{ github.event.workflow_run.head_repository.full_name }}-${{ github.event.workflow_run.head_branch }}-${{ github.workflow_ref }}"
  cancel-in-progress: true

jobs:
  changes:
    name: "changes"
    runs-on: ubuntu-latest
    outputs:
      should_run: ${{ steps.changes.outputs.should_run }}
      sha: ${{ steps.changes.outputs.sha }}
      pr_number: ${{ steps.changes.outputs.pr_number }}
      source_branch: ${{ steps.changes.outputs.source_branch }}
      source_repo: ${{ steps.changes.outputs.source_repo }}
      merge_sha: ${{ steps.changes.outputs.merge_sha }}
      mergeable: ${{ steps.changes.outputs.mergeable }}
    steps:
      - uses: actions/checkout@v4
      - uses: "gradio-app/gradio/.github/actions/changes@main"
        id: changes
        with:
          type: "all"
          token: ${{ secrets.GITHUB_TOKEN }}
  test-hygiene:
    name: "test-hygiene"
    runs-on: ubuntu-latest
    needs: changes
    if: needs.changes.outputs.should_run == 'true'
    steps:
      - uses: actions/checkout@v4
        with:
          ref: ${{ needs.changes.outputs.merge_sha }}
          repository: ${{ needs.changes.outputs.mergeable == 'true' &&  github.repository || needs.changes.outputs.source_repo }}
      - name: Generate Notebooks
        run: |
          pip install nbformat && python scripts/generate_notebooks.py
      - name: Print Git Status
        run: echo $(git status) && echo $(git diff)
      - name: Assert Notebooks Match
        run: git status | grep "nothing to commit, working tree clean"
      - name: Check for large files
        uses: actionsdesk/lfs-warning@v3.3
        with:
          filesizelimit: 5MB
      - name: do check
        if: always()
        uses: "gradio-app/github/actions/commit-status@main"
        with:
          type: "all"
          token: ${{ secrets.GITHUB_TOKEN }}
          pr: ${{ needs.changes.outputs.pr_number }}
          sha: ${{ needs.changes.outputs.sha }}
          name: "test / hygiene"
          result: ${{ job.status }}
          job_id: "test-hygiene"


test / functional

name: "test / functional"

on:
  workflow_run:
    workflows: ["trigger"]
    types:
      - requested

permissions:
  statuses: write

concurrency:
  group: "${{ github.event.workflow_run.head_repository.full_name }}-${{ github.event.workflow_run.head_branch }}-${{ github.workflow_ref }}"
  cancel-in-progress: true

jobs:
  changes:
    name: "changes"
    runs-on: ubuntu-latest
    outputs:
      should_run: ${{ steps.changes.outputs.should_run }}
      sha: ${{ steps.changes.outputs.sha }}
      merge_sha: ${{ steps.changes.outputs.merge_sha }}
      pr_number: ${{ steps.changes.outputs.pr_number }}
      source_branch: ${{ steps.changes.outputs.source_branch }}
      source_repo: ${{ steps.changes.outputs.source_repo }}
      mergeable: ${{ steps.changes.outputs.mergeable }}
    steps:
      - uses: actions/checkout@v4
      - uses: "gradio-app/gradio/.github/actions/changes@main"
        id: changes
        with:
          type: "functional"
          token: ${{ secrets.GITHUB_TOKEN }}

  test-functional:
    name: "test-functional"
    needs: changes
    if: needs.changes.outputs.should_run == 'true'
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v4
        with:
          ref: ${{ needs.changes.outputs.merge_sha }}
          repository: ${{ needs.changes.outputs.mergeable == 'true' &&  github.repository || needs.changes.outputs.source_repo }}
      - name: install dependencies
        id: install_deps
        uses: "gradio-app/gradio/.github/actions/install-all-deps@main"
        with:
          always_install_pnpm: true
          build_lite: true
      - name: install outbreak_forecast dependencies
        run: |
          . venv/bin/activate
          python -m pip install -r demo/outbreak_forecast/requirements.txt
          python -m pip install -r demo/gradio_pdf_demo/requirements.txt
      - run: pnpm exec playwright install chromium
      - name: run browser tests
        run: |
          . venv/bin/activate
          CI=1 pnpm test:browser
      - name: upload screenshots
        uses: actions/upload-artifact@v4
        if: always()
        with:
          name: playwright-screenshots
          path: |
            ./test-results
      - name: run browser component tests
        run: |
          . venv/bin/activate
          pnpm run test:ct
      - name: run reload mode test
        run: |
          . venv/bin/activate
          pnpm test:browser:reload
      - name: Run Lite E2E tests
        run: |
          . venv/bin/activate
          pnpm --filter @gradio/app test:browser:lite
      - name: do check
        if: always()
        uses: "gradio-app/github/actions/commit-status@main"
        with:
          type: "functional"
          token: ${{ secrets.GITHUB_TOKEN }}
          pr: ${{ needs.changes.outputs.pr_number }}
          sha: ${{ needs.changes.outputs.sha }}
          name: "test / functional"
          result: ${{ job.status }}
          job_id: "test-functional"


test / visual

name: "test / visual"

on:
  workflow_run:
    workflows: ["trigger"]
    types:
      - requested

permissions:
  statuses: write

concurrency:

  group: "${{ github.event.workflow_run.head_repository.full_name }}-${{ github.event.workflow_run.head_branch }}-${{ github.workflow_ref }}"
  cancel-in-progress: true

jobs:
  changes:
    name: "changes"
    runs-on: ubuntu-latest
    outputs:
      should_run: ${{ steps.changes.outputs.should_run }}
      sha: ${{ steps.changes.outputs.sha }}
      pr_number: ${{ steps.changes.outputs.pr_number }}
      source_branch: ${{ steps.changes.outputs.source_branch }}
      source_repo: ${{ steps.changes.outputs.source_repo }}
      labels: ${{ steps.changes.outputs.labels }}
      mergeable: ${{ steps.changes.outputs.mergeable }}
    steps:
      - uses: actions/checkout@v4
      - uses: "gradio-app/gradio/.github/actions/changes@main"
        id: changes
        with:
          type: "visual"
          token: ${{ secrets.GITHUB_TOKEN }}
          name: "UI Tests"
  comment-chromatic-start:
    uses: "./.github/workflows/comment-queue.yml"
    needs: changes
    if: ${{ needs.changes.outputs.should_run == 'true' }}
    secrets:
      gh_token: ${{ secrets.COMMENT_TOKEN }}
    with:
      pr_number: ${{ needs.changes.outputs.pr_number }}
      message: |
        storybook~pending~null
  test-visual:
    name: "test-visual"
    needs: changes
    if: ${{ needs.changes.outputs.should_run == 'true' && github.repository == 'gradio-app/gradio' && !contains(needs.changes.outputs.labels, 'no-visual-update') }}
    runs-on: ubuntu-latest
    outputs:
      changes: ${{ steps.publish-chromatic.outputs.changeCount }}
      errors: ${{ steps.publish-chromatic.outputs.errorCount }}
      storybook_url: ${{ steps.publish-chromatic.outputs.storybookUrl }}
      build_url: ${{ steps.publish-chromatic.outputs.buildUrl }}
    steps:
      - uses: actions/checkout@v4
        with:
            fetch-depth: 0
            ref: ${{ needs.changes.outputs.sha }}
            repository: ${{ needs.changes.outputs.mergeable == 'true' &&  github.repository || needs.changes.outputs.source_repo }}
      - name: install dependencies
        uses: "gradio-app/gradio/.github/actions/install-all-deps@main"
        with:
          always_install_pnpm: true
          skip_build: 'true'
      - name: build client
        run: pnpm --filter @gradio/client build
      - name: generate theme.css
        run: |
          . venv/bin/activate
          python scripts/generate_theme.py --outfile js/storybook/theme.css
      - name: build storybook
        run: pnpm build-storybook --quiet
      - name: publish to chromatic
        id: publish-chromatic
        uses: chromaui/action@v11
        with:
          projectToken: ${{ secrets.CHROMATIC_PROJECT_TOKEN }}
          token: ${{ secrets.GITHUB_TOKEN }}
          onlyChanged: true
          exitOnceUploaded: true

  comment-chromatic-end:
    uses: "./.github/workflows/comment-queue.yml"
    needs: [test-visual, changes]
    secrets:
      gh_token: ${{ secrets.COMMENT_TOKEN }}
    with:
      pr_number: ${{ needs.changes.outputs.pr_number }}
      message: |
        storybook~success~${{ needs.test-visual.outputs.storybook_url }}

  comment-chromatic-fail:
    uses: "./.github/workflows/comment-queue.yml"
    needs: [test-visual, changes]
    if: always() && needs.test-visual.result == 'failure'
    secrets:
      gh_token: ${{ secrets.COMMENT_TOKEN }}
    with:
      pr_number: ${{ needs.changes.outputs.pr_number }}
      message: |
        storybook~failure~https://github.com/gradio-app/gradio/actions/runs/${{github.run_id}}/

# visual~success~${{ needs.chromatic-deployment.outputs.changes }}~${{ needs.chromatic-deployment.outputs.errors }}~${{ needs.chromatic-deployment.outputs.build_url }}

# visual~failure~0~0~https://github.com/gradio-app/gradio/actions/runs/${{github.run_id}}/


publish

name: publish
on:
  push:
    branches:
      - main

env:
  CI: true
  PNPM_CACHE_FOLDER: .pnpm-store
  NODE_OPTIONS: "--max-old-space-size=4096"
jobs:
  version_or_publish:
    runs-on: ubuntu-22.04
    steps:
      - name: checkout repo
        uses: actions/checkout@v4
        with:
          fetch-depth: 0
          persist-credentials: false
      - name: install dependencies
        uses: "gradio-app/gradio/.github/actions/install-all-deps@main"
        with:
          always_install_pnpm: true
          skip_build: 'false'
      - name: Build packages
        run: |
          . venv/bin/activate
          pip install -U build hatch packaging>=23.2  # packaging>=23.2 is needed to build Lite due to https://github.com/pypa/hatch/issues/1381
          pnpm --filter @gradio/client --filter @gradio/lite --filter @gradio/preview build
      - name: create and publish versions
        id: changesets
        uses: changesets/action@v1
        with:
          version: pnpm ci:version
          commit: "chore: update versions"
          title: "chore: update versions"
          publish: pnpm ci:publish
        env:
          NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
          NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
          GITHUB_TOKEN: ${{ secrets.GRADIO_PAT }}
      - name: add label to skip chromatic build
        if: ${{ steps.changesets.outputs.pullRequestNumber != '' && steps.changesets.outputs.pullRequestNumber != 'undefined' }}
        run: gh pr edit "$PR_NUMBER" --add-label "no-visual-update"
        env:
          PR_NUMBER: ${{ steps.changesets.outputs.pullRequestNumber }}
          GITHUB_TOKEN: ${{ secrets.GRADIO_PAT }}
      - name: add label to run flaky tests
        if: ${{ steps.changesets.outputs.pullRequestNumber != '' && steps.changesets.outputs.pullRequestNumber != 'undefined' }}
        run: gh pr edit "$PR_NUMBER" --add-label "flaky-tests"
        env:
          PR_NUMBER: ${{ steps.changesets.outputs.pullRequestNumber }}
          GITHUB_TOKEN: ${{ secrets.GRADIO_PAT }}
      - name: add label to run backend tests on Windows
        if: ${{ steps.changesets.outputs.pullRequestNumber != '' && steps.changesets.outputs.pullRequestNumber != 'undefined' }}
        run: gh pr edit "$PR_NUMBER" --add-label "windows-tests"
        env:
          PR_NUMBER: ${{ steps.changesets.outputs.pullRequestNumber }}
          GITHUB_TOKEN: ${{ secrets.GRADIO_PAT }}
      - name: publish to pypi
        if: steps.changesets.outputs.hasChangesets != 'true'
        uses: "gradio-app/github/actions/publish-pypi@main"
        env:
          AWS_ACCESS_KEY_ID: ${{ secrets.AWSACCESSKEYID }}
          AWS_SECRET_ACCESS_KEY: ${{ secrets.AWSSECRETKEY }}
          AWS_DEFAULT_REGION: us-west-2
        with:
          user: __token__
          passwords: |
            gradio:${{ secrets.PYPI_API_TOKEN }}
            gradio_client:${{ secrets.PYPI_GRADIO_CLIENT_TOKEN }}
      - name: trigger spaces deploy workflow
        env:
          GITHUB_TOKEN: ${{ secrets.COMMENT_TOKEN }}
        run: gh workflow run deploy-spaces.yml


trigger

name: trigger
on:
  pull_request:
    types: [opened, synchronize, reopened, labeled, unlabeled]
    branches:
      - main
  push:
    branches:
      - main

jobs:
  checks:
    permissions: write-all
    runs-on: ubuntu-22.04
    if: github.event.sender.login != 'gradio-pr-bot'
    steps:
      - run: echo "Requesting checks"


build tag

# This workflow will install Python dependencies, run tests and lint with a variety of Python versions when a new tag is created
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions

name: build tag

on:
  push:
    tags:
      - '*'

jobs:
  build:

    runs-on: ubuntu-latest
    strategy:
      matrix:
        python-version: ['3.8', '3.9', '3.10', '3.11']

    steps:
    - uses: actions/checkout@v2
    - name: Set up Python ${{ matrix.python-version }}
      uses: actions/setup-python@v2
      with:
        python-version: ${{ matrix.python-version }}
    - name: Install dependencies
      run: |
        python -m pip install --upgrade pip
        pip install tox tox-gh-actions
    - name: Test with tox
      run: tox

    #   run: |
    #     python -m pip install --upgrade pip
    #     python -m pip install flake8 pytest
    #     if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
    # - name: Lint with flake8
    #   run: |
    #     # stop the build if there are Python syntax errors or undefined names
    #     flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
    #     # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
    #     flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
    # - name: Test with pytest
    #   run: |
    #     pytest