2024-08-06 02:11:24 +08:00
|
|
|
name: "previews-deploy"
|
2024-08-05 22:27:26 +08:00
|
|
|
|
|
|
|
on:
|
|
|
|
workflow_dispatch:
|
|
|
|
workflow_run:
|
2024-08-06 02:21:43 +08:00
|
|
|
workflows: ["previews-build"]
|
2024-08-05 22:27:26 +08:00
|
|
|
types:
|
2024-08-06 02:11:24 +08:00
|
|
|
- completed
|
2024-08-05 22:27:26 +08:00
|
|
|
|
|
|
|
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
|
2024-08-06 02:01:52 +08:00
|
|
|
permissions:
|
|
|
|
actions: read
|
2024-08-05 22:27:26 +08:00
|
|
|
outputs:
|
2024-08-06 02:01:52 +08:00
|
|
|
should_run: ${{ steps.json.outputs.should_run }}
|
|
|
|
sha: ${{ steps.json.outputs.sha }}
|
|
|
|
pr_number: ${{ steps.json.outputs.pr_number }}
|
|
|
|
source_branch: ${{ steps.json.outputs.source_branch }}
|
|
|
|
source_repo: ${{ steps.json.outputs.source_repo }}
|
|
|
|
labels: ${{ steps.json.outputs.labels }}
|
|
|
|
run_id: ${{ steps.json.outputs.run_id }}
|
|
|
|
gradio_version: ${{ steps.json.outputs.gradio_version }}
|
2024-08-05 22:27:26 +08:00
|
|
|
steps:
|
2024-08-06 02:01:52 +08:00
|
|
|
- name: Download artifact
|
|
|
|
uses: actions/download-artifact@v4
|
2024-08-05 22:27:26 +08:00
|
|
|
with:
|
2024-08-06 02:01:52 +08:00
|
|
|
name: changes
|
|
|
|
github-token: ${{ secrets.GITHUB_TOKEN }}
|
|
|
|
run-id: ${{ github.event.workflow_run.id }}
|
|
|
|
- uses: gradio-app/github/actions/json-to-output@main
|
|
|
|
id: json
|
|
|
|
with:
|
|
|
|
path: output.json
|
2024-08-05 22:27:26 +08:00
|
|
|
|
|
|
|
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
|
2024-08-06 02:11:24 +08:00
|
|
|
deploy:
|
2024-08-06 18:54:11 +08:00
|
|
|
name: "previews-deploy"
|
2024-08-05 22:27:26 +08:00
|
|
|
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
|
2024-08-06 03:23:28 +08:00
|
|
|
permissions:
|
|
|
|
actions: read
|
2024-08-05 22:27:26 +08:00
|
|
|
steps:
|
|
|
|
- name: Download all artifacts
|
|
|
|
uses: actions/download-artifact@v4
|
2024-08-06 02:21:43 +08:00
|
|
|
with:
|
|
|
|
run-id: ${{ github.event.workflow_run.id }}
|
2024-08-06 06:34:26 +08:00
|
|
|
github-token: ${{ secrets.GITHUB_TOKEN }}
|
2024-08-05 22:27:26 +08:00
|
|
|
- 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: |
|
2024-08-05 23:22:27 +08:00
|
|
|
export AWS_ACCESS_KEY_ID=${{ secrets.PYPI_PREVIEWS_AWS_S3_ACCESS_KEY }}
|
|
|
|
export AWS_SECRET_ACCESS_KEY=${{ secrets.PYPI_PREVIEWS_AWS_S3_SECRET_ACCESS_KEY }}
|
2024-08-05 22:27:26 +08:00
|
|
|
export AWS_DEFAULT_REGION=us-east-1
|
2024-08-06 06:47:45 +08:00
|
|
|
aws s3 cp ${{ steps.set_wheel_name.outputs.wheel_name}} s3://gradio-pypi-previews/${{ needs.changes.outputs.sha }}/
|
2024-08-05 22:27:26 +08:00
|
|
|
|
|
|
|
- name: Set tarball name
|
|
|
|
id: set_tarball_name
|
|
|
|
run: |
|
|
|
|
tar_gz_file=$(find ./js-client-tarball -maxdepth 1 -type f -name "*.tgz" -print -quit)
|
2024-08-06 07:29:24 +08:00
|
|
|
echo "tarball_path=$tar_gz_file" >> $GITHUB_OUTPUT
|
|
|
|
echo "tarball_name=$(basename $tar_gz_file)" >> $GITHUB_OUTPUT
|
2024-08-05 22:27:26 +08:00
|
|
|
- name: Upload JS Client Tarball to S3
|
|
|
|
id: upload_js_tarball
|
|
|
|
continue-on-error: true
|
|
|
|
run: |
|
2024-08-05 23:22:27 +08:00
|
|
|
export AWS_ACCESS_KEY_ID=${{ secrets.NPM_PREVIEWS_AWS_S3_ACCESS_KEY }}
|
|
|
|
export AWS_SECRET_ACCESS_KEY=${{ secrets.NPM_PREVIEWS_AWS_S3_SECRET_ACCESS_KEY }}
|
2024-08-05 22:27:26 +08:00
|
|
|
export AWS_DEFAULT_REGION=us-east-1
|
2024-08-06 07:29:24 +08:00
|
|
|
aws s3 cp ${{ steps.set_tarball_name.outputs.tarball_path }} s3://gradio-npm-previews/${{ needs.changes.outputs.sha }}/
|
2024-08-06 18:36:20 +08:00
|
|
|
echo "js_tarball_url=https://gradio-npm-previews.s3.amazonaws.com/${{ needs.changes.outputs.sha }}/${{ steps.set_tarball_name.outputs.tarball_name }}" >> $GITHUB_OUTPUT
|
2024-08-05 22:27:26 +08:00
|
|
|
|
|
|
|
- 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: |
|
2024-08-06 06:57:28 +08:00
|
|
|
mkdir scripts
|
2024-08-05 22:27:26 +08:00
|
|
|
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
|
2024-08-06 07:10:50 +08:00
|
|
|
- name: make dirs
|
2024-08-06 07:45:15 +08:00
|
|
|
run: mkdir -p demo/all_demos && mv all_demos/* demo/all_demos/
|
2024-08-05 22:27:26 +08:00
|
|
|
- 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
|
|
|
|
- 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 }}
|
|
|
|
|
|
|
|
comment-spaces-success:
|
|
|
|
uses: "./.github/workflows/comment-queue.yml"
|
2024-08-06 02:11:24 +08:00
|
|
|
needs: [deploy, changes]
|
2024-08-06 18:17:03 +08:00
|
|
|
if: needs.changes.outputs.should_run == 'true' && needs.deploy.result == 'success'
|
2024-08-05 22:27:26 +08:00
|
|
|
secrets:
|
|
|
|
gh_token: ${{ secrets.COMMENT_TOKEN }}
|
|
|
|
with:
|
|
|
|
pr_number: ${{ needs.changes.outputs.pr_number }}
|
2024-08-06 02:11:24 +08:00
|
|
|
message: spaces~success~${{ needs.deploy.outputs.space_url }}
|
2024-08-05 22:27:26 +08:00
|
|
|
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
|
2024-08-06 02:11:24 +08:00
|
|
|
npm install ${{ needs.deploy.outputs.js_tarball_url }}
|
2024-08-05 22:27:26 +08:00
|
|
|
```
|
|
|
|
comment-spaces-failure:
|
|
|
|
uses: "./.github/workflows/comment-queue.yml"
|
2024-08-06 02:11:24 +08:00
|
|
|
needs: [deploy, changes]
|
2024-08-06 18:17:03 +08:00
|
|
|
if: always() && needs.deploy.result == 'failure' && needs.changes.outputs.should_run == 'true'
|
2024-08-05 22:27:26 +08:00
|
|
|
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}}/
|