Skip to content

Commit 59ceee9

Browse files
feat: allow skipping job summary when no blocks or failures are present
Co-authored-by: Allan Reyes <allanbreyes@users.noreply.github.com>
1 parent 5d96858 commit 59ceee9

File tree

5 files changed

+35
-19
lines changed

5 files changed

+35
-19
lines changed

README.md

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,12 @@ jobs:
4343
4444
#### Inputs
4545
46-
| Input | Description | Required | Default |
47-
| ------------------ | ----------------------------------------------------- | -------- | -------------------- |
48-
| `firewall-version` | Specify the firewall version number | No | `latest` |
49-
| `job-summary` | Create a [job summary][job-summary] | No | `true` |
50-
| `use-cache` | Cache the Socket binaries (force download if `false`) | No | `true` |
51-
| `github-token` | GitHub API Token used for downloading binaries | No | `${{ github.token}}` |
46+
| Input | Description | Required | Default |
47+
| ------------------ | ---------------------------------------------------------------- | -------- | -------------------- |
48+
| `firewall-version` | Specify the firewall version number | No | `latest` |
49+
| `job-summary` | Create a [job summary][job-summary] (`all`, `errors`, or `none`) | No | `all` |
50+
| `use-cache` | Cache the Socket binaries (force download if `false`) | No | `true` |
51+
| `github-token` | GitHub API Token used for downloading binaries | No | `${{ github.token}}` |
5252

5353
#### Outputs
5454

@@ -88,13 +88,13 @@ jobs:
8888

8989
#### Inputs
9090

91-
| Input | Description | Required | Default |
92-
| ------------------ | ----------------------------------------------------- | -------- | -------------------- |
93-
| `firewall-version` | Specify the firewall version number | No | `latest` |
94-
| `job-summary` | Create a [job summary][job-summary] | No | `true` |
95-
| `use-cache` | Cache the Socket binaries (force download if `false`) | No | `true` |
96-
| `github-token` | GitHub API Token used for downloading binaries | No | `${{ github.token}}` |
97-
| `socket-token` | Socket API Token | **YES** | `-` |
91+
| Input | Description | Required | Default |
92+
| ------------------ | ---------------------------------------------------------------- | -------- | -------------------- |
93+
| `firewall-version` | Specify the firewall version number | No | `latest` |
94+
| `job-summary` | Create a [job summary][job-summary] (`all`, `errors`, or `none`) | No | `all` |
95+
| `use-cache` | Cache the Socket binaries (force download if `false`) | No | `true` |
96+
| `github-token` | GitHub API Token used for downloading binaries | No | `${{ github.token}}` |
97+
| `socket-token` | Socket API Token | **YES** | `-` |
9898

9999
#### Outputs
100100

@@ -104,4 +104,3 @@ jobs:
104104
| `firewall-path-binary` | Path to the installed binary |
105105

106106
[job-summary]: https://github.blog/news-insights/product-news/supercharging-github-actions-with-job-summaries
107-
[job-summary]: https://github.blog/news-insights/product-news/supercharging-github-actions-with-job-summaries

action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ inputs:
2727

2828
job-summary:
2929
description: Create a job summary
30-
default: 'true'
30+
default: all
3131

3232
firewall-version:
3333
description: Specify the firewall version number

src/main.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,13 @@ const inputs = {
2222
tokenSocket: core.getInput('socket-token'),
2323
versionFirewall: core.getInput('firewall-version'),
2424
useCache: core.getBooleanInput('use-cache'),
25-
jobSummary: core.getBooleanInput('job-summary')
25+
jobSummary: core.getInput('job-summary', { required: false }).toLowerCase()
2626
}
2727

28+
// backward compatibility
29+
if (inputs.jobSummary === 'true') inputs.jobSummary = 'all'
30+
if (inputs.jobSummary === 'false') inputs.jobSummary = 'none'
31+
2832
if (inputs.tokenSocket) {
2933
// setup socket token as a secret env
3034
core.exportVariable('SOCKET_API_KEY', inputs.tokenSocket)

src/post.js

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,21 @@ import { readFile } from 'node:fs/promises'
33
import { PackageURL } from 'packageurl-js'
44

55
// should show job summary?
6-
const jobSummary = core.getBooleanInput('job-summary', { required: false })
6+
const inputs = {
7+
jobSummary: core.getInput('job-summary', { required: false }).toLowerCase()
8+
}
9+
10+
// backward compatibility
11+
if (inputs.jobSummary === 'true') inputs.jobSummary = 'all'
12+
if (inputs.jobSummary === 'false') inputs.jobSummary = 'none'
713

8-
if (!jobSummary) {
14+
// exit early
15+
if (inputs.jobSummary === 'none') {
916
core.info('skipping firewall job summary')
1017
process.exit(0)
1118
}
1219

20+
// failed in setup
1321
if (!process.env.SFW_JSON_REPORT_PATH) {
1422
core.info('firewall report path not set')
1523
process.exit(0)
@@ -35,6 +43,11 @@ try {
3543
await core.summary.addRaw('<h2>Socket Firewall Report</h2>')
3644

3745
if (!report.blocked && !report.parseFail) {
46+
if (inputs.jobSummary === 'errors') {
47+
core.info('no errors detected, skipping job summary')
48+
process.exit(0)
49+
}
50+
3851
core.summary.addRaw('Nothing to report :tada:', true)
3952
}
4053

src/tools/firewall.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ export default async function download ({ edition = 'free', ...inputs }) {
111111
core.debug(`binary location: ${pathCache}`)
112112

113113
// set report path env
114-
if (inputs.jobSummary) {
114+
if (inputs.jobSummary !== 'none') {
115115
const pathReport = `${path.join(process.env.RUNNER_TEMP, randomUUID())}.json`
116116
// set the env info to be used in "post.js" step
117117
core.exportVariable('SFW_JSON_REPORT_PATH', pathReport)

0 commit comments

Comments
 (0)