Skip to content

Commit a655fa9

Browse files
committed
Merge master to update CI workflows
2 parents 373e240 + 27217b4 commit a655fa9

5 files changed

Lines changed: 106 additions & 18 deletions

File tree

.github/workflows/pr-check.yml

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ jobs:
1919
pr-check:
2020
runs-on: ubuntu-latest
2121
permissions:
22-
pull-requests: write
2322
contents: read
2423
steps:
2524
- uses: actions/checkout@v4
@@ -62,9 +61,35 @@ jobs:
6261
run: cargo build --release --manifest-path ci/Cargo.toml -p pr-check
6362

6463
- name: Run pr-check
64+
id: run-check
6565
env:
6666
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
6767
GITHUB_REPOSITORY: ${{ github.repository }}
6868
PR_NUMBER: ${{ github.event_name == 'workflow_dispatch' && inputs.pr_number || github.event.pull_request.number }}
69+
# For pull_request events (including forks), write the comment to a
70+
# file instead of posting it directly. The fork's GITHUB_TOKEN does
71+
# not have write access to the base repository, so direct posting
72+
# returns 403. The pr-comment workflow picks up this artifact and
73+
# posts the comment with the right permissions.
74+
COMMENT_OUTPUT_FILE: ${{ github.event_name == 'pull_request' && 'pr-check-output/comment.md' || '' }}
6975
run: |
70-
ci/target/release/pr-check ${{ steps.changed.outputs.files }}
76+
mkdir -p pr-check-output
77+
echo "$PR_NUMBER" > pr-check-output/pr_number.txt
78+
if ci/target/release/pr-check ${{ steps.changed.outputs.files }}; then
79+
echo "passed" > pr-check-output/result.txt
80+
else
81+
echo "failed" > pr-check-output/result.txt
82+
fi
83+
84+
- name: Upload check results
85+
if: always() && github.event_name == 'pull_request'
86+
uses: actions/upload-artifact@v4
87+
with:
88+
name: pr-check-output
89+
path: pr-check-output/
90+
91+
- name: Fail if checks did not pass
92+
if: always()
93+
run: |
94+
result=$(cat pr-check-output/result.txt 2>/dev/null || echo "failed")
95+
[ "$result" = "passed" ]

.github/workflows/pr-comment.yml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
name: PR Check Comment
2+
3+
on:
4+
workflow_run:
5+
workflows: ["PR Check"]
6+
types: [completed]
7+
8+
jobs:
9+
comment:
10+
runs-on: ubuntu-latest
11+
permissions:
12+
pull-requests: write
13+
steps:
14+
- name: Download check results
15+
uses: actions/download-artifact@v4
16+
with:
17+
name: pr-check-output
18+
github-token: ${{ secrets.GITHUB_TOKEN }}
19+
run-id: ${{ github.event.workflow_run.id }}
20+
continue-on-error: true
21+
22+
- name: Post or update PR comment
23+
if: hashFiles('pr_number.txt') != '' && hashFiles('comment.md') != ''
24+
env:
25+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
26+
GH_REPO: ${{ github.repository }}
27+
run: |
28+
PR_NUMBER=$(cat pr_number.txt)
29+
COMMENT_BODY=$(cat comment.md)
30+
31+
EXISTING_ID=$(gh api "repos/$GH_REPO/issues/$PR_NUMBER/comments" \
32+
--jq '[.[] | select(.body | contains("<!-- pr-check-bot -->"))] | first | .id // empty')
33+
34+
if [ -n "$EXISTING_ID" ]; then
35+
gh api --method PATCH "repos/$GH_REPO/issues/comments/$EXISTING_ID" \
36+
--field body="$COMMENT_BODY"
37+
else
38+
gh api --method POST "repos/$GH_REPO/issues/$PR_NUMBER/comments" \
39+
--field body="$COMMENT_BODY"
40+
fi

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -497,7 +497,7 @@ Fprettify is a tool that provides consistent whitespace, indentation, and delimi
497497

498498
- [errcheck](https://github.com/kisielk/errcheck) — Check that error return values are used.
499499

500-
- [errwrap](https://github.com/fatih/errwrap) — Wrap and fix Go errors with the new %w verb directive. This tool analyzes fmt.Errorf() calls and reports calls that contain a verb directive that is different than the new %w verb directive introduced in Go v1.13. It's also capable of rewriting calls to use the new %w wrap verb directive.
500+
- **errwrap** :warning: — Wrap and fix Go errors with the new %w verb directive. This tool analyzes fmt.Errorf() calls and reports calls that contain a verb directive that is different than the new %w verb directive introduced in Go v1.13. It's also capable of rewriting calls to use the new %w wrap verb directive.
501501

502502
- [flen](https://github.com/lafolle/flen) — Get info on length of functions in a Go package.
503503

@@ -556,7 +556,7 @@ By default, govulncheck makes requests to the Go vulnerability database at https
556556

557557
- [misspell](https://github.com/client9/misspell) — Finds commonly misspelled English words.
558558

559-
- [nakedret](https://github.com/alexkohler/nakedret) — Finds naked returns.
559+
- **nakedret** :warning: — Finds naked returns.
560560

561561
- [nargs](https://github.com/alexkohler/nargs) — Finds unused arguments in function declarations.
562562

@@ -1334,7 +1334,7 @@ Kani verifies:
13341334

13351335
- **Codelyzer** :warning: — A set of tslint rules for static code analysis of Angular 2 TypeScript projects.
13361336

1337-
- [ENRE-ts](https://github.com/xjtu-enre/ENRE-ts) — ENRE (ENtity Relationship Extractor) is a tool for extraction of code entity dependencies or relationships from source code. ENRE-ts is a ENtity Relationship Extractor for ECMAScript and TypeScript based on @babel/parser.
1337+
- **ENRE-ts** :warning: — ENRE (ENtity Relationship Extractor) is a tool for extraction of code entity dependencies or relationships from source code. ENRE-ts is a ENtity Relationship Extractor for ECMAScript and TypeScript based on @babel/parser.
13381338

13391339
- [fta](https://ftaproject.dev/) — Rust-based static analysis for TypeScript projects
13401340

@@ -2070,7 +2070,7 @@ Its technology helps developers automate testing, find bugs, and reduce manual l
20702070
- [krane](https://github.com/appvia/krane) — Krane is a simple Kubernetes RBAC static analysis tool.
20712071
It identifies potential security risks in K8s RBAC design and makes suggestions on how to mitigate them. Krane dashboard presents current RBAC security posture and lets you navigate through its definition.
20722072

2073-
- **kube-hunter** :warning: — Hunt for security weaknesses in Kubernetes clusters.
2073+
- [kube-hunter](https://aquasecurity.github.io/kube-hunter/) — Hunt for security weaknesses in Kubernetes clusters.
20742074

20752075
- [kube-lint](https://github.com/viglesiasce/kube-lint) — A linter for Kubernetes resources with a customizable rule set. You define a list of rules that you would like to validate against your resources and kube-lint will evaluate those rules against them.
20762076

@@ -2315,7 +2315,7 @@ Kani verifies:
23152315

23162316
- [kics](https://kics.io/) — Find security vulnerabilities, compliance issues, and infrastructure misconfigurations in your infrastructure-as-code. Supports Terraform, Kubernetes, Docker, AWS CloudFormation and Ansible
23172317

2318-
- **kube-hunter** :warning: — Hunt for security weaknesses in Kubernetes clusters.
2318+
- [kube-hunter](https://aquasecurity.github.io/kube-hunter/) — Hunt for security weaknesses in Kubernetes clusters.
23192319

23202320
- [lockfile-lint](https://github.com/lirantal/lockfile-lint) — Lint an npm or yarn lockfile to analyze and detect security issues
23212321

ci/pr-check/src/main.rs

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,22 @@
99
//! - More than one contributor
1010
//! - Repository is at least 3 months old
1111
//!
12-
//! The results are posted as a single comment on the PR (updating an existing
13-
//! bot comment if one already exists). The process exits with a non-zero status
14-
//! code when any hard criterion is not met, causing CI to fail.
12+
//! The results are either posted as a single comment on the PR (updating an
13+
//! existing bot comment if one already exists) or written to a file when the
14+
//! `COMMENT_OUTPUT_FILE` environment variable is set. The latter mode is used
15+
//! in CI to work around the GitHub Actions restriction that prevents fork PRs
16+
//! from writing to the base repository. A separate `pr-comment` workflow then
17+
//! picks up the file and posts the comment with the necessary permissions.
18+
//!
19+
//! The process exits with a non-zero status code when any hard criterion is
20+
//! not met, causing CI to fail.
1521
//!
1622
//! Expected environment variables:
17-
//! GITHUB_TOKEN - a token with `pull-requests: write` permission
18-
//! GITHUB_REPOSITORY - owner/repo, e.g. "analysis-tools-dev/static-analysis"
19-
//! PR_NUMBER - the pull request number
23+
//! GITHUB_TOKEN - a token with `pull-requests: write` permission
24+
//! GITHUB_REPOSITORY - owner/repo, e.g. "analysis-tools-dev/static-analysis"
25+
//! PR_NUMBER - the pull request number
26+
//! COMMENT_OUTPUT_FILE - (optional) path to write the rendered comment body
27+
//! to instead of posting it directly via the API.
2028
2129
use anyhow::{Context, Result, bail};
2230
use askama::Template;
@@ -470,7 +478,22 @@ async fn main() -> Result<()> {
470478

471479
let comment_body = render_comment(&reports)?;
472480

473-
upsert_comment(&client, &gh_repo, pr_number, &comment_body).await?;
481+
// If COMMENT_OUTPUT_FILE is set, write the comment to that file instead of
482+
// posting it via the API. This is used by the `pull_request` CI workflow to
483+
// avoid the 403 that GitHub returns when a fork PR tries to write comments.
484+
// A separate `pr-comment` workflow picks up the file and posts the comment
485+
// with the write permissions it has as a `workflow_run` job.
486+
if let Ok(output_file) = env::var("COMMENT_OUTPUT_FILE") {
487+
if let Some(parent) = std::path::Path::new(&output_file).parent() {
488+
std::fs::create_dir_all(parent)
489+
.with_context(|| format!("Failed to create directory for {output_file}"))?;
490+
}
491+
std::fs::write(&output_file, &comment_body)
492+
.with_context(|| format!("Failed to write comment to {output_file}"))?;
493+
eprintln!("Comment written to {output_file}");
494+
} else {
495+
upsert_comment(&client, &gh_repo, pr_number, &comment_body).await?;
496+
}
474497

475498
let any_failures = reports.iter().any(|r| r.any_fail());
476499
if any_failures {

data/api/tools.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6987,7 +6987,7 @@
69876987
"plans": null,
69886988
"description": "ENRE (ENtity Relationship Extractor) is a tool for extraction of code entity dependencies or relationships from source code. ENRE-ts is a ENtity Relationship Extractor for ECMAScript and TypeScript based on @babel/parser.",
69896989
"discussion": null,
6990-
"deprecated": null,
6990+
"deprecated": true,
69916991
"resources": null,
69926992
"reviews": null,
69936993
"demos": null,
@@ -7129,7 +7129,7 @@
71297129
"plans": null,
71307130
"description": "Wrap and fix Go errors with the new %w verb directive. This tool analyzes fmt.Errorf() calls and reports calls that contain a verb directive that is different than the new %w verb directive introduced in Go v1.13. It's also capable of rewriting calls to use the new %w wrap verb directive.",
71317131
"discussion": null,
7132-
"deprecated": null,
7132+
"deprecated": true,
71337133
"resources": null,
71347134
"reviews": null,
71357135
"demos": null,
@@ -11044,7 +11044,7 @@
1104411044
"plans": null,
1104511045
"description": "Hunt for security weaknesses in Kubernetes clusters.",
1104611046
"discussion": null,
11047-
"deprecated": true,
11047+
"deprecated": null,
1104811048
"resources": null,
1104911049
"reviews": null,
1105011050
"demos": null,
@@ -12889,7 +12889,7 @@
1288912889
"plans": null,
1289012890
"description": "Finds naked returns.",
1289112891
"discussion": null,
12892-
"deprecated": null,
12892+
"deprecated": true,
1289312893
"resources": null,
1289412894
"reviews": null,
1289512895
"demos": null,

0 commit comments

Comments
 (0)