@@ -21,10 +21,33 @@ jobs:
2121 with :
2222 access_token : ${{ secrets.GITHUB_TOKEN }}
2323
24- generate- allure-report :
24+ check-if- allure-artifacts-exist :
2525 runs-on : ubuntu-22.04
26- if : always()
2726 needs : stop-previous-run
27+ outputs :
28+ artifacts-exist : ${{ steps.check-artifacts-exist.outputs.artifacts-exist }}
29+ steps :
30+ - name : Check if allure artifacts exist
31+ id : check-artifacts-exist
32+ uses : actions/github-script@v6
33+ with :
34+ script : |
35+ const artifacts = await github.rest.actions.listWorkflowRunArtifacts({
36+ owner: context.repo.owner,
37+ repo: context.repo.repo,
38+ run_id: ${{github.event.workflow_run.id }}
39+ });
40+ const matchArtifact = artifacts.data.artifacts.find(artifact => artifact.name === 'allure-results');
41+ if (!matchArtifact) {
42+ core.setOutput('artifacts-exist', 'false');
43+ } else {
44+ core.setOutput('artifacts-exist', 'true');
45+ }
46+
47+ generate-allure-report :
48+ runs-on : ubuntu-22.04
49+ needs : check-if-allure-artifacts-exist
50+ if : ${{ needs.check-if-allure-artifacts-exist.outputs.artifacts-exist != 'false' }}
2851 steps :
2952 - name : Dowload artifacts
3053 uses : actions/github-script@v6
6386 with :
6487 allure_results : ./
6588 allure_history : allure-history
66- keep_reports : 20
89+ keep_reports : 30
6790
6891 - name : Deploy report to Github Pages
6992 if : always()
77100 comment-to-pr :
78101 runs-on : ubuntu-22.04
79102 needs : generate-allure-report
80- if : >
81- github.event.workflow_run.event == 'pull_request'
103+ if : always() && github.event.workflow_run.event == 'pull_request'
82104 steps :
83105 - name : ' Download artifact'
84106 uses : actions/github-script@v6
@@ -101,36 +123,21 @@ jobs:
101123 });
102124 const fs = require('fs');
103125 fs.writeFileSync('${{github.workspace}}/env_for_comment.zip', Buffer.from(download.data));
104- - run : unzip env_for_comment.zip
126+ - run : |
127+ unzip env_for_comment.zip
128+ echo ${{ needs.generate-allure-report.result }}
105129
106- - name : ' Comment to PR -- if success'
107- if : github.event.workflow_run.conclusion == 'success'
108- uses : actions/github-script@v6
109- with :
110- script : |
111- const fs = require('fs');
112- const issue_number = Number(fs.readFileSync('./prNum'));
113- const runNumber = process.env.RUN_NUMBER;
114- const runId = Number(fs.readFileSync('./runId'));
115- const repoFullName = fs.readFileSync('./repoFullName');
116- const ownerName = fs.readFileSync('./ownerName');
117- const githubPagesLink = 'https://' + ownerName.toString().toLowerCase().trim() + '.github.io/' + String(repoFullName).replace(`${ownerName.toString().trim()}/`, '') + '/';
118- const githubRunLink = 'https://github.com/' + repoFullName + '/actions/runs/' + runId;
119- github.rest.issues.createComment({
120- issue_number: issue_number,
121- owner: context.repo.owner,
122- repo: context.repo.repo,
123- body: 'All tests are passed ✅ \n Checkout tests results here: <a href="' + githubPagesLink + runNumber + '">Cypress e2e Test Report</a> \n Link to GitHub workflow: <a href="' + githubRunLink + '">Github Workflow Link</a> \n Take care of yourself and have a great day! 🌞 \n❕Note: Report deployment may take up to 5 minutes.'
124- })
125-
126- - name : ' Comment to PR -- if failed'
127- if : github.event.workflow_run.conclusion == 'failure'
130+ - name : ' Comment to PR -- if report generated'
131+ if : needs.generate-allure-report.result == 'success'
128132 uses : actions/github-script@v6
133+ env :
134+ WORKFLOW_CONCLUSION : ${{ github.event.workflow_run.conclusion }}
129135 with :
130136 script : |
131137 const fs = require('fs');
132138 const issue_number = Number(fs.readFileSync('./prNum'));
133139 const runNumber = process.env.RUN_NUMBER;
140+ const conclusion = process.env.WORKFLOW_CONCLUSION;
134141 const runId = Number(fs.readFileSync('./runId'));
135142 const repoFullName = fs.readFileSync('./repoFullName');
136143 const ownerName = fs.readFileSync('./ownerName');
@@ -140,17 +147,20 @@ jobs:
140147 issue_number: issue_number,
141148 owner: context.repo.owner,
142149 repo: context.repo.repo,
143- body: ' Workflow is failed ❌ \n Test might not start, so please chekout workflow first \n Link to GitHub workflow: <a href="' + githubRunLink + '">Github Workflow Link</a> \n Checkout tests results here: <a href="' + githubPagesLink + runNumber + ' ">Cypress e2e Test Report</a> \n Take care of yourself and have a great day! 🌞 \n❕Note: Report deployment may take up to 5 minutes.'
150+ body: ` Workflow status is ${conclusion === 'success'? conclusion + ' \u2705' : conclusion + ' \u274C'} \n Checkout tests results here: <a href="${ githubPagesLink}${ runNumber} ">Cypress e2e Test Report</a> \n Link to GitHub workflow: <a href="${githubRunLink}">Github Workflow Link</a> \n❕Note: Report deployment may take up to 10 minutes.`
144151 })
145152
146- - name : ' Comment to PR -- if cancelled '
147- if : github.event.workflow_run.conclusion == 'cancelled '
153+ - name : ' Comment to PR -- if report wasnt generated '
154+ if : needs.generate-allure-report.result == 'skipped '
148155 uses : actions/github-script@v6
156+ env :
157+ WORKFLOW_CONCLUSION : ${{ github.event.workflow_run.conclusion }}
149158 with :
150159 script : |
151160 const fs = require('fs');
152161 const issue_number = Number(fs.readFileSync('./prNum'));
153162 const runNumber = process.env.RUN_NUMBER;
163+ const conclusion = process.env.WORKFLOW_CONCLUSION;
154164 const runId = Number(fs.readFileSync('./runId'));
155165 const repoFullName = fs.readFileSync('./repoFullName');
156166 const ownerName = fs.readFileSync('./ownerName');
@@ -160,53 +170,41 @@ jobs:
160170 issue_number: issue_number,
161171 owner: context.repo.owner,
162172 repo: context.repo.repo,
163- body: 'Workflow is cancelled 🚫 \n Test might not start, so please chekout workflow first \n Link to GitHub workflow: <a href="' + githubRunLink + '">Github Workflow Link</a> \n Checkout tests results: <a href="' + githubPagesLink + runNumber + '">Cypress e2e Test Report</a> \n Take care of yourself and have a great day! 🌞 \n❕Note: Report deployment may take up to 5 minutes.'
164- })
165-
166- - name : ' Add label to PR -- if success'
167- if : github.event.workflow_run.conclusion == 'success'
168- uses : actions/github-script@v6
169- with :
170- github-token : ${{ secrets.GITHUB_TOKEN }}
171- script : |
172- const fs = require('fs');
173- const issue_number = Number(fs.readFileSync('./prNum'));
174- const runNumber = process.env.RUN_NUMBER;
175- github.rest.issues.addLabels({
176- issue_number: issue_number,
177- owner: context.repo.owner,
178- repo: context.repo.repo,
179- labels: ['e2e-success']
173+ body: `Workflow status is ${conclusion === 'success'? conclusion + ' \u2705' : conclusion === 'cancelled'? conclusion + ' \u2757' : conclusion + ' \u274C'} \n Unfortunately test report wasn't generated, it can be if no workspaces changed. Please check the workflow run below. \n Link to GitHub workflow: <a href="${githubRunLink}">Github Workflow Link</a>`
180174 })
181175
182- - name : ' Add label to PR -- if failed '
183- if : github.event.workflow_run.conclusion == 'failure '
176+ - name : ' Add e2e label to PR -- if report generated '
177+ if : needs.generate-allure-report.result == 'success '
184178 uses : actions/github-script@v6
179+ env :
180+ WORKFLOW_CONCLUSION : ${{ github.event.workflow_run.conclusion }}
185181 with :
186182 github-token : ${{ secrets.GITHUB_TOKEN }}
187183 script : |
188184 const fs = require('fs');
189185 const issue_number = Number(fs.readFileSync('./prNum'));
190- const runNumber = process.env.RUN_NUMBER ;
186+ const conclusion = process.env.WORKFLOW_CONCLUSION ;
191187 github.rest.issues.addLabels({
192188 issue_number: issue_number,
193189 owner: context.repo.owner,
194190 repo: context.repo.repo,
195- labels: [' e2e-failure' ]
191+ labels: [` e2e-${conclusion}` ]
196192 })
197193
198- - name : ' Add label to PR -- if cancelled '
199- if : github.event.workflow_run.conclusion == 'cancelled'
194+ - name : ' Add workflow label to PR'
195+ if : always()
200196 uses : actions/github-script@v6
197+ env :
198+ WORKFLOW_CONCLUSION : ${{ github.event.workflow_run.conclusion }}
201199 with :
202200 github-token : ${{ secrets.GITHUB_TOKEN }}
203201 script : |
204202 const fs = require('fs');
205203 const issue_number = Number(fs.readFileSync('./prNum'));
206- const runNumber = process.env.RUN_NUMBER ;
204+ const conclusion = process.env.WORKFLOW_CONCLUSION ;
207205 github.rest.issues.addLabels({
208206 issue_number: issue_number,
209207 owner: context.repo.owner,
210208 repo: context.repo.repo,
211- labels: ['e2e-cancelled' ]
209+ labels: [`workflow-${conclusion}` ]
212210 })
0 commit comments