gradio / .github /workflows /deploy-pr-to-spaces.yml
mindmime's picture
Upload folder using huggingface_hub
a03b3ba verified
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}}/