-
Notifications
You must be signed in to change notification settings - Fork 14
113 lines (108 loc) · 3.76 KB
/
percy.yml
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
name: percy
concurrency:
group: ${{ github.head_ref }}-${{ github.workflow }}
cancel-in-progress: true
on:
pull_request:
types:
- opened
- reopened
- synchronize
- labeled
paths:
- "package.json"
- "package-lock.json"
- "components/**"
- "!components/**/*.md"
- "!components/o3-*/**"
push:
branches: main
paths:
- "package.json"
- "package-lock.json"
- "components/**"
- "!components/**/*.md"
- "!components/o3-*/**"
jobs:
changes:
runs-on: ubuntu-latest
permissions:
pull-requests: read
outputs:
components: ${{ steps.set-matrix.outputs.changes }}
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
- uses: volta-cli/action@v4
- uses: actions/cache@v2
with:
volta-version: "1.0.8"
path: ~/.npm
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
- name: Configure Cloudsmith
env:
CLOUDSMITH_API_KEY: ${{ secrets.CLOUDSMITH_API_KEY }}
run: |
npm config set registry=https://npm.packages.ft.com/financial-times-internal-releases/
npm config set //npm.packages.ft.com/financial-times-internal-releases/:_authToken=${CLOUDSMITH_API_KEY}
- name: Install node modules
run: npm ci
- name: Find components affected by changes
id: percy-changes
run: |
changes=()
for component in components/*/; do
RESULT=$(WORKSPACE=$component node ./scripts/should-percy-run.js | grep "\-RESULT:" | cut -d ":" -f 2)
component_trimmed=$(echo $component | sed 's/\/$//g')
if [[ $RESULT = 'true' ]]; then
echo "$component_trimmed is affected by changes, adding to percy run list."
changes+=("$component_trimmed")
fi
done
json_array=$(jq -n '$ARGS.positional' --args "${changes[@]}");
echo "Changes:\n$json_array:";
echo "CHANGES=$(echo ${json_array})" >> "$GITHUB_OUTPUT";
- name: Set Matrix
id: set-matrix
run: |
CHANGES_INPUT=$(echo '${{ steps.percy-changes.outputs.changes }}')
if [ $CHANGES_INPUT -ne "[]"]; then
MATRIX=$(echo $CHANGES_INPUT | jq '{include: (map({component: ., token_name: ("PERCY_TOKEN_" + (. | ascii_upcase | sub("(/|-)"; "_"; "g")))}))}' | tr '\n' ' ')
echo "CHANGES=$(echo "$MATRIX")" >> "$GITHUB_OUTPUT";
else
echo "CHANGES=$(echo '[]')" >> "$GITHUB_OUTPUT";
fi
run-percy:
if: ${{ needs.changes.outputs.components != '[]' && needs.changes.outputs.components != '' }}
needs: changes
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix: ${{ fromJson(needs.changes.outputs.components) }}
steps:
- uses: actions/checkout@v2
- uses: volta-cli/action@v4
- uses: actions/cache@v2
with:
volta-version: "1.0.8"
path: ~/.npm
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
- name: Configure Cloudsmith
env:
CLOUDSMITH_API_KEY: ${{ secrets.CLOUDSMITH_API_KEY }}
run: |
npm config set registry=https://npm.packages.ft.com/financial-times-internal-releases/
npm config set //npm.packages.ft.com/financial-times-internal-releases/:_authToken=${CLOUDSMITH_API_KEY}
- name: Install node modules
run: npm ci
- name: Start Percy check
env:
PERCY_TOKEN: ${{ secrets[matrix.token_name] }}
WORKSPACE: ${{ matrix.component }}
run: |
node ./scripts/percy.js