File size: 4,392 Bytes
0ad74ed
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
name: "storybook-deploy"

on:
  workflow_run:
    workflows: ["storybook-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

permissions: {}

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 }}
    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-chromatic-start:
    uses: "./.github/workflows/comment-queue.yml"
    needs: changes
    if: needs.changes.outputs.should_run == 'true' || contains(needs.changes.outputs.labels, 'no-visual-update')
    secrets:
      gh_token: ${{ secrets.COMMENT_TOKEN }}
    with:
      pr_number: ${{ needs.changes.outputs.pr_number }}
      message: |
        storybook~pending~null
  update-status:
    permissions:
      actions: read
      statuses: write
    runs-on: ubuntu-latest
    needs: changes
    if: needs.changes.outputs.should_run == 'false' || contains(needs.changes.outputs.labels, 'no-visual-update')
    steps:
      - name: update status
        uses: gradio-app/github/actions/set-commit-status@main
        with:
          sha: ${{ needs.changes.outputs.sha }}
          token: ${{ secrets.GITHUB_TOKEN }}
          name: "UI Tests"
          run_id: ${{ needs.changes.outputs.run_id }}
  deploy:
    permissions:
      actions: read
      contents: read
    environment: storybook
    name: "storybook-deploy"
    needs: changes
    if: needs.changes.outputs.should_run == 'true' && github.repository == 'gradio-app/gradio' && !contains(needs.changes.outputs.labels, 'no-visual-update')
    runs-on: ubuntu-latest
    outputs:
      changes: ${{ steps.publish-chromatic.outputs.changeCount }}
      errors: ${{ steps.publish-chromatic.outputs.errorCount }}
      storybook_url: ${{ steps.publish-chromatic.outputs.storybookUrl }}
      build_url: ${{ steps.publish-chromatic.outputs.buildUrl }}
    steps:
      - uses: actions/checkout@v4
        with:
          ref: ${{ needs.changes.outputs.source_branch }}
          repository: ${{ needs.changes.outputs.source_repo }}
          fetch-depth: 0
      - name: dowload storybook artifacts
        uses: actions/download-artifact@v4
        with:
          name: storybook-static
          path: storybook-static
          run-id: ${{ github.event.workflow_run.id }}
          github-token: ${{ secrets.GITHUB_TOKEN }}
      - name: list artifacts
        run: ls -R .
      - name: create dummy pkg.json
        run: echo "{}" > package.json
      - name: publish to chromatic
        id: publish-chromatic
        uses: chromaui/action@fdbe7756d4dbf493e2fbb822df73be7accd07e1c # @v11
        with:
          projectToken: ${{ secrets.CHROMATIC_PROJECT_TOKEN }}
          token: ${{ secrets.COMMIT_STATUS }}
          onlyChanged: true
          exitOnceUploaded: true
          storybookBuildDir: storybook-static

  comment-chromatic-end:
    uses: "./.github/workflows/comment-queue.yml"
    needs: [deploy, changes]
    secrets:
      gh_token: ${{ secrets.COMMENT_TOKEN }}
    with:
      pr_number: ${{ needs.changes.outputs.pr_number }}
      message: |
        storybook~success~${{ needs.deploy.outputs.storybook_url }}

  comment-chromatic-fail:
    uses: "./.github/workflows/comment-queue.yml"
    needs: [deploy, changes]
    if: always() && needs.deploy.result == 'failure'
    secrets:
      gh_token: ${{ secrets.COMMENT_TOKEN }}
    with:
      pr_number: ${{ needs.changes.outputs.pr_number }}
      message: |
        storybook~failure~https://github.com/gradio-app/gradio/actions/runs/${{github.run_id}}/