-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaction.yml
More file actions
149 lines (136 loc) · 5.45 KB
/
Copy pathaction.yml
File metadata and controls
149 lines (136 loc) · 5.45 KB
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
name: 'Gradle Lighthouse'
description: 'Run Gradle Lighthouse audit and post results as PR comments + SARIF upload'
branding:
icon: 'zap'
color: 'orange'
inputs:
gradle-args:
description: 'Additional Gradle arguments'
required: false
default: ''
fail-on-severity:
description: 'Fail the action if issues at this severity or above exist (NONE, INFO, WARNING, ERROR, FATAL)'
required: false
default: 'NONE'
upload-sarif:
description: 'Upload SARIF results to GitHub Security tab'
required: false
default: 'true'
comment-on-pr:
description: 'Post score summary as PR comment'
required: false
default: 'true'
base-report-path:
description: 'Path to base reports for delta calculation (optional)'
required: false
default: '.lighthouse/base-reports'
runs:
using: 'composite'
steps:
- name: Download Base Reports (Main Branch)
if: github.event_name == 'pull_request'
uses: actions/github-script@v9
with:
script: |
try {
const { data: runs } = await github.rest.actions.listWorkflowRuns({
owner: context.repo.owner,
repo: context.repo.repo,
workflow_id: context.workflow,
branch: context.payload.pull_request.base.ref,
status: 'success',
per_page: 1
});
if (runs.workflow_runs.length > 0) {
const runId = runs.workflow_runs[0].id;
const { data: artifacts } = await github.rest.actions.listWorkflowRunArtifacts({
owner: context.repo.owner,
repo: context.repo.repo,
run_id: runId
});
const match = artifacts.artifacts.find(a => a.name === 'lighthouse-reports');
if (match) {
const download = await github.rest.actions.downloadArtifact({
owner: context.repo.owner,
repo: context.repo.repo,
artifact_id: match.id,
archive_format: 'zip'
});
const fs = require('fs');
fs.writeFileSync('${{ github.workspace }}/base-reports.zip', Buffer.from(download.data));
const exec = require('@actions/exec');
await exec.exec('unzip', ['-o', '${{ github.workspace }}/base-reports.zip', '-d', '${{ inputs.base-report-path }}']);
console.log('Successfully downloaded base reports from run ' + runId);
}
}
} catch (e) {
console.log('Could not download base reports: ' + e.message);
}
- name: Run Lighthouse Audit
shell: bash
run: |
./gradlew lighthouseAudit lighthouseAggregate \
-Plighthouse.failOnSeverity=${{ inputs.fail-on-severity }} \
-Plighthouse.baseReportDir=${{ inputs.base-report-path }} \
${{ inputs.gradle-args }} \
--no-daemon --stacktrace
env:
TERM: xterm-256color
- name: Upload SARIF
if: inputs.upload-sarif == 'true' && always()
uses: github/codeql-action/upload-sarif@v4.37.3
with:
sarif_file: build/reports/lighthouse/
category: gradle-lighthouse
- name: Find SARIF reports
if: always()
shell: bash
id: reports
run: |
REPORT_FILES=$(find . -path '*/reports/lighthouse/*-report.sarif' | head -20)
echo "sarif_files=$REPORT_FILES" >> $GITHUB_OUTPUT
# Extract score from root module report
SCORE=$(grep -o '"score": [0-9]*' build/reports/lighthouse/module-report.json 2>/dev/null | head -1 | grep -o '[0-9]*' || echo "N/A")
echo "score=$SCORE" >> $GITHUB_OUTPUT
- name: PR Comment
if: inputs.comment-on-pr == 'true' && github.event_name == 'pull_request' && always()
uses: actions/github-script@v9
with:
script: |
const fs = require('fs');
const summaryPath = 'build/reports/lighthouse/lighthouse-pr-summary.md';
let body = '';
if (fs.existsSync(summaryPath)) {
body = fs.readFileSync(summaryPath, 'utf8');
} else {
const score = '${{ steps.reports.outputs.score }}';
body = `## 🏗️ Gradle Lighthouse Report
| Metric | Value |
|--------|-------|
| **Health Score** | ${score}/100 |
| **Status** | ${parseInt(score) >= 70 ? '✅ Passing' : '⚠️ Needs attention'} |
> Full report available in the [Actions artifacts](${context.serverUrl}/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}).
> SARIF results uploaded to the Security tab.`;
}
// Find existing comment
const { data: comments } = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
});
const existing = comments.find(c => c.body.includes('Gradle Lighthouse Report'));
if (existing) {
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: existing.id,
body: body
});
} else {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body: body
});
}