-
Notifications
You must be signed in to change notification settings - Fork 3.8k
199 lines (174 loc) · 9 KB
/
pr-automation.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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
name: PR Automation test suite
on:
pull_request:
branches: [release]
types:
- opened
- labeled
jobs:
parse-tags:
runs-on: ubuntu-latest
permissions:
pull-requests: write
defaults:
run:
shell: bash
outputs:
tags: ${{ steps.checkAll.outputs.tags }}
matrix: ${{ steps.checkAll.outputs.matrix }}
steps:
# Checkout the code in the current branch in case the workflow is called because of a branch push event
- name: Checkout the head commit of the branch
uses: actions/checkout@v4
with:
repository: appsmithorg/appsmith
# Checks for ok-to-test label presence in PR
- name: Check label
run: |
if [[ '${{ github.event.label.name }}' != 'ok-to-test' ]]; then
echo "Irrelevant label '${{ github.event.label.name }}' added! "
exit 1
fi
# Reads the PR description to retrieve the /ok-to-test or, if that's absent, the /test command
- name: Get tags
uses: actions/github-script@v7
id: getTags
env:
NODE_PATH: "${{ github.workspace }}/.github/workflows/scripts"
with:
script: |
const testTagParser = require("test-tag-parser.js")
core.setOutput("tags", testTagParser.parseTags({core, context}))
# Parses the retrieved /ok-to-test slash command to retrieve tags
- name: Parse tags
id: parseTags
run: |
if [[ '${{ steps.getTags.outputs.tags }}' != '' ]]; then
echo "tags=${{ steps.getTags.outputs.tags }}" >> $GITHUB_OUTPUT
echo "outcome=success" >> $GITHUB_OUTPUT
else
echo "Tags were not found!"
echo "outcome=failure" >> $GITHUB_OUTPUT
fi
# In case of missing tags, guides towards correct usage in test response
- name: Add test response with tags documentation link
if: steps.parseTags.outputs.outcome != 'success'
uses: nefrob/[email protected]
with:
content: |
<!-- This is an auto-generated comment: Cypress test results -->
> [!WARNING]
> The provided command lacks proper tags. Please modify PR body, specifying the tags you want to include or use `/ok-to-test tags="@tag.All"` to run all specs.
> Explore the tags documentation [here](https://www.notion.so/appsmith/Ok-to-test-With-Tags-7c0fc64d4efb4afebf53348cd6252918)
<!-- end of auto-generated comment: Cypress test results -->
regex: "<!-- This is an auto-generated comment: Cypress test results -->.*?<!-- end of auto-generated comment: Cypress test results -->"
regexFlags: ims
token: ${{ secrets.GITHUB_TOKEN }}
# In case of missing tags, exit the workflow with failure
- name: Stop the workflow run if tags are not present
if: steps.parseTags.outputs.outcome != 'success'
run: exit 1
- name: Check Tags
env:
TAG_LIST: ${{ steps.getTags.outputs.tags }}
id: checkTags
run: |
export IFS=","
for tag in ${TAG_LIST//[[:blank:]]/}; do
if [[ `cat app/client/cypress/tags.js|grep -w $tag|wc -l` != 1 && $tag != "@tag.All" ]]; then
echo "Incorrect Tags"
echo "outcome=failure" >> $GITHUB_OUTPUT
fi
done
shell: bash
# In case of incorrect tags, guides towards correct tags
- name: Add test response with tags list link
if: steps.checkTags.outputs.outcome == 'failure'
uses: nefrob/[email protected]
with:
content: |
<!-- This is an auto-generated comment: Cypress test results -->
> [!WARNING]
> The provided command contains incorrect tags. Please modify PR body, specifying the tags you want to include or use `/ok-to-test tags="@tag.All"` to run all specs.
> Please find complete list of tags [here](https://github.com/appsmithorg/appsmith/blob/release/app/client/cypress/tags.js)
<!-- end of auto-generated comment: Cypress test results -->
regex: "<!-- This is an auto-generated comment: Cypress test results -->.*?<!-- end of auto-generated comment: Cypress test results -->"
regexFlags: ims
token: ${{ secrets.GITHUB_TOKEN }}
# In case of incorrect tags, exit the workflow with failure
- name: Stop the workflow run if tags are incorrect
if: steps.checkTags.outputs.outcome == 'failure'
run: exit 1
# In case of a run with all test cases, allocate a larger matrix
- name: Check if @tag.All is present in tags
id: checkAll
run: |
tags="${{ steps.parseTags.outputs.tags }}"
if [[ ($tags == *"ALL"* || $tags == *"All"* || $tags == *"all"*) && $tags != *"@tag.All"* ]]; then
echo "invalid_tags_all=$tags" >> $GITHUB_OUTPUT
elif [[ $tags == *"@tag.All"* ]]; then
echo "tags=" >> $GITHUB_OUTPUT
echo "matrix=[0, 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]" >> $GITHUB_OUTPUT
else
echo "tags=$tags" >> $GITHUB_OUTPUT
echo "matrix=[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19]" >> $GITHUB_OUTPUT
fi
# In case of incorrect usage for all test cases, inform the PR author of correct usage
- name: Add test response to use correct @tag.All format
if: steps.checkAll.outputs.invalid_tags_all != ''
uses: nefrob/[email protected]
with:
content: |
<!-- This is an auto-generated comment: Cypress test results -->
> [!WARNING]
> Please use `/ok-to-test tags="@tag.All"` to run all specs.
> Explore the tags documentation [here](https://www.notion.so/appsmith/Ok-to-test-With-Tags-7c0fc64d4efb4afebf53348cd6252918)
<!-- end of auto-generated comment: Cypress test results -->
regex: "<!-- This is an auto-generated comment: Cypress test results -->.*?<!-- end of auto-generated comment: Cypress test results -->"
regexFlags: ims
token: ${{ secrets.GITHUB_TOKEN }}
# In case of incorrect usage for all test cases, exit the workflow with failure
- name: Stop the workflow run if given @tag.All format is wrong
if: steps.checkAll.outputs.invalid_tags_all != ''
run: exit 1
# In case of a run with all test cases, inform the PR author of better usage
- name: Add test response to use @tag.All
if: steps.checkAll.outputs.tags == ''
uses: nefrob/[email protected]
with:
content: |
<!-- This is an auto-generated comment: Cypress test results -->
> [!WARNING]
> Whoa, @tag.All spotted in your test suite! 🚀
> While @tag.All is cool, like a catch-all net, why not try specific tags? 🏷️
> Narrow down your suite with specific tags for quicker and more accurate tests! 🚀 Less waiting, more zipping through tests like a ninja!
> Explore the tags documentation [here](https://www.notion.so/appsmith/Ok-to-test-With-Tags-7c0fc64d4efb4afebf53348cd6252918)
<!-- end of auto-generated comment: Cypress test results -->
regex: "<!-- This is an auto-generated comment: Cypress test results -->.*?<!-- end of auto-generated comment: Cypress test results -->"
regexFlags: ims
token: ${{ secrets.GITHUB_TOKEN }}
# In case of a runnable command, update the PR with run details
- name: Add test response with link to workflow run
uses: nefrob/[email protected]
with:
content: |
<!-- This is an auto-generated comment: Cypress test results -->
> [!IMPORTANT]
> 🟣 🟣 🟣 Your tests are running.
> Tests running at: <${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}>
> Commit: ${{ github.event.pull_request.head.sha }}
> Workflow: `${{ github.workflow }}`
> Tags: `${{ steps.checkAll.outputs.tags }}`
<!-- end of auto-generated comment: Cypress test results -->
regex: "<!-- This is an auto-generated comment: Cypress test results -->.*?<!-- end of auto-generated comment: Cypress test results -->"
regexFlags: ims
token: ${{ secrets.GITHUB_TOKEN }}
# Call the workflow to run Cypress tests
perform-test:
needs: [parse-tags]
if: success()
uses: ./.github/workflows/pr-cypress.yml
secrets: inherit
with:
tags: ${{ needs.parse-tags.outputs.tags}}
matrix: ${{ needs.parse-tags.outputs.matrix}}