-
Notifications
You must be signed in to change notification settings - Fork 8
103 lines (87 loc) · 4.33 KB
/
deploy-chromatic-pull-request.yaml
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
name: "Deploy chromatic pull request"
on:
pull_request:
types: [ labeled, synchronize ]
concurrency:
group: chromatic-${{ github.head_ref }}
cancel-in-progress: true
jobs:
deploy_chromatic:
if: "github.event.action == 'labeled' && github.event.label.name == 'need: deploy-chromatic'"
name: "Deploy chromatic"
runs-on: ubuntu-latest
steps:
- name: "Checkout repository"
uses: actions/checkout@v3
with:
fetch-depth: 0 # retrieve all the repo history (required by chromatic)
- name: "Init variables"
id: vars
uses: actions/github-script@v6
with:
script: |
// Link to the current run on github website
const run_html_url = "${{github.event.repository.html_url}}/actions/runs/${{github.run_id}}?pr=${{github.event.pull_request.number}}";
// StoryBook URL
const utils = require('./.github/actions/utils');
const storybook_url = await utils.getStoryBookURL('${{github.event.pull_request.head.sha}}');
return { run_html_url, storybook_url };
- name: "Update PR body: Deploying state"
uses: ./.github/actions/update-pr-body
with:
pattern: 'StoryBook: .*'
replace: 'StoryBook: [Deploying...](${{fromJSON(steps.vars.outputs.result).run_html_url}})'
whenNotFound: 'append'
keepLastMatch: true
- name: "Setup"
uses: ./.github/actions/setup
- name: "Deploy chromatic"
id: deploy
uses: chromaui/action@3f82bf5d065290658af8add6dce946809ee0f923 #v6.1.0
with:
token: ${{ secrets.GITHUB_TOKEN }}
projectToken: ${{ secrets.CHROMATIC_TOKEN }}
buildScriptName: build:storybook
onlyChanged: true
#skip: true
- if: "failure()"
name: "Update PR body: Failure state"
uses: ./.github/actions/update-pr-body
with:
pattern: 'StoryBook: .*'
replace: 'StoryBook: [:x: Failed](${{fromJSON(steps.vars.outputs.result).run_html_url}})'
whenNotFound: 'ignore'
keepLastMatch: true
- if: "always() && contains(github.event.pull_request.labels.*.name, 'need: deploy-chromatic')"
name: "Remove label"
uses: ./.github/actions/remove-label
with:
label: "need: deploy-chromatic"
- name: "Update PR body: Deployed state"
uses: ./.github/actions/update-pr-body
with:
pattern: 'StoryBook: .*'
replace: 'StoryBook: ${{fromJSON(steps.vars.outputs.result).storybook_url}} ([Chromatic build](${{steps.deploy.outputs.buildUrl}}))'
whenNotFound: 'append'
keepLastMatch: true
check_up_to_date:
if: "github.event.action == 'synchronize' && contains(github.event.pull_request.body, '\nStoryBook: https')"
name: "Check StoryBook URL is up-to-date"
runs-on: ubuntu-latest
steps:
- name: "Checkout repository"
uses: actions/checkout@v3
- name: "Get current short SHA"
id: short_sha
run: echo "short_sha=$(git rev-parse --short ${{github.event.pull_request.head.sha}})" >> $GITHUB_OUTPUT
- name: "Mark storybook URL as outdated"
uses: ./.github/actions/update-pr-body
with:
pattern: 'StoryBook: ((https:\/\/([a-z0-9]+)--[^ ]*).*)'
# Ignore if the short SHA in the storybook URL is up-to-date or if it was already marked as outdated
skipReplaceIf: |
groups[3] === "${{steps.short_sha.outputs.short_sha}}"
|| groups[0].includes("Outdated commit")
replace: 'StoryBook: $1 **⚠️ Outdated commit**'
whenNotFound: 'ignore'
keepLastMatch: true