Skip to content

Commit bfb4913

Browse files
Balaji Srinivasanzgosalvez
andauthored
Make uploading artifacts optional (#23)
* Make uploading artifacts optional This allows users to execute this action even if they dont have permissions to upload artifacts to the target repo of their PR. This is usually the case when creating PRs from forks because by default github limits permissons for workflows that are not yet part of the target repo. Signed-off-by: Balaji Srinivasan <balaji.srinivasan@nordicsemi.no> * Clean up * Update action.yml Co-authored-by: Zennon Gosalvez <1798166+zgosalvez@users.noreply.github.com>
1 parent 5e9fb99 commit bfb4913

File tree

5 files changed

+37
-26
lines changed

5 files changed

+37
-26
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Create a workflow `.yml` file in your `.github/workflows` directory. An [example
1313
For more information on these inputs, see the [Workflow syntax for GitHub Actions](https://docs.github.com/actions/reference/workflow-syntax-for-github-actions#jobsjob_idstepswith)
1414

1515
- `coverage-files`: The coverage files to scan. For example, `coverage/lcov.*.info`
16-
- `artifact-name`: The GitHub artifact name of the generated HTML report. For example, `code-coverage-report`. _Note:_ When downloading, it will be extracted in an `html` directory
16+
- `artifact-name`: The GitHub artifact name of the generated HTML report. For example, `code-coverage-report`. _Note:_ When downloading, it will be extracted in an `html` directory. Optional. Default: `` (Skips uploading of artifacts)
1717
- `minimum-coverage`: The minimum coverage to pass the check. Optional. Default: `0` (always passes)
1818
- `github-token`: Set the `${{ secrets.GITHUB_TOKEN }}` token to have the action comment the coverage summary in the pull request. This token is provided by Actions, you do not need to create your own token. Optional. Default: ``
1919
- `working-directory`: The working directory containing the source files referenced in the LCOV files. Optional. Default: `./`

action.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ inputs:
88
description: 'The coverage files to scan. For example, `coverage/lcov.*.info`'
99
required: true
1010
artifact-name:
11-
description: 'The GitHub artifact name of the generated HTML report. For example, `code-coverage-report`. _Note:_ When downloading, it will be extracted in an `html` directory'
12-
required: true
11+
description: 'The GitHub artifact name of the generated HTML report. For example, `code-coverage-report`. _Note:_ When downloading, it will be extracted in an `html` directory. Optional. Default: `` (Skips uploading of artifacts)'
1312
minimum-coverage:
1413
description: 'The minimum coverage to pass the check. Optional. Default: `0` (always passes)'
1514
default: 0

dist/main/index.js

Lines changed: 17 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/main/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/main.js

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -64,17 +64,23 @@ async function genhtml(coverageFiles, tmpPath) {
6464

6565
await exec.exec('genhtml', args, { cwd: workingDirectory });
6666

67-
const globber = await glob.create(`${artifactPath}/**`);
68-
const htmlFiles = await globber.glob();
69-
70-
await artifact
71-
.create()
72-
.uploadArtifact(
73-
artifactName,
74-
htmlFiles,
75-
artifactPath,
76-
{ continueOnError: false },
77-
);
67+
if (artifactName !== '') {
68+
const globber = await glob.create(`${artifactPath}/**`);
69+
const htmlFiles = await globber.glob();
70+
71+
core.info(`Uploading artifacts.`);
72+
73+
await artifact
74+
.create()
75+
.uploadArtifact(
76+
artifactName,
77+
htmlFiles,
78+
artifactPath,
79+
{ continueOnError: false },
80+
);
81+
} else {
82+
core.info("Skip uploading artifacts");
83+
}
7884
}
7985

8086
async function mergeCoverages(coverageFiles, tmpPath) {

0 commit comments

Comments
 (0)