Skip to content
This repository has been archived by the owner on Oct 13, 2023. It is now read-only.

Commit

Permalink
Falling back to the stdout report if token permissions are not allowi…
Browse files Browse the repository at this point in the history
…ng to post Check annotations (#2)
  • Loading branch information
svartalf committed Oct 4, 2019
1 parent 6115359 commit 8bca5ed
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 23 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [1.0.4] - 2019-10-04

### Added

- Falling back to the stdout report if token permissions are not allowing to post Check annotations (#2)

## [1.0.3] - 2019-10-01

### Fixed
Expand Down
10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,12 @@ jobs:
For extra details about the `toolchain`, `args` and `use-cross` inputs,
see [`cargo` Action](https://github.com/actions-rs/cargo#inputs) documentation.

## Notes
## Limitations

Due to [token permissions](https://help.github.com/en/articles/virtual-environments-for-github-actions#token-permissions),
this Action **WILL NOT** be able to post `clippy` annotations for Pull Requests from the forked repositories.\
This is a pretty big problem, which can be solved only by Github itself. Consider this before using this Action.
this Action **WILL NOT** be able to post `clippy` annotations for Pull Requests from the forked repositories.

This is a pretty big problem, which can be solved only by Github themselves,
see [#2](https://github.com/actions-rs/clippy-check/issues/2) for details.\
As a fallback this Action will output all clippy messages into the stdout
and fail the result correspondingly.
2 changes: 1 addition & 1 deletion dist/index.js

Large diffs are not rendered by default.

20 changes: 10 additions & 10 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "rust-clippy-check",
"version": "1.0.3",
"version": "1.0.4",
"private": false,
"description": "Run clippy and annotate the diff with errors and warnings",
"main": "lib/main.js",
Expand Down Expand Up @@ -29,14 +29,14 @@
},
"dependencies": {
"@actions-rs/core": "0.0.4",
"@actions/core": "^1.1.1",
"@actions/core": "^1.1.3",
"@actions/github": "^1.1.0",
"@octokit/rest": "^16.30.1",
"@octokit/rest": "^16.30.2",
"string-argv": "^0.3.1"
},
"devDependencies": {
"@types/jest": "^24.0.13",
"@types/node": "^12.7.8",
"@types/node": "^12.7.11",
"@zeit/ncc": "^0.20.5",
"jest": "^24.9.0",
"jest-circus": "^24.9.0",
Expand Down
40 changes: 37 additions & 3 deletions src/check.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,37 @@ ${this.stats.help} help`);
const client = new github.GitHub(options.token, {
userAgent: USER_AGENT,
});
const checkRunId = await this.createCheck(client, options);
let checkRunId: number;
try {
checkRunId = await this.createCheck(client, options);
} catch (error) {

// `GITHUB_HEAD_REF` is set only for forked repos,
// so we could check if it is a fork and not a base repo.
if (process.env.GITHUB_HEAD_REF) {
core.error(`Unable to create clippy annotations! Reason: ${error}`);
core.warning("It seems that this Action is executed from the forked repository.");
core.warning(`GitHub Actions are not allowed to create Check annotations, \
when executed for a forked repos. \
See https://github.com/actions-rs/clippy-check/issues/2 for details.`);
core.info('Posting clippy checks here instead.');

this.dumpToStdout();

// So, if there were any errors, we are considering this output
// as failed, throwing an error will set a non-zero exit code later
if (this.getConclusion() == 'failure') {
throw new Error('Exiting due to clippy errors');
} else {
// Otherwise if there were no errors (and we do not care about warnings),
// exiting successfully.
return;
}
} else {
throw error;
}
}

try {
if (this.isSuccessCheck()) {
await this.successCheck(client, checkRunId, options);
Expand All @@ -108,8 +138,6 @@ ${this.stats.help} help`);
await this.cancelCheck(client, checkRunId, options);
throw error;
}

return;
}

private async createCheck(client, options: CheckOptions): Promise<number> {
Expand Down Expand Up @@ -211,6 +239,12 @@ ${this.stats.help} help`);
return;
}

private dumpToStdout() {
for (const annotation of this.annotations) {
core.info(annotation.message);
}
}

private getBucket(): Array<octokit.ChecksCreateParamsOutputAnnotations> {
// TODO: Use slice or smth?
let annotations: Array<octokit.ChecksCreateParamsOutputAnnotations> = [];
Expand Down
4 changes: 2 additions & 2 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,9 @@ export async function run(actionInput: input.Input): Promise<void> {
}

async function main(): Promise<void> {
const actionInput = input.get();

try {
const actionInput = input.get();

await run(actionInput);
} catch (error) {
core.setFailed(error.message);
Expand Down

0 comments on commit 8bca5ed

Please sign in to comment.