| 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@v4 | |
| with: | |
| python-version: '3.9' | |
| - name: Install pnpm | |
| uses: pnpm/action-setup@v2 | |
| with: | |
| version: 8 | |
| - uses: actions/setup-node@v3 | |
| 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@v3 | |
| 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@v3 | |
| 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@v3 | |
| with: | |
| name: metadata.json | |
| path: metadata.json |