previews-deploy #16976
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: "previews-deploy" | |
| on: | |
| workflow_run: | |
| workflows: ["previews-build"] | |
| types: | |
| - completed | |
| 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 | |
| if: github.event.workflow_run.conclusion == 'success' | |
| permissions: | |
| actions: read | |
| outputs: | |
| 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 }} | |
| steps: | |
| - name: Download artifact | |
| uses: actions/download-artifact@v4 | |
| with: | |
| 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 | |
| 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: | |
| name: "previews-deploy" | |
| environment: deploy_spaces | |
| outputs: | |
| space_url: ${{ steps.upload-demo.outputs.SPACE_URL }} | |
| needs: changes | |
| if: ${{ (github.event.workflow_run.conclusion == 'success' && needs.changes.outputs.should_run == 'true') || github.event.workflow_run.event == 'workflow_dispatch' }} | |
| runs-on: ubuntu-latest | |
| permissions: | |
| actions: read | |
| steps: | |
| - name: Download all artifacts | |
| uses: actions/download-artifact@v4 | |
| with: | |
| run-id: ${{ github.event.workflow_run.id }} | |
| github-token: ${{ secrets.GITHUB_TOKEN }} | |
| - 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: Install hf CLI | |
| run: curl -LsSf https://hf.co/cli/install.sh | bash -s | |
| - name: Upload wheel | |
| run: hf buckets cp ${{ steps.set_wheel_name.outputs.wheel_name }} hf://buckets/gradio/pypi-previews/${{ needs.changes.outputs.sha }}/ | |
| env: | |
| HF_TOKEN: ${{ secrets.PYPI_PREVIEWS_TOKEN }} | |
| - name: Upload JS client dist to HF | |
| run: | | |
| if [ -d ./js-client-dist ]; then | |
| hf buckets sync ./js-client-dist hf://buckets/gradio/npm-previews/${{ needs.changes.outputs.sha }} | |
| else | |
| echo "Skipping JS client dist upload: ./js-client-dist not found." | |
| fi | |
| env: | |
| HF_TOKEN: ${{ secrets.PYPI_PREVIEWS_TOKEN }} | |
| - name: Install Hub Client Library | |
| run: | | |
| python3 -m venv venv | |
| . venv/bin/activate | |
| pip install huggingface-hub==0.23.2 | |
| # temporary, but ensures the script cannot be modified in a PR | |
| - name: Get deploy scripts | |
| run: | | |
| mkdir scripts | |
| 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 | |
| - name: make dirs | |
| run: mkdir -p demo && mv all_demos/* demo/ | |
| - name: Upload demo to spaces | |
| if: github.event.workflow_run.event == 'pull_request' | |
| id: upload-demo | |
| run: | | |
| . venv/bin/activate | |
| python scripts/upload_demo_to_space.py all_demos \ | |
| gradio-pr-deploys/pr-${{ needs.changes.outputs.pr_number }}-all-demos \ | |
| ${{ secrets.WEBSITE_SPACES_DEPLOY_TOKEN }} \ | |
| --gradio-version ${{ needs.changes.outputs.gradio_version }} > url.txt | |
| echo "SPACE_URL=$(tail -n 1 url.txt)" >> $GITHUB_OUTPUT | |
| - name: Upload Website Demos | |
| if: github.event.workflow_run.event == 'workflow_dispatch' | |
| id: upload-website-demos | |
| run: | | |
| . venv/bin/activate | |
| python scripts/upload_website_demos.py --AUTH_TOKEN ${{ secrets.WEBSITE_SPACES_DEPLOY_TOKEN }} \ | |
| --WHEEL_URL https://huggingface.co/buckets/gradio/pypi-previews/resolve/${{ 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" | |
| needs: [deploy, changes] | |
| if: needs.changes.outputs.should_run == 'true' && needs.deploy.result == 'success' | |
| secrets: | |
| gh_token: ${{ secrets.COMMENT_TOKEN }} | |
| with: | |
| pr_number: ${{ needs.changes.outputs.pr_number }} | |
| message: spaces~success~${{ needs.deploy.outputs.space_url }} | |
| additional_text: | | |
| **Install Gradio from this PR** | |
| ```bash | |
| pip install https://huggingface.co/buckets/gradio/pypi-previews/resolve/${{ 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" | |
| ``` | |
| **Import Gradio JS Client from this PR via CDN** | |
| ```js | |
| import { Client } from "https://huggingface.co/buckets/gradio/npm-previews/resolve/${{ needs.changes.outputs.sha }}/browser.js"; | |
| ``` | |
| comment-spaces-failure: | |
| uses: "./.github/workflows/comment-queue.yml" | |
| needs: [deploy, changes] | |
| if: always() && needs.deploy.result == 'failure' && needs.changes.outputs.should_run == '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}}/ |