mirror of
https://github.com/gradio-app/gradio.git
synced 2024-12-21 02:19:59 +08:00
154 lines
6.2 KiB
YAML
154 lines
6.2 KiB
YAML
|
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 }}
|
||
|
gradio_version: ${{ steps.changes.outputs.gradio_version }}
|
||
|
steps:
|
||
|
- uses: actions/checkout@v4
|
||
|
- uses: "gradio-app/gradio/.github/actions/changes@main"
|
||
|
id: changes
|
||
|
with:
|
||
|
filter: "functional"
|
||
|
token: ${{ secrets.GITHUB_TOKEN }}
|
||
|
|
||
|
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:
|
||
|
environment: deploy_spaces
|
||
|
outputs:
|
||
|
space_url: ${{ steps.upload-demo.outputs.SPACE_URL }}
|
||
|
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:
|
||
|
- name: Download all artifacts
|
||
|
uses: actions/download-artifact@v4
|
||
|
- name: list artifacts
|
||
|
run: ls -R .
|
||
|
|
||
|
- name: Set wheel name
|
||
|
id: set_wheel_name
|
||
|
run: |
|
||
|
wheel_file=$(find ./gradio-build -maxdepth 1 -type f -name "*.whl" -print -quit)
|
||
|
echo "wheel_name=$wheel_file" >> $GITHUB_OUTPUT
|
||
|
- 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_wheel_name.outputs.wheel_name}}-py3-none-any.whl s3://gradio-pypi-previews/${{ needs.changes.outputs.sha }}/
|
||
|
|
||
|
- name: Set tarball name
|
||
|
id: set_tarball_name
|
||
|
run: |
|
||
|
tar_gz_file=$(find ./js-client-tarball -maxdepth 1 -type f -name "*.tgz" -print -quit)
|
||
|
echo "tarball_name=$tar_gz_file" >> $GITHUB_OUTPUT
|
||
|
- name: Upload JS Client Tarball to S3
|
||
|
id: upload_js_tarball
|
||
|
continue-on-error: true
|
||
|
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 $tarball_name s3://gradio-npm-previews/${{ needs.changes.outputs.sha }}/${{ steps.set_tarball_name.outputs.tarball_name }}
|
||
|
echo "js_tarball_url=https://gradio-npm-previews.s3.amazonaws.com/${{ steps.set_tarball_name.outputs.tarball_name }}" >> $GITHUB_OUTPUT
|
||
|
|
||
|
- name: Install Hub Client Library
|
||
|
run: pip install huggingface-hub==0.23.2
|
||
|
# temporary, but ensures the script cannot be modified in a PR
|
||
|
- name: Get deploy scripts
|
||
|
run: |
|
||
|
curl https://raw.githubusercontent.com/gradio-app/gradio/main/scripts/upload_demo_to_space.py -o scripts/upload_demo_to_space.py
|
||
|
curl https://raw.githubusercontent.com/gradio-app/gradio/main/scripts/upload_website_demos.py -o scripts/upload_website_demos.py
|
||
|
|
||
|
|
||
|
# safe, pulls from main branch
|
||
|
- 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 ${{ needs.changes.outputs.gradio_version }} > url.txt
|
||
|
echo "SPACE_URL=$(cat url.txt)" >> $GITHUB_OUTPUT
|
||
|
# safe, pulls from main branch
|
||
|
- 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 ${{ needs.changes.outputs.gradio_version }}
|
||
|
- name: log
|
||
|
run: |
|
||
|
echo ${{github.event.workflow_run.event }}
|
||
|
echo ${{ github.event.workflow_run.conclusion }}
|
||
|
- name: log context
|
||
|
run: |
|
||
|
echo ${{ toJson(github) }}
|
||
|
|
||
|
comment-spaces-success:
|
||
|
uses: "./.github/workflows/comment-queue.yml"
|
||
|
needs: [deploy-spaces, changes]
|
||
|
if: 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-pypi-previews.s3.amazonaws.com/${{ needs.changes.outputs.sha }}/gradio-${{ needs.changes.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'
|
||
|
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}}/
|