gradio

Форк
0
/
deploy-spaces.yml 
154 строки · 6.5 Кб
1
name: "deploy / spaces"
2

3
on:
4
  workflow_dispatch:
5
  workflow_run:
6
    workflows: ["trigger"]
7
    types: 
8
      - requested
9

10
permissions:
11
  statuses: write
12
concurrency:
13
  group: "${{ github.event.workflow_run.head_repository.full_name }}-${{ github.event.workflow_run.head_branch }}-${{ github.workflow_ref }}"
14
  cancel-in-progress: true
15
  
16
jobs:
17
  changes:
18
    name: "changes"
19
    runs-on: ubuntu-latest
20
    outputs:
21
      should_run: ${{ steps.changes.outputs.should_run }}
22
      sha: ${{ steps.changes.outputs.sha }}
23
      pr_number: ${{ steps.changes.outputs.pr_number }}
24
      source_branch: ${{ steps.changes.outputs.source_branch }}
25
      source_repo: ${{ steps.changes.outputs.source_repo }}
26
      merge_sha: ${{ steps.changes.outputs.merge_sha }}
27
      mergeable: ${{ steps.changes.outputs.mergeable }}
28
      found_pr: ${{ steps.changes.outputs.found_pr }}
29
    steps:
30
      - uses: actions/checkout@v4
31
      - uses: "gradio-app/gradio/.github/actions/changes@main"
32
        id: changes
33
        with:
34
          type: "functional"
35
          name: "deploy / spaces"
36
          token: ${{ secrets.GITHUB_TOKEN }}
37
          commit_status: false
38
  
39
  comment-spaces-start:
40
    needs: changes
41
    uses: "./.github/workflows/comment-queue.yml"
42
    if: ${{ needs.changes.outputs.should_run == 'true' }}
43
    secrets:
44
      gh_token: ${{ secrets.COMMENT_TOKEN }}
45
    with:
46
      pr_number: ${{ needs.changes.outputs.pr_number }}
47
      message: spaces~pending~null
48
  deploy-spaces:
49
    outputs:
50
      space_url: ${{ steps.upload-demo.outputs.SPACE_URL }}
51
      gradio_version: ${{ steps.get_gradio_version.outputs.gradio_version }}
52
    needs: changes
53
    if: ${{ needs.changes.outputs.should_run == 'true' }}
54
    runs-on: ubuntu-latest
55
    steps:
56
    - uses: actions/checkout@v4
57
      with:
58
        ref: ${{ needs.changes.outputs.merge_sha }}
59
        repository: ${{ needs.changes.outputs.mergeable == 'true' &&  github.repository || needs.changes.outputs.source_repo }}
60
    - name: Install Python
61
      uses: actions/setup-python@v5
62
      with:
63
        python-version: '3.9'
64
    - name: Install pnpm
65
      uses: pnpm/action-setup@v2
66
      with:
67
        version: 8.15
68
    - uses: actions/setup-node@v4
69
      with:
70
        node-version: 18
71
        cache: pnpm
72
        cache-dependency-path: pnpm-lock.yaml
73
    - name: Install pip
74
      run: python -m pip install build requests
75
    - name: Get Gradio Version
76
      id: get_gradio_version
77
      run: |
78
        if ${{ github.event_name == 'pull_request' || github.event.workflow_run.event == 'pull_request' }}; then
79
          echo "GRADIO_VERSION=$(python -c 'import requests;print(requests.get("https://pypi.org/pypi/gradio/json").json()["info"]["version"])')" >> $GITHUB_OUTPUT
80
          python -c "import os;print(os.environ['GITHUB_REF'].split('/')[2])" > pr_number.txt
81
        else 
82
          echo "GRADIO_VERSION=$(python -c 'import json; print(json.load(open("gradio/package.json"))["version"])')" >> $GITHUB_OUTPUT
83
        fi
84
    - name: Build pr package
85
      run: |
86
        python -c 'import json; j = json.load(open("gradio/package.json")); j["version"] = "${{ steps.get_gradio_version.outputs.GRADIO_VERSION }}"; json.dump(j, open("gradio/package.json", "w"))'
87
        pnpm i --frozen-lockfile --ignore-scripts
88
        pnpm build
89
        python3 -m build -w
90
      env:
91
        NODE_OPTIONS: --max_old_space_size=8192
92

93
    - name: Set up Demos
94
      run: |
95
        python scripts/copy_demos.py https://gradio-builds.s3.amazonaws.com/${{ needs.changes.outputs.sha }}/gradio-${{ steps.get_gradio_version.outputs.GRADIO_VERSION }}-py3-none-any.whl \
96
        "gradio-client @ git+https://github.com/gradio-app/gradio@${{ needs.changes.outputs.sha }}#subdirectory=client/python"
97
    - name: Upload wheel
98
      run: |
99
        export AWS_ACCESS_KEY_ID=${{ secrets.PR_DEPLOY_KEY }}
100
        export AWS_SECRET_ACCESS_KEY=${{ secrets.PR_DEPLOY_SECRET }}
101
        export AWS_DEFAULT_REGION=us-east-1
102
        aws s3 cp dist/gradio-${{ steps.get_gradio_version.outputs.GRADIO_VERSION }}-py3-none-any.whl s3://gradio-builds/${{ needs.changes.outputs.sha  }}/
103
    - name: Install Hub Client Library
104
      run: pip install huggingface-hub
105
    - name: Upload demo to spaces
106
      if: github.event.workflow_run.event == 'pull_request'
107
      id: upload-demo
108
      run: |
109
        python scripts/upload_demo_to_space.py all_demos \
110
        gradio-pr-deploys/pr-${{ needs.changes.outputs.pr_number }}-all-demos \
111
        ${{ secrets.SPACES_DEPLOY_TOKEN }} \
112
        --gradio-version ${{ steps.get_gradio_version.outputs.GRADIO_VERSION }} > url.txt
113
        echo "SPACE_URL=$(cat url.txt)" >> $GITHUB_OUTPUT
114
    - name: Upload Website Demos
115
      if: github.event_name == 'workflow_dispatch'
116
      id: upload-website-demos
117
      run: |
118
        python scripts/upload_website_demos.py --AUTH_TOKEN ${{ secrets.WEBSITE_SPACES_DEPLOY_TOKEN }} \
119
        --WHEEL_URL https://gradio-builds.s3.amazonaws.com/${{ needs.changes.outputs.sha }}/ \
120
        --CLIENT_URL "gradio-client @ git+https://github.com/gradio-app/gradio@${{ needs.changes.outputs.sha }}#subdirectory=client/python" \
121
        --GRADIO_VERSION ${{ steps.get_gradio_version.outputs.GRADIO_VERSION }}
122
    - name: log
123
      run: |
124
        echo ${{github.event.workflow_run.event }}
125
        echo ${{ github.event.workflow_run.conclusion }}
126
    
127
  comment-spaces-success:
128
    uses: "./.github/workflows/comment-queue.yml"
129
    needs: [deploy-spaces, changes]
130
    if: needs.deploy-spaces.result == 'success' && needs.changes.outputs.found_pr == 'true'
131
    secrets:
132
      gh_token: ${{ secrets.COMMENT_TOKEN }}
133
    with:
134
      pr_number: ${{ needs.changes.outputs.pr_number }}
135
      message: spaces~success~${{ needs.deploy-spaces.outputs.space_url }}
136
      additional_text: |
137
        **Install Gradio from this PR**
138
        ```bash
139
        pip install https://gradio-builds.s3.amazonaws.com/${{ needs.changes.outputs.sha }}/gradio-${{ needs.deploy-spaces.outputs.gradio_version }}-py3-none-any.whl
140
        ```
141

142
        **Install Gradio Python Client from this PR**
143
        ```bash
144
        pip install "gradio-client @ git+https://github.com/gradio-app/gradio@${{ needs.changes.outputs.sha }}#subdirectory=client/python"
145
        ```
146
  comment-spaces-failure:
147
    uses: "./.github/workflows/comment-queue.yml"
148
    needs: [deploy-spaces, changes]
149
    if: always() && needs.deploy-spaces == 'failure' && needs.changes.outputs.found_pr == 'true'
150
    secrets:
151
      gh_token: ${{ secrets.COMMENT_TOKEN }}
152
    with:
153
      pr_number: ${{ needs.changes.outputs.pr_number }}
154
      message: spaces~failure~https://github.com/gradio-app/gradio/actions/runs/${{github.run_id}}/
155

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.