Make ci work (#7233)

* update ci

* test

* test

* test

* test

* test

* test

* test

* test

* editable install

* editable install

* escape backslashes for bash

* escape backslashes for bash

* only generate website json in linux

* that was stupiud

* check ci still works

* please work

* pretty please?

* errr

* now?

* more

* more

* more

* deploy space

* deploy space

* tweaks

* changes

* tweaks

* tweaks

* tweaks

* tweaks

* tweaks

* final tweaks

---------

Co-authored-by: Abubakar Abid <abubakar@huggingface.co>
This commit is contained in:
pngwn 2024-02-01 00:46:55 +00:00 committed by GitHub
parent 18937564ab
commit 4cfd8dcde8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
28 changed files with 882 additions and 885 deletions

151
.github/actions/changes/action.yml vendored Normal file
View File

@ -0,0 +1,151 @@
name: "prepare"
description: "Prepare workflow"
inputs:
type:
description: "Type of workflow"
default: "one of: `gradio`, `python-client`, `js`, `js-client`, `functional`"
token:
description: "Github token"
required: true
name:
description: "Check name"
default: "false"
commit_status:
description: "Whether to create a commit status"
default: "true"
outputs:
should_run:
description: "Whether to run the workflow"
value: ${{ steps.should_run.outputs.should_run }}
pr_number:
description: "PR number"
value: ${{ steps.pr.outputs.pr_number }}
sha:
description: "SHA of the HEAD commit of the PR"
value: ${{ steps.pr.outputs.sha }}
source_repo:
description: "Source repo"
value: ${{ steps.pr.outputs.source_repo }}
source_branch:
description: "Source branch"
value: ${{ steps.pr.outputs.source_branch }}
merge_sha:
description: "SHA of the merged result preview branch"
value: ${{ steps.merge.outputs.merge_sha }}
mergeable:
description: "Whether the PR is mergeable"
value: ${{ steps.merge.outputs.mergeable }}
labels:
description: "Labels on the PR"
value: ${{ steps.pr.outputs.labels }}
found_pr:
description: "Whether a PR was found"
value: ${{ steps.pr.outputs.found_pr }}
runs:
using: "composite"
steps:
- name: "Get PR number"
id: pr
uses: "gradio-app/github/actions/find-pr@main"
with:
github_token: ${{ inputs.token }}
- uses: actions/checkout@v3
with:
repository: ${{ steps.pr.outputs.source_repo }}
ref: ${{ steps.pr.outputs.source_branch }}
fetch-depth: 0
token: ${{ inputs.token }}
- uses: dorny/paths-filter@v2
id: changes
with:
ref: ${{ steps.pr.outputs.source_branch }}
filters: |
gradio:
- 'client/python/**'
- 'gradio/**'
- 'requirements.txt'
- '.github/**'
- 'scripts/**'
- 'test/**'
js:
- 'js/**'
- 'client/js/**'
- '.github/**'
- 'package.json'
- 'pnpm-lock.yaml'
- 'tsconfig.json'
- '.config/**'
functional:
- '.github/**'
- 'client/**'
- 'demo/**'
- 'gradio/**'
- 'js/**'
- 'scripts/**'
- 'globals.d.ts'
- 'package.json'
- 'pnpm-lock.yaml'
- 'pyproject.toml'
- 'requirements.txt'
- '.config/**'
visual:
- '.github/workflows/deploy-chromatic.yml'
- 'js!(/_website)/**'
- 'package.json'
website:
- 'js/_website/**'
- 'package.json'
- 'pnpm-lock.yaml'
- 'guides/**'
- 'README.md'
- 'CHANGELOG.md'
- 'gradio/**'
- 'client/**'
- 'demo/**'
- '.github/deplooy-website.yml'
- name: set env (gradio)
if: ${{ inputs.type == 'gradio' }}
shell: bash
run: echo "SHOULD_RUN=${{ steps.changes.outputs.gradio == 'true' }}" >> $GITHUB_ENV
- name: set env (js)
if: ${{ inputs.type == 'js' }}
shell: bash
run: echo "SHOULD_RUN=${{ steps.changes.outputs.js == 'true' }}" >> $GITHUB_ENV
- name: set env (functional)
if: ${{ inputs.type == 'functional' }}
shell: bash
run: echo "SHOULD_RUN=${{ steps.changes.outputs.functional == 'true' }}" >> $GITHUB_ENV
- name: set env (visual)
if: ${{ inputs.type == 'visual' }}
shell: bash
run: echo "SHOULD_RUN=${{ steps.changes.outputs.visual == 'true' }}" >> $GITHUB_ENV
- name: set end (all)
if: ${{ inputs.type == 'all' }}
shell: bash
run: echo "SHOULD_RUN=true" >> $GITHUB_ENV
- name: set env (website)
if: ${{ inputs.type == 'website' }}
shell: bash
run: echo "SHOULD_RUN=${{ steps.changes.outputs.website == 'true' }}" >> $GITHUB_ENV
- if: ${{ steps.pr.outputs.mergeable == 'false' && steps.pr.outputs.source_branch != 'main' }}
run: echo "SHOULD_RUN=false" >> $GITHUB_ENV
shell: bash
- name: set output
id: should_run
shell: bash
run: echo "should_run=${{ env.SHOULD_RUN }}" >> $GITHUB_OUTPUT
- uses: "gradio-app/github/actions/commit-status@main"
with:
token: ${{ inputs.token }}
pr: ${{ steps.pr.outputs.pr_number }}
sha: ${{ steps.pr.outputs.sha }}
name: ${{ inputs.name }}
changes: ${{ steps.changes.outputs.changes }}
type: ${{ inputs.type }}
init: true
mergeable: ${{ steps.pr.outputs.source_branch == 'main' || steps.pr.outputs.mergeable }}
commit_status: ${{ inputs.commit_status }}

View File

@ -2,7 +2,7 @@ name: 'install all deps'
description: 'Install all deps'
inputs:
always-install-pnpm:
always_install_pnpm:
description: 'Dictates whether or not we should install pnpm & dependencies, regardless of the cache'
default: 'false'
node_auth_token:
@ -14,14 +14,42 @@ inputs:
skip_build:
description: 'Skip build'
default: 'false'
test:
description: 'Test'
default: 'false'
python_version:
description: 'Python version'
default: '3.10'
os:
description: 'OS'
default: 'ubuntu-latest'
outputs:
venv_activate:
description: 'Venv activate'
value: ${{ steps.venv.outputs.venv_activate }}
runs:
using: "composite"
steps:
- name: Set venv binary path (linux)
if: ${{ inputs.os == 'ubuntu-latest' }}
shell: bash
run: |
echo "VENV_ACTIVATE=venv/bin/activate" >> $GITHUB_ENV
- name: Set venv binary path (windows)
if: ${{ inputs.os == 'windows-latest' }}
shell: bash
run: |
echo "VENV_ACTIVATE=venv\\\Scripts\\\activate" >> $GITHUB_ENV
- name: log venv binary path
id: venv
shell: bash
run: |
echo "venv_activate=$VENV_ACTIVATE" >> $GITHUB_OUTPUT
- name: Install Python
uses: actions/setup-python@v5
with:
python-version: 3.8
python-version: ${{ inputs.python_version }}
cache: pip
cache-dependency-path: |
client/python/requirements.txt
@ -37,24 +65,35 @@ runs:
with:
path: |
venv/*
key: gradio-lib-ubuntu-latest-pip-${{ hashFiles('client/python/requirements.txt') }}-${{ hashFiles('requirements.txt') }}-${{ hashFiles('test/requirements.txt') }}
client/python/venv
restore-keys: |
gradio-lib-${{inputs.os}}-latest-pip-
key: gradio-lib-${{inputs.os}}-latest-pip-${{ hashFiles('client/python/requirements.txt') }}-${{ hashFiles('requirements.txt') }}-${{ hashFiles('test/requirements.txt') }}-${{ hashFiles('client/python/test/requirements.txt') }}
- name: Install Gradio and Client Libraries Locally (Linux)
shell: bash
run: |
. venv/bin/activate
python -m pip install -e client/python
python -m pip install -e .
. ${{ env.VENV_ACTIVATE }}
python -m pip install -e client/python
python -m pip install -e ".[oauth]"
- name: Install ffmpeg
uses: FedericoCarboni/setup-ffmpeg@v2
- name: Install test dependencies
if: inputs.test == 'true' && steps.cache.outputs.cache-hit != 'true'
shell: bash
run: |
. ${{ env.VENV_ACTIVATE }}
python -m pip install -r test/requirements.txt
python -m pip install -r client/python/test/requirements.txt
- name: install-frontend
uses: "./.github/actions/install-frontend-deps"
with:
always-install-pnpm: ${{ inputs.always-install-pnpm }}
always_install_pnpm: ${{ inputs.always_install_pnpm }}
node_auth_token: ${{ inputs.node_auth_token }}
npm_token: ${{ inputs.npm_token }}
skip_build: ${{ inputs.skip_build }}
- name: generate json
shell: bash
if: inputs.os == 'ubuntu-latest'
run: |
. venv/bin/activate
. ${{ env.VENV_ACTIVATE }}
python js/_website/generate_jsons/generate.py

View File

@ -2,7 +2,7 @@ name: 'install frontend'
description: 'Install frontend deps'
inputs:
always-install-pnpm:
always_install_pnpm:
description: 'Dictates whether or not we should install pnpm & dependencies, regardless of the cache'
default: 'false'
node_auth_token:
@ -14,6 +14,9 @@ inputs:
skip_build:
description: 'Skip build'
default: 'false'
os:
description: 'OS'
default: 'ubuntu-latest'
runs:
using: "composite"
@ -25,7 +28,6 @@ runs:
gradio/templates/*
key: gradio-lib-front-end-${{ hashFiles('js/**', 'client/js/**')}}
- name: Install pnpm
if: steps.frontend-cache.outputs.cache-hit != 'true' || inputs.always-install-pnpm == 'true'
uses: pnpm/action-setup@v2
with:
version: 8.15
@ -34,15 +36,12 @@ runs:
node-version: 18
cache: pnpm
cache-dependency-path: pnpm-lock.yaml
env:
NODE_AUTH_TOKEN: ${{ inputs.always-install-pnpm }}
NPM_TOKEN: ${{ inputs.always-install-pnpm }}
- name: Install deps
if: steps.frontend-cache.outputs.cache-hit != 'true' || inputs.always-install-pnpm == 'true'
if: steps.frontend-cache.outputs.cache-hit != 'true' || inputs.always_install_pnpm == 'true'
shell: bash
run: pnpm i --frozen-lockfile --ignore-scripts
- name: Build Css
if: inputs.always-install-pnpm == 'true'
if: inputs.always_install_pnpm == 'true'
shell: bash
run: pnpm css
- name: Build frontend

View File

@ -1,244 +0,0 @@
name: gradio-backend
on:
push:
branches:
- "main"
pull_request:
types: [opened, synchronize, reopened, labeled, unlabeled]
concurrency:
group: backend-${{ github.ref }}-${{ github.event_name == 'push' || github.event.inputs.fire != null }}
cancel-in-progress: true
env:
NODE_OPTIONS: "--max-old-space-size=4096"
HF_TOKEN: ${{ secrets.HF_TOKEN }}
jobs:
changes:
runs-on: ubuntu-latest
outputs:
python-client: ${{ steps.changes.outputs.python-client }}
gradio: ${{ steps.changes.outputs.gradio }}
test: ${{ steps.changes.outputs.test }}
workflows: ${{ steps.changes.outputs.workflows }}
scripts: ${{ steps.changes.outputs.scripts }}
client-scripts: ${{ steps.changes.outputs.client-scripts }}
steps:
- uses: actions/checkout@v3
- uses: dorny/paths-filter@v2
id: changes
with:
filters: |
python-client:
- 'client/python/**'
- 'gradio/**'
- 'requirements.txt'
gradio:
- 'client/python/**'
- 'gradio/**'
- 'requirements.txt'
test:
- 'test/**'
workflows:
- '.github/**'
scripts:
- 'scripts/**'
client-test:
needs: [changes]
if: needs.changes.outputs.python-client == 'true' || needs.changes.outputs.workflows == 'true'
strategy:
matrix:
os: ["ubuntu-latest", "windows-latest"]
test-type: ["not flaky", "flaky"]
python-version: ["3.8"]
exclude:
- os: ${{ github.event_name == 'pull_request' && contains( github.event.pull_request.labels.*.name, 'windows-tests') && 'dummy' || 'windows-latest' }}
- test-type: ${{ github.event_name == 'pull_request' && contains( github.event.pull_request.labels.*.name, 'flaky-tests') && 'dummy' || 'flaky' }}
runs-on: ${{ matrix.os }}
continue-on-error: true
steps:
- uses: actions/checkout@v3
- name: Install Python
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
cache: pip
cache-dependency-path: |
client/python/requirements.txt
requirements.txt
test/requirements.txt
- name: Create env
run: |
python -m pip install --upgrade virtualenv
python -m virtualenv venv
- uses: actions/cache@master
id: cache
with:
path: |
client/python/venv/*
key: python-client-${{ runner.os }}-pip-${{ hashFiles('client/python/requirements.txt') }}-${{ hashFiles('client/python/test/requirements.txt') }}
- uses: actions/cache@v4
id: frontend-cache
with:
path: |
gradio/templates/*
key: gradio-lib-front-end-${{ hashFiles('js/**', 'client/js/**')}}
- name: Install pnpm
if: steps.frontend-cache.outputs.cache-hit != 'true'
uses: pnpm/action-setup@v2
with:
version: 8.15
- uses: actions/setup-node@v4
if: steps.frontend-cache.outputs.cache-hit != 'true'
with:
node-version: 18
cache: pnpm
cache-dependency-path: pnpm-lock.yaml
- name: Build Frontend
if: steps.frontend-cache.outputs.cache-hit != 'true'
run: |
pnpm i --frozen-lockfile --ignore-scripts
pnpm build
- name: Install Test Requirements (Linux)
if: runner.os == 'Linux'
run: |
. venv/bin/activate
python -m pip install -r client/python/test/requirements.txt
- name: Install ffmpeg
uses: FedericoCarboni/setup-ffmpeg@v2
- name: Install Gradio and Client Libraries Locally (Linux)
if: runner.os == 'Linux'
run: |
. venv/bin/activate
python -m pip install client/python
python -m pip install ".[oauth]"
- name: Lint (Linux)
if: runner.os == 'Linux'
run: |
. venv/bin/activate
bash client/python/scripts/lint.sh
- name: Tests (Linux)
if: runner.os == 'Linux'
run: |
. venv/bin/activate
python -m pytest -m "${{ matrix.test-type }}" client/python/
- name: Install Test Requirements (Windows)
if: runner.os == 'Windows'
run: |
venv\Scripts\activate
pip install -r client/python/test/requirements.txt
- name: Install Gradio and Client Libraries Locally (Windows)
if: runner.os == 'Windows'
run: |
venv\Scripts\activate
python -m pip install client/python
python -m pip install ".[oauth]"
- name: Tests (Windows)
if: runner.os == 'Windows'
run: |
venv\Scripts\activate
python -m pytest -m "${{ matrix.test-type }}" client/python/
test:
needs: [changes]
if: needs.changes.outputs.gradio == 'true' || needs.changes.outputs.workflows == 'true' || needs.changes.outputs.scripts == 'true' || needs.changes.outputs.test == 'true'
strategy:
matrix:
os: ["ubuntu-latest", "windows-latest"]
test-type: ["not flaky", "flaky"]
python-version: ["3.8"]
exclude:
- os: ${{ github.event_name == 'pull_request' && contains( github.event.pull_request.labels.*.name, 'windows-tests') && 'dummy' || 'windows-latest' }}
- test-type: ${{ github.event_name == 'pull_request' && contains( github.event.pull_request.labels.*.name, 'flaky-tests') && 'dummy' || 'flaky' }}
runs-on: ${{ matrix.os }}
continue-on-error: true
steps:
- uses: actions/checkout@v3
- name: Install Python
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
cache: pip
cache-dependency-path: |
client/python/requirements.txt
requirements.txt
test/requirements.txt
- name: Create env
run: |
python -m pip install --upgrade virtualenv
python -m virtualenv venv
- uses: actions/cache@v4
id: cache
with:
path: |
venv/*
key: gradio-lib-${{ runner.os }}-pip-${{ hashFiles('client/python/requirements.txt') }}-${{ hashFiles('requirements.txt') }}-${{ hashFiles('test/requirements.txt') }}
- uses: actions/cache@v4
id: frontend-cache
with:
path: |
gradio/templates/*
gradio/node/*
key: gradio-lib-front-end-${{ hashFiles('js/**', 'client/js/**')}}
- name: Install pnpm
if: steps.frontend-cache.outputs.cache-hit != 'true'
uses: pnpm/action-setup@v2
with:
version: 8.15
- uses: actions/setup-node@v4
if: steps.frontend-cache.outputs.cache-hit != 'true'
with:
node-version: 18
cache: pnpm
cache-dependency-path: pnpm-lock.yaml
- name: Build frontend
if: steps.frontend-cache.outputs.cache-hit != 'true'
run: |
pnpm i --frozen-lockfile --ignore-scripts
pnpm build
- name: Install Gradio and Client Libraries Locally (Linux)
if: runner.os == 'Linux'
run: |
. venv/bin/activate
python -m pip install client/python
python -m pip install ".[oauth]"
- name: Install Test Dependencies (Linux)
if: steps.cache.outputs.cache-hit != 'true' && runner.os == 'Linux'
run: |
. venv/bin/activate
bash scripts/install_test_requirements.sh
- name: Install ffmpeg
uses: FedericoCarboni/setup-ffmpeg@v2
- name: Lint (Linux)
if: runner.os == 'Linux'
run: |
. venv/bin/activate
bash scripts/lint_backend.sh
- name: Typecheck (Linux)
if: runner.os == 'Linux'
run: |
. venv/bin/activate
bash scripts/type_check_backend.sh
- name: Run tests (Linux)
if: runner.os == 'Linux'
run: |
. venv/bin/activate
python -m pytest -m "${{ matrix.test-type }}" --ignore=client
- name: Install Gradio and Client Libraries Locally (Windows)
if: runner.os == 'Windows'
run: |
venv\Scripts\activate
python -m pip install client/python
python -m pip install ".[oauth]"
- name: Install Test Dependencies (Windows)
if: steps.cache.outputs.cache-hit != 'true' && runner.os == 'Windows'
run: |
venv\Scripts\activate
python -m pip install . -r test/requirements.txt
- name: Run tests (Windows)
if: runner.os == 'Windows'
run: |
venv\Scripts\activate
python -m pytest -m "${{ matrix.test-type }}" --ignore=client
echo "The exit code for pytest was $LASTEXITCODE"

View File

@ -1,76 +0,0 @@
name: Build PR Artifacts
on:
workflow_dispatch:
pull_request:
branches:
- main
jobs:
comment-spaces-start:
uses: "./.github/workflows/comment-queue.yml"
secrets:
gh_token: ${{ secrets.COMMENT_TOKEN }}
with:
pr_number: ${{ github.event.pull_request.number }}
message: spaces~pending~null
build_pr:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Install Python
uses: actions/setup-python@v5
with:
python-version: '3.9'
- name: Install pnpm
uses: pnpm/action-setup@v2
with:
version: 8.15
- uses: actions/setup-node@v4
with:
node-version: 18
cache: pnpm
cache-dependency-path: pnpm-lock.yaml
- name: Install pip
run: python -m pip install build requests
- name: Get PR Number
id: get_pr_number
run: |
if ${{ github.event_name == '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
echo "PR_NUMBER=$(cat pr_number.txt)" >> $GITHUB_OUTPUT
else
echo "GRADIO_VERSION=$(python -c 'import json; print(json.load(open("gradio/package.json"))["version"])')" >> $GITHUB_OUTPUT
echo "PR_NUMBER='main'" >> $GITHUB_OUTPUT
fi
- name: Build pr package
run: |
python -c 'import json; j = json.load(open("gradio/package.json")); j["version"] = "${{ steps.get_pr_number.outputs.GRADIO_VERSION }}"; json.dump(j, open("gradio/package.json", "w"))'
pnpm i --frozen-lockfile --ignore-scripts
pnpm build
python3 -m build -w
env:
NODE_OPTIONS: --max_old_space_size=8192
- name: Upload wheel
uses: actions/upload-artifact@v4
with:
name: gradio-${{ steps.get_pr_number.outputs.GRADIO_VERSION }}-py3-none-any.whl
path: dist/gradio-${{ steps.get_pr_number.outputs.GRADIO_VERSION }}-py3-none-any.whl
- name: Set up Demos
run: |
python scripts/copy_demos.py https://gradio-builds.s3.amazonaws.com/${{ github.sha }}/gradio-${{ steps.get_pr_number.outputs.GRADIO_VERSION }}-py3-none-any.whl \
"gradio-client @ git+https://github.com/gradio-app/gradio@${{ github.sha }}#subdirectory=client/python"
- name: Upload all_demos
uses: actions/upload-artifact@v4
with:
name: all_demos
path: demo/all_demos
- name: Create metadata artifact
run: |
python -c "import json; json.dump({'gh_sha': '${{ github.sha }}', 'pr_number': ${{ steps.get_pr_number.outputs.pr_number }}, 'version': '${{ steps.get_pr_number.outputs.GRADIO_VERSION }}', 'wheel': 'gradio-${{ steps.get_pr_number.outputs.GRADIO_VERSION }}-py3-none-any.whl'}, open('metadata.json', 'w'))"
- name: Upload metadata
uses: actions/upload-artifact@v4
with:
name: metadata.json
path: metadata.json

View File

@ -1,50 +0,0 @@
# This workflow will check if the run.py files in every demo match the run.ipynb notebooks.
name: Check Demos Match Notebooks
on:
pull_request:
types: [opened, synchronize, reopened]
paths:
- 'demo/**'
jobs:
comment-notebook-start:
uses: "./.github/workflows/comment-queue.yml"
secrets:
gh_token: ${{ secrets.COMMENT_TOKEN }}
with:
pr_number: ${{ github.event.pull_request.number }}
message: notebooks~pending~null
check-notebooks:
name: Generate Notebooks and Check
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
with:
ref: ${{ github.event.pull_request.head.ref }}
repository: ${{ github.event.pull_request.head.repo.full_name }}
- name: Generate Notebooks
run: |
pip install nbformat && cd demo && python generate_notebooks.py
- name: Print Git Status
run: echo $(git status) && echo $(git diff)
- name: Assert Notebooks Match
id: assertNotebooksMatch
run: git status | grep "nothing to commit, working tree clean"
- name: Get PR Number
if: always()
run: |
python -c "import os;print(os.environ['GITHUB_REF'].split('/')[2])" > pr_number.txt
echo "PR_NUMBER=$(cat pr_number.txt)" >> $GITHUB_ENV
- name: Upload PR Number
if: always()
run: |
python -c "import json; json.dump({'pr_number': ${{ env.PR_NUMBER }}}, open('metadata.json', 'w'))"
- name: Upload metadata
if: always()
uses: actions/upload-artifact@v4
with:
name: metadata.json
path: metadata.json

121
.github/workflows/deploy+test-visual.yml vendored Normal file
View File

@ -0,0 +1,121 @@
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 }}
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 }}
steps:
- uses: actions/checkout@v3
- uses: "./.github/actions/changes"
id: changes
with:
type: "visual"
token: ${{ secrets.GITHUB_TOKEN }}
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
visual~pending~0~0~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@v3
with:
fetch-depth: 0
ref: ${{ needs.changes.outputs.sha }}
repository: ${{ needs.changes.outputs.source_repo }}
- name: install dependencies
uses: "./.github/actions/install-all-deps"
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@v10
with:
projectToken: ${{ secrets.CHROMATIC_PROJECT_TOKEN }}
token: ${{ secrets.GITHUB_TOKEN }}
onlyChanged: true
exitOnceUploaded: true
- name: do check
if: always()
uses: "gradio-app/github/actions/commit-status@main"
with:
type: "visual"
token: ${{ secrets.GITHUB_TOKEN }}
pr: ${{ needs.changes.outputs.pr_number }}
sha: ${{ needs.changes.outputs.sha }}
name: "test / visual"
result: ${{ job.status }}
job_id: "test-visual"
url: ${{ steps.publish-chromatic.outputs.buildUrl }}
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}}/

View File

@ -1,88 +0,0 @@
name: 'deploy to chromatic'
on:
push:
paths:
- 'js/**'
- 'gradio/themes/**'
- '.github/workflows/deploy-chromatic.yml'
- '!js/_website/**'
jobs:
get-current-pr:
runs-on: ubuntu-latest
outputs:
pr_found: ${{ steps.get-pr.outputs.pr_found }}
pr_number: ${{ steps.get-pr.outputs.number }}
pr_labels: ${{ steps.get-pr.outputs.pr_labels }}
steps:
- uses: 8BitJonny/gh-get-current-pr@3.0.0
id: get-pr
with:
filterOutDraft: true
comment-chromatic-start:
uses: "./.github/workflows/comment-queue.yml"
needs: get-current-pr
secrets:
gh_token: ${{ secrets.COMMENT_TOKEN }}
with:
pr_number: ${{ needs.get-current-pr.outputs.pr_number }}
message: |
storybook~pending~null
visual~pending~0~0~null
chromatic-deployment:
needs: get-current-pr
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 }}
if: ${{ github.repository == 'gradio-app/gradio' && !contains(needs.get-current-pr.outputs.pr_labels, 'no-visual-update') }}
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: install dependencies
uses: "./.github/actions/install-all-deps"
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@v10
with:
projectToken: ${{ secrets.CHROMATIC_PROJECT_TOKEN }}
token: ${{ secrets.GITHUB_TOKEN }}
onlyChanged: true
exitOnceUploaded: true
comment-chromatic-end:
uses: "./.github/workflows/comment-queue.yml"
needs: [chromatic-deployment, get-current-pr]
secrets:
gh_token: ${{ secrets.COMMENT_TOKEN }}
with:
pr_number: ${{ needs.get-current-pr.outputs.pr_number }}
message: |
storybook~success~${{ needs.chromatic-deployment.outputs.storybook_url }}
visual~success~${{ needs.chromatic-deployment.outputs.changes }}~${{ needs.chromatic-deployment.outputs.errors }}~${{ needs.chromatic-deployment.outputs.build_url }}
comment-chromatic-fail:
uses: "./.github/workflows/comment-queue.yml"
needs: [chromatic-deployment, get-current-pr]
if: always() && needs.chromatic-deployment.result == 'failure'
secrets:
gh_token: ${{ secrets.COMMENT_TOKEN }}
with:
pr_number: ${{ needs.get-current-pr.outputs.pr_number }}
message: |
storybook~failure~https://github.com/gradio-app/gradio/actions/runs/${{github.run_id}}/
visual~failure~0~0~https://github.com/gradio-app/gradio/actions/runs/${{github.run_id}}/

View File

@ -1,99 +0,0 @@
name: Deploy PR to Spaces
on:
workflow_run:
workflows: [Build PR Artifacts]
types:
- completed
jobs:
deploy-current-pr:
outputs:
pr_number: ${{ steps.set-outputs.outputs.pr_number }}
space_url: ${{ steps.upload-demo.outputs.SPACE_URL }}
sha: ${{ steps.set-outputs.outputs.gh_sha }}
gradio_version: ${{ steps.set-outputs.outputs.gradio_version }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Install Python
uses: actions/setup-python@v5
with:
python-version: '3.9'
- name: Install pip
run: python -m pip install build requests
- name: Download metadata
run: python scripts/download_artifacts.py ${{github.event.workflow_run.id }} metadata.json ${{ secrets.COMMENT_TOKEN }} --owner ${{ github.repository_owner }}
- run: unzip metadata.json.zip
- name: set outputs
id: set-outputs
run: |
echo "wheel_name=$(python -c 'import json; print(json.load(open("metadata.json"))["wheel"])')" >> $GITHUB_OUTPUT
echo "gh_sha=$(python -c 'import json; print(json.load(open("metadata.json"))["gh_sha"])')" >> $GITHUB_OUTPUT
echo "gradio_version=$(python -c 'import json; print(json.load(open("metadata.json"))["version"])')" >> $GITHUB_OUTPUT
echo "pr_number=$(python -c 'import json; print(json.load(open("metadata.json"))["pr_number"])')" >> $GITHUB_OUTPUT
- name: 'Download wheel'
run: python scripts/download_artifacts.py ${{ github.event.workflow_run.id }} ${{ steps.set-outputs.outputs.wheel_name }} ${{ secrets.COMMENT_TOKEN }} --owner ${{ github.repository_owner }}
- run: unzip ${{ steps.set-outputs.outputs.wheel_name }}.zip
- 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 ${{ steps.set-outputs.outputs.wheel_name }} s3://gradio-builds/${{ steps.set-outputs.outputs.gh_sha }}/
- name: Install Hub Client Library
run: pip install huggingface-hub
- name: 'Download all_demos'
run: python scripts/download_artifacts.py ${{ github.event.workflow_run.id }} all_demos ${{ secrets.COMMENT_TOKEN }} --owner ${{ github.repository_owner }}
- run: unzip all_demos.zip -d all_demos
- run: cp -R all_demos/* demo/all_demos
- 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-${{ steps.set-outputs.outputs.pr_number }}-all-demos \
${{ secrets.SPACES_DEPLOY_TOKEN }} \
--gradio-version ${{ steps.set-outputs.outputs.gradio_version }} > url.txt
echo "SPACE_URL=$(cat url.txt)" >> $GITHUB_OUTPUT
- name: Upload Website Demos
if: >
github.event.workflow_run.event == 'workflow_dispatch' &&
github.event.workflow_run.conclusion == 'success'
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/${{ steps.set-outputs.outputs.gh_sha }}/ \
--GRADIO_VERSION ${{ steps.set-outputs.outputs.gradio_version }}
comment-spaces-success:
uses: "./.github/workflows/comment-queue.yml"
needs: [deploy-current-pr]
if: >
github.event.workflow_run.event == 'pull_request' &&
github.event.workflow_run.conclusion == 'success' &&
needs.deploy-current-pr.result == 'success'
secrets:
gh_token: ${{ secrets.COMMENT_TOKEN }}
with:
pr_number: ${{ needs.deploy-current-pr.outputs.pr_number }}
message: spaces~success~${{ needs.deploy-current-pr.outputs.space_url }}
additional_text: |
**Install Gradio from this PR**
```bash
pip install https://gradio-builds.s3.amazonaws.com/${{ needs.deploy-current-pr.outputs.sha }}/gradio-${{ needs.deploy-current-pr.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.deploy-current-pr.outputs.sha }}#subdirectory=client/python"
```
comment-spaces-failure:
uses: "./.github/workflows/comment-queue.yml"
needs: [deploy-current-pr]
if: always() && needs.deploy-current-pr.result == 'failure'
secrets:
gh_token: ${{ secrets.COMMENT_TOKEN }}
with:
pr_number: ${{ needs.deploy-current-pr.outputs.pr_number }}
message: spaces~failure~https://github.com/gradio-app/gradio/actions/runs/${{github.run_id}}/

147
.github/workflows/deploy-spaces.yml vendored Normal file
View File

@ -0,0 +1,147 @@
name: "deploy / spaces"
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 }}
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 }}
steps:
- uses: actions/checkout@v3
- uses: "./.github/actions/changes"
id: changes
with:
type: "functional"
name: "deploy / spaces"
token: ${{ secrets.GITHUB_TOKEN }}
commit_status: false
comment-spaces-start:
uses: "./.github/workflows/comment-queue.yml"
secrets:
gh_token: ${{ secrets.COMMENT_TOKEN }}
with:
pr_number: ${{ github.event.pull_request.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 }}
needs: changes
if: ${{ needs.changes.outputs.should_run == 'true' }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
ref: ${{ needs.changes.outputs.merge_sha }}
repository: ${{ needs.changes.outputs.source_repo }}
- name: Install Python
uses: actions/setup-python@v5
with:
python-version: '3.9'
- name: Install pnpm
uses: pnpm/action-setup@v2
with:
version: 8.15
- uses: actions/setup-node@v4
with:
node-version: 18
cache: pnpm
cache-dependency-path: pnpm-lock.yaml
- name: Install pip
run: python -m pip install build requests
- name: Get PR Number
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"))'
pnpm i --frozen-lockfile --ignore-scripts
pnpm build
python3 -m build -w
env:
NODE_OPTIONS: --max_old_space_size=8192
- 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: Install Hub Client Library
run: pip install huggingface-hub
- name: Upload demo to spaces
if: github.event.workflow_run.event == 'pull_request' || github.event_name == '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.workflow_run.event == 'workflow_dispatch' &&
github.event.workflow_run.conclusion == 'success'
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 }}/ \
--GRADIO_VERSION ${{ steps.get_gradio_version.outputs.GRADIO_VERSION }}
comment-spaces-success:
uses: "./.github/workflows/comment-queue.yml"
needs: [deploy-spaces, changes]
if: >
github.event_name == 'pull_request' ||
github.event.workflow_run.event == 'pull_request' &&
github.event.workflow_run.conclusion == 'success' &&
needs.deploy-spaces.result == 'success'
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"
```
comment-spaces-failure:
uses: "./.github/workflows/comment-queue.yml"
needs: [deploy-spaces, changes]
if: always() && needs.deploy-spaces == 'failure'
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}}/

View File

@ -1,108 +1,129 @@
name: "deploy website"
name: "deploy / website"
on:
workflow_call:
inputs:
branch_name:
description: "The branch name"
type: string
pr_number:
description: "The PR number"
type: string
secrets:
vercel_token:
description: "Vercel API token"
gh_token:
description: "Github token"
required: true
vercel_org_id:
description: "Vercel organization ID"
required: true
vercel_project_id:
description: "Vercel project ID"
required: true
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 }}
cancel-in-progress: true
env:
VERCEL_ORG_ID: ${{ secrets.vercel_org_id }}
VERCEL_PROJECT_ID: ${{ secrets.vercel_project_id }}
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 }}
steps:
- uses: actions/checkout@v3
- uses: "./.github/actions/changes"
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.gh_token }}
gh_token: ${{ secrets.COMMENT_TOKEN }}
with:
pr_number: ${{ inputs.pr_number }}
pr_number: ${{ needs.changes.outputs.pr_number }}
message: website~pending~null
deploy:
name: "Deploy website"
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@v3
with:
ref: ${{ needs.changes.outputs.merge_sha }}
repository: ${{ needs.changes.outputs.source_repo }}
- name: install dependencies
uses: "./.github/actions/install-frontend-deps"
uses: "./.github/actions/install-all-deps"
with:
always-install-pnpm: true
always_install_pnpm: true
skip_build: true
- name: download artifacts
uses: actions/download-artifact@v4
with:
name: website-json-${{ inputs.pr_number }}
path: |
./js/_website/src/lib/json
- name: echo artifact path
shell: bash
run: ls ./js/_website/src/lib/json
- 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
- name: Install Vercel CLI
shell: bash
run: pnpm install --global vercel@latest
- name: echo outputs
run: |
echo "source_repo=${{ needs.changes.outputs.source_repo }}"
echo "source_branch=${{ needs.changes.outputs.source_branch }}"
echo "found_pr=${{ needs.changes.outputs.found_pr }}"
echo "pr_number=${{ needs.changes.outputs.pr_number }}"
# preview
- name: Pull Vercel Environment Information
shell: bash
if: github.event_name == 'pull_request'
run: vercel pull --yes --environment=preview --token=${{ secrets.vercel_token }}
if: needs.changes.outputs.found_pr == 'true'
run: vercel pull --yes --environment=preview --token=${{ secrets.VERCEL_TOKEN }}
- name: Build Project Artifacts
if: github.event_name == 'pull_request'
if: needs.changes.outputs.found_pr == 'true'
shell: bash
run: vercel build --token=${{ secrets.vercel_token }}
run: vercel build --token=${{ secrets.VERCEL_TOKEN }}
- name: Deploy Project Artifacts to Vercel
if: github.event_name == 'pull_request'
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
run: echo "vercel_url=$(vercel deploy --prebuilt --token=${{ secrets.VERCEL_TOKEN }})" >> $GITHUB_OUTPUT
# production
- name: Pull Vercel Environment Information
if: github.event_name == 'push' && inputs.branch_name == 'main'
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 }}
run: vercel pull --yes --environment=production --token=${{ secrets.VERCEL_TOKEN }}
- name: Build Project Artifacts
if: github.event_name == 'push' && inputs.branch_name == 'main'
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 }}
run: vercel build --prod --token=${{ secrets.VERCEL_TOKEN }}
- name: Deploy Project Artifacts to Vercel
if: github.event_name == 'push' && inputs.branch_name == 'main'
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
- name: echo vercel url
shell: bash
run: echo $VERCEL_URL #add to comment
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
if: needs.deploy.result == 'success'
needs: [deploy-website, changes]
if: needs.deploy-website.result == 'success' && needs.changes.outputs.found_pr == 'true'
secrets:
gh_token: ${{ secrets.gh_token }}
gh_token: ${{ secrets.COMMENT_TOKEN }}
with:
pr_number: ${{ inputs.pr_number }}
message: website~success~${{needs.deploy.outputs.vercel_url}}
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
if: always() && needs.deploy.result == 'failure'
needs: [deploy-website, changes]
if: always() && needs.deploy-website.result == 'failure' && needs.changes.outputs.found_pr == 'true'
secrets:
gh_token: ${{ secrets.gh_token }}
gh_token: ${{ secrets.COMMENT_TOKEN }}
with:
pr_number: ${{ inputs.pr_number }}
message: website~failure~https://github.com/gradio-app/gradio/actions/runs/${{github.run_id}}/
pr_number: ${{ needs.changes.outputs.pr_number }}
message: website~failure~https://github.com/gradio-app/gradio/actions/runs/${{github.run_id}}/

View File

@ -1,21 +0,0 @@
name: Check for large files
on:
pull_request:
jobs:
check-files:
runs-on: ubuntu-latest
if: github.event.pull_request.head.repo.full_name == github.event.pull_request.base.repo.full_name
steps:
- name: Checkout
uses: actions/checkout@v3
with:
ref: ${{ github.event.pull_request.head.ref }}
repository: ${{ github.event.pull_request.head.repo.full_name }}
- name: Check for large files
uses: actionsdesk/lfs-warning@v3.2
with:
filesizelimit: 5MB

View File

@ -1,4 +1,4 @@
name: Changesets
name: publish
on:
push:
branches:
@ -20,7 +20,7 @@ jobs:
- name: install dependencies
uses: "./.github/actions/install-all-deps"
with:
always-install-pnpm: true
always_install_pnpm: true
node_auth_token: ${{ secrets.NPM_TOKEN }}
npm_token: ${{ secrets.NPM_TOKEN }}
skip_build: 'true'

View File

@ -1,47 +0,0 @@
on:
workflow_run:
workflows: [Check Demos Match Notebooks]
types: [completed]
jobs:
get-pr-number:
runs-on: ubuntu-latest
outputs:
pr_number: ${{ steps.pr_number.outputs.pr_number }}
steps:
- uses: actions/checkout@v3
- name: Install Python
uses: actions/setup-python@v5
with:
python-version: '3.9'
- name: Install pip
run: python -m pip install requests
- name: Download metadata
run: python scripts/download_artifacts.py ${{github.event.workflow_run.id }} metadata.json ${{ secrets.COMMENT_TOKEN }} --owner ${{ github.repository_owner }}
- run: unzip metadata.json.zip
- name: Pipe metadata to env
id: pr_number
run: echo "pr_number=$(python -c 'import json; print(json.load(open("metadata.json"))["pr_number"])')" >> $GITHUB_OUTPUT
comment-success:
uses: "./.github/workflows/comment-queue.yml"
if: ${{ github.event.workflow_run.conclusion == 'success' && github.event.workflow_run.name == 'Check Demos Match Notebooks'}}
needs: get-pr-number
secrets:
gh_token: ${{ secrets.COMMENT_TOKEN }}
with:
pr_number: ${{ needs.get-pr-number.outputs.pr_number }}
message: notebooks~success~null
comment-failure:
uses: "./.github/workflows/comment-queue.yml"
if: ${{ github.event.workflow_run.conclusion == 'failure' && github.event.workflow_run.name == 'Check Demos Match Notebooks'}}
needs: get-pr-number
secrets:
gh_token: ${{ secrets.COMMENT_TOKEN }}
with:
pr_number: ${{ needs.get-pr-number.outputs.pr_number }}
message: notebooks~failure~https://github.com/gradio-app/gradio/actions/runs/${{github.run_id}}/
additional_text: |
The demo notebooks don't match the run.py files. Please run this command from the root of the repo and then commit the changes:
```bash
pip install nbformat && cd demo && python generate_notebooks.py
```

81
.github/workflows/test-functional.yml vendored Normal file
View File

@ -0,0 +1,81 @@
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 }}
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 }}
steps:
- uses: actions/checkout@v3
- uses: "./.github/actions/changes"
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@v3
with:
ref: ${{ needs.changes.outputs.merge_sha }}
repository: ${{ needs.changes.outputs.source_repo }}
- name: install dependencies
id: install_deps
uses: "./.github/actions/install-all-deps"
with:
always_install_pnpm: true
- name: install outbreak_forecast dependencies
run: |
. venv/bin/activate
python -m pip install -r demo/outbreak_forecast/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: 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"

65
.github/workflows/test-hygiene.yml vendored Normal file
View File

@ -0,0 +1,65 @@
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 }}
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 }}
steps:
- uses: actions/checkout@v3
- uses: "./.github/actions/changes"
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@v3
with:
ref: ${{ needs.changes.outputs.merge_sha }}
repository: ${{ needs.changes.outputs.source_repo }}
- name: Generate Notebooks
run: |
pip install nbformat && cd demo && python 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.2
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"

89
.github/workflows/test-python.yml vendored Normal file
View File

@ -0,0 +1,89 @@
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 }}
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
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 }}
steps:
- uses: actions/checkout@v3
- uses: "./.github/actions/changes"
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_name == 'pull_request' && contains( github.event.pull_request.labels.*.name, 'windows-tests') && 'dummy' || 'windows-latest' }}
- test-type: ${{ github.event_name == 'pull_request' && contains( github.event.pull_request.labels.*.name, 'flaky-tests') && 'dummy' || 'flaky' }}
runs-on: ${{ matrix.os }}
continue-on-error: true
steps:
- uses: actions/checkout@v3
with:
ref: ${{ needs.changes.outputs.merge_sha }}
repository: ${{ needs.changes.outputs.source_repo }}
- name: install dependencies
id: install_deps
uses: "./.github/actions/install-all-deps"
with:
python_version: "3.8"
os: ${{ matrix.os }}
test: true
- name: Lint
if: runner.os == 'Linux'
run: |
. venv/bin/activate
bash scripts/lint_backend.sh
- name: Typecheck
if: runner.os == 'Linux'
run: |
. venv/bin/activate
bash 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'}}"

78
.github/workflows/tests-js.yml vendored Normal file
View File

@ -0,0 +1,78 @@
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 }}
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 }}
steps:
- uses: actions/checkout@v3
- uses: "./.github/actions/changes"
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@v3
with:
ref: ${{ needs.changes.outputs.merge_sha }}
repository: ${{ needs.changes.outputs.source_repo }}
- name: install dependencies
uses: "./.github/actions/install-frontend-deps"
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: 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"

View File

@ -1,4 +1,4 @@
name: trigger changeset generation
name: trigger
on:
pull_request:
types: [opened, synchronize, reopened, edited, labeled, unlabeled]
@ -8,12 +8,10 @@ on:
types: [edited]
jobs:
version:
checks:
permissions: write-all
name: static checks
runs-on: ubuntu-22.04
if: github.event.sender.login != 'gradio-pr-bot'
steps:
- run: echo ${{ github.event_name }}
- run: echo ${{ github.event.sender.login }}
- run: echo "Triggering changeset generation"
- run: echo "Requesting checks"

View File

@ -1,103 +0,0 @@
name: gradio-ui
on:
push:
branches:
- "main"
pull_request:
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: deploy-${{ github.ref }}-${{ github.event_name == 'push' || github.event.inputs.fire != null }}
cancel-in-progress: true
jobs:
quick-checks:
name: static checks
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v3
- name: install dependencies
uses: "./.github/actions/install-frontend-deps"
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
functional-test:
runs-on: ubuntu-latest
outputs:
source_branch: ${{ steps.pr_details.outputs.source_branch }}
pr_number: ${{ steps.pr_details.outputs.pr_number }}
steps:
- uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac # v4
- name: install dependencies
id: install_deps
uses: "./.github/actions/install-all-deps"
with:
always-install-pnpm: true
- name: get pr details
id: pr_details
uses: gradio-app/github/actions/find-pr@main
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
- name: deploy json to aws
if: steps.pr_details.outputs.source_branch == 'changeset-release/main'
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
- name: install outbreak_forecast dependencies
run: |
. venv/bin/activate
python -m pip install -r demo/outbreak_forecast/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: save artifacts
uses: actions/upload-artifact@v4
with:
name: website-json-${{ steps.pr_details.outputs.pr_number }}
path: |
./js/_website/src/lib/json
deploy_to_vercel:
uses: "./.github/workflows/deploy-website.yml"
needs: functional-test
if: always()
secrets:
gh_token: ${{ secrets.COMMENT_TOKEN }}
vercel_token: ${{ secrets.VERCEL_TOKEN }}
vercel_org_id: ${{ secrets.VERCEL_ORG_ID }}
vercel_project_id: ${{ secrets.VERCEL_PROJECT_ID }}
with:
branch_name: ${{ needs.functional-test.outputs.source_branch }}
pr_number: ${{ needs.functional-test.outputs.pr_number }}

View File

@ -1,8 +0,0 @@
#!/bin/bash -eu
cd "$(dirname ${0})/.."
python3 -m pip install build
rm -rf dist/*
rm -rf build/*
python3 -m build

View File

@ -1,17 +0,0 @@
import json
import sys
import urllib.request
from pathlib import Path
version_file = Path(__file__).parent.parent / "gradio_client" / "package.json"
with version_file.open() as f:
version = json.load(f)["version"]
with urllib.request.urlopen("https://pypi.org/pypi/gradio_client/json") as url:
releases = json.load(url)["releases"]
if version in releases:
print(f"Version {version} already exists on PyPI")
sys.exit(1)
else:
print(f"Version {version} does not exist on PyPI")

View File

@ -1,10 +0,0 @@
#!/bin/bash -eu
cd "$(dirname ${0})/.."
echo "Formatting the client library.. Our style follows the ruff code style."
python -m ruff --fix .
python -m ruff format .
echo "Type checking the client library with pyright"
python -m pyright gradio_client/*.py

View File

@ -1,10 +0,0 @@
#!/bin/bash -eu
cd "$(dirname ${0})/.."
echo "Linting..."
python -m ruff test gradio_client
python -m ruff format --check test gradio_client
echo "Type checking the client library with pyright"
python -m pyright gradio_client/*.py

View File

@ -75,7 +75,7 @@ artifacts = [
"/gradio/_frontend_code",
"*.pyi",
"/gradio/node",
"py.typed"
"py.typed",
]
[tool.hatch.build.targets.wheel.hooks.custom]
@ -101,7 +101,7 @@ exclude = [
"gradio/components/*_plot.py",
"gradio/ipython_ext.py",
"gradio/node/*.py",
"gradio/_frontend_code/*.py"
"gradio/_frontend_code/*.py",
]
[tool.ruff]
@ -119,7 +119,7 @@ ignore = [
"UP007", # use X | Y for type annotations (TODO: can be enabled once Pydantic plays nice with them)
"UP006", # use `list` instead of `List` for type annotations (fails for 3.8)
]
exclude = ["gradio/node/*.py"]
exclude = ["gradio/node/*.py", ".venv/*", "gradio/_frontend_code/*.py"]
[tool.ruff.per-file-ignores]
"demo/*" = [

View File

@ -1,17 +0,0 @@
import json
import sys
import urllib.request
from pathlib import Path
version_file = Path(__file__).parent.parent / "gradio" / "package.json"
with version_file.open() as f:
version = json.load(f)["version"]
with urllib.request.urlopen("https://pypi.org/pypi/gradio/json") as url:
releases = json.load(url)["releases"]
if version in releases:
print(f"Version {version} already exists on PyPI")
sys.exit(1)
else:
print(f"Version {version} does not exist on PyPI")

View File

@ -4,8 +4,6 @@ cd "$(dirname ${0})/.."
echo "Formatting the backend... Our style follows the ruff code style."
python -c "import gradio"
python -m ruff --fix gradio test
python -m ruff format gradio test
bash scripts/type_check_backend.sh
bash client/python/scripts/format.sh # Call the client library's formatting script
python -m ruff --fix gradio test client
python -m ruff format gradio test client
bash scripts/type_check_backend.sh

View File

@ -1,4 +1,4 @@
# component-styles
# component styles
## Textbox