forked from LedgerHQ/ledger-live-desktop
169 lines (151 loc) · 5.58 KB
/
ui-tests-reports.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
name: "Report | Tests Reports"
on:
# workflow_dispatch:
# inputs:
# runId:
# description: run id
# required: true
workflow_run:
workflows: ["Tests | Test Suite"]
types:
- "completed"
jobs:
log:
name: "Check previous github object"
runs-on: ubuntu-20.04
steps:
- name: log github object
env:
GITHUB: ${{ toJSON(github) }}
run: |
echo $GITHUB
comment-on-pr:
name: "Comment report on PR"
runs-on: ubuntu-20.04
steps:
- name: download artifacts
uses: actions/github-script@v6
with:
script: |
const fs = require('fs');
const artifacts = await github.rest.actions.listWorkflowRunArtifacts({
owner: context.repo.owner,
repo: context.repo.repo,
run_id: ${{github.event.workflow_run.id || github.event.inputs.runId }},
});
// Filter Artifacts
const reportArtifacts = artifacts.data.artifacts.filter(artifact => {
return artifact.name == "tests-reports";
})[0];
const playwrightArtifacts = artifacts.data.artifacts.filter(artifact => {
return (
artifact.name == "playwright-results-windows-latest" ||
artifact.name === "playwright-results-linux"
);
});
const imagesArtifacts = artifacts.data.artifacts.filter(artifact => {
return artifact.name.includes("images-");
});
// Download Artifacts
const downloadReport = await github.rest.actions.downloadArtifact({
owner: context.repo.owner,
repo: context.repo.repo,
artifact_id: reportArtifacts.id,
archive_format: "zip",
});
fs.writeFileSync(
"${{github.workspace}}/" + reportArtifacts.name + ".zip",
Buffer.from(downloadReport.data)
);
const pPWArtifacts = await Promise.all(
playwrightArtifacts.map(artifact => {
return github.rest.actions.downloadArtifact({
owner: context.repo.owner,
repo: context.repo.repo,
artifact_id: artifact.id,
archive_format: "zip",
});
})
);
pPWArtifacts.forEach((artifact, i) => {
fs.writeFileSync(
"${{github.workspace}}/" + playwrightArtifacts[i].name + ".zip",
Buffer.from(artifact.data)
);
});
const pImagesArtifacts = await Promise.all(
imagesArtifacts.map(image => {
return github.rest.actions.downloadArtifact({
owner: context.repo.owner,
repo: context.repo.repo,
artifact_id: image.id,
archive_format: "zip",
});
})
);
pImagesArtifacts.forEach((artifact, i) => {
fs.writeFileSync(
"${{github.workspace}}/" + imagesArtifacts[i].name + ".zip",
Buffer.from(artifact.data)
);
});
- name: unzip files
run: |
unzip tests-reports.zip || true
unzip playwright-results-windows-latest.zip -d pw-windows || true
unzip playwright-results-linux.zip -d pw-linux || true
unzip images-linux.json.zip || true
unzip images-windows-latest.json.zip || true
rm tests-reports.zip playwright-results-windows-latest.zip playwright-results-linux.zip images-linux.json.zip images-windows-latest.json.zip
- name: parse images
uses: actions/github-script@v6
with:
script: |
const fs = require("fs");
const files = ["images-linux", "images-windows-latest"];
let result = {};
for (const file of files) {
try {
const raw = JSON.parse(fs.readFileSync("${{github.workspace}}/" + file + ".json"));
const key = file.replace("images-", "").replace("-latest", "").trim()
result[key] = raw;
} catch (err) {
console.log(err);
}
}
fs.writeFileSync(`./images.json`, JSON.stringify(result, null, 2));
- name: prepare comment body
id: comment-body
uses: ledgerhq/actions/packages/prepare-comment@main
with:
images: images.json
lintoutput: lint.txt
jestoutput: jest.txt
# - name: comment (manual trigger)
# if: github.event.workflow_dispatch != ''
# uses: actions/github-script@v6
# with:
# script: |
# const fs = require("fs");
# const issueNumber = Number(fs.readFileSync("./pr/NR"));
# await github.rest.issues.createComment({
# owner: "LedgerHQ",
# repo: "ledger-live-desktop",
# issue_number: issueNumber,
# body: `
# ${{ steps.comment-body.outputs.body }}
# `
# });
- name: comment
if: github.event.workflow_run != ''
uses: actions/github-script@v6
with:
script: |
await github.rest.repos.createCommitComment({
owner: "LedgerHQ",
repo: "ledger-live-desktop",
commit_sha: "${{ github.event.workflow_run.head_sha }}",
body: `
${{ steps.comment-body.outputs.body }}
`
});