Skip to content

Commit e47ea19

Browse files
committed
Merge master to update CI workflows
2 parents 6c56cf3 + 27217b4 commit e47ea19

5 files changed

Lines changed: 121 additions & 33 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: 14 additions & 14 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

@@ -1228,7 +1228,7 @@ Kani verifies:
12281228

12291229
- **Prusti** :warning: — A static verifier for Rust, based on the Viper verification infrastructure. By default Prusti verifies absence of panics by proving that statements such as unreachable!() and panic!() are unreachable.
12301230

1231-
- **Rudra** :warning: — Rust Memory Safety & Undefined Behavior Detection. It is capable of analyzing single Rust packages as well as all the packages on crates.io.
1231+
- [Rudra](https://github.com/sslab-gatech/Rudra) — Rust Memory Safety & Undefined Behavior Detection. It is capable of analyzing single Rust packages as well as all the packages on crates.io.
12321232

12331233
- **Rust Language Server** :warning: — Supports functionality such as 'goto definition', symbol search, reformatting, and code completion, and enables renaming and refactorings.
12341234

@@ -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

@@ -1662,7 +1662,7 @@ orchestration to ensure zero breaking changes. Specialized for React, Next.js, a
16621662

16631663
- [Teamscale](https://teamscale.com) :copyright: — Static and dynamic analysis tool supporting more than 25 languages and direct IDE integration. Free hosting for Open Source projects available on request. Free academic licenses available.
16641664

1665-
- [TencentCodeAnalysis](https://tca.tencent.com/) — Tencent Cloud Code Analysis (TCA for short, code-named CodeDog inside the company early) is a comprehensive platform for code analysis and issue tracking. TCA consist of three components, server, web and client. It integrates of a number of self-developed tools, and also supports dynamic integration of code analysis tools in various programming languages.
1665+
- **TencentCodeAnalysis** :warning: — Tencent Cloud Code Analysis (TCA for short, code-named CodeDog inside the company early) is a comprehensive platform for code analysis and issue tracking. TCA consist of three components, server, web and client. It integrates of a number of self-developed tools, and also supports dynamic integration of code analysis tools in various programming languages.
16661666

16671667
- [ThreatMapper](https://github.com/deepfence/ThreatMapper) — Vulnerability Scanner and Risk Evaluation for containers, serverless and hosts at runtime. ThreatMapper generates runtime BOMs from dependencies and operating system packages, matches against multiple threat feeds, scans for unprotected secrets, and scores issues based on severity and risk-of-exploit.
16681668

@@ -1722,10 +1722,10 @@ orchestration to ensure zero breaking changes. Specialized for React, Next.js, a
17221722
<h2>Archive</h2>
17231723

17241724

1725-
- [alquitran](https://github.com/ferivoz/alquitran) — Inspects tar archives and tries to spot portability issues in regard to POSIX 2017 pax specification and common tar implementations.
1725+
- **alquitran** :warning: — Inspects tar archives and tries to spot portability issues in regard to POSIX 2017 pax specification and common tar implementations.
17261726
This project is intended to be used by maintainers of projects who want to offer portable source code archives for as many systems as possible. Checking tar archives with alquitran before publishing them should help spotting issues before they reach distributors and users.
17271727

1728-
- **packj** :warning: — Packj (pronounced package) is a command line (CLI) tool to vet open-source software packages for "risky" attributes that make them vulnerable to supply chain attacks. This is the tool behind our large-scale security analysis platform Packj.dev that continuously vets packages and provides free reports.
1728+
- [packj](https://github.com/ossillate-inc/packj) — Packj (pronounced package) is a command line (CLI) tool to vet open-source software packages for "risky" attributes that make them vulnerable to supply chain attacks. This is the tool behind our large-scale security analysis platform Packj.dev that continuously vets packages and provides free reports.
17291729

17301730
- **pure** :warning: — Pure is a static analysis file format checker that checks ZIP files for dangerous compression ratios, spec deviations, malicious archive signatures, mismatching local and central directory headers, ambiguous UTF-8 filenames, directory and symlink traversals, invalid MS-DOS dates, overlapping headers, overflow, underflow, sparseness, accidental buffer bleeds etc.
17311731

@@ -1887,7 +1887,7 @@ Loading address: binbloom can parse a raw binary firmware and determine its load
18871887

18881888
- **Docker Label Inspector** :warning: — Lint and validate Dockerfile labels.
18891889

1890-
- **Dockle** :warning: — Container Image Linter for Security helping build the Best-Practice Docker Image. Scans Docker images for security vulnerabilities and CIS Benchmark compliance. Checks for secrets, credential exposure, and security best practices. Provides multiple severity levels (FATAL, WARN, INFO) and supports various output formats for CI/CD integration.
1890+
- [Dockle](https://github.com/goodwithtech/dockle) — Container Image Linter for Security helping build the Best-Practice Docker Image. Scans Docker images for security vulnerabilities and CIS Benchmark compliance. Checks for secrets, credential exposure, and security best practices. Provides multiple severity levels (FATAL, WARN, INFO) and supports various output formats for CI/CD integration.
18911891

18921892
- [GitGuardian ggshield](https://www.gitguardian.com/ggshield) — ggshield is a CLI application that runs in your local environment or in a CI environment to help you detect more than 350+ types of secrets, as well as other potential security vulnerabilities or policy breaks affecting your codebase.
18931893

@@ -1977,7 +1977,7 @@ Its technology helps developers automate testing, find bugs, and reduce manual l
19771977

19781978
- [Code Pathfinder](https://codepathfinder.dev) — An open-source security suite aiming to combine structural code analysis with AI-powered vulnerability detection. Built for advanced structural search, derive insights, find vulnerabilities in code.
19791979

1980-
- **Dockle** :warning: — Container Image Linter for Security helping build the Best-Practice Docker Image. Scans Docker images for security vulnerabilities and CIS Benchmark compliance. Checks for secrets, credential exposure, and security best practices. Provides multiple severity levels (FATAL, WARN, INFO) and supports various output formats for CI/CD integration.
1980+
- [Dockle](https://github.com/goodwithtech/dockle) — Container Image Linter for Security helping build the Best-Practice Docker Image. Scans Docker images for security vulnerabilities and CIS Benchmark compliance. Checks for secrets, credential exposure, and security best practices. Provides multiple severity levels (FATAL, WARN, INFO) and supports various output formats for CI/CD integration.
19811981

19821982

19831983
<a name="embedded" />
@@ -2068,7 +2068,7 @@ Its technology helps developers automate testing, find bugs, and reduce manual l
20682068
- [krane](https://github.com/appvia/krane) — Krane is a simple Kubernetes RBAC static analysis tool.
20692069
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.
20702070

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

20732073
- [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.
20742074

@@ -2284,7 +2284,7 @@ but with the following improvements:
22842284
- [detect-secrets](https://github.com/Yelp/detect-secrets) — An enterprise friendly way of detecting and preventing secrets in code.
22852285
It does this by running periodic diff outputs against heuristically crafted regex statements, to identify whether any new secret has been committed. This way, it avoids the overhead of digging through all git history, as well as the need to scan the entire repository every time.
22862286

2287-
- **Dockle** :warning: — Container Image Linter for Security helping build the Best-Practice Docker Image. Scans Docker images for security vulnerabilities and CIS Benchmark compliance. Checks for secrets, credential exposure, and security best practices. Provides multiple severity levels (FATAL, WARN, INFO) and supports various output formats for CI/CD integration.
2287+
- [Dockle](https://github.com/goodwithtech/dockle) — Container Image Linter for Security helping build the Best-Practice Docker Image. Scans Docker images for security vulnerabilities and CIS Benchmark compliance. Checks for secrets, credential exposure, and security best practices. Provides multiple severity levels (FATAL, WARN, INFO) and supports various output formats for CI/CD integration.
22882288

22892289
- **Enlightn** :warning: — A static and dynamic analysis tool for Laravel applications that provides recommendations to improve the performance, security and code reliability of Laravel apps. Contains 120 automated checks.
22902290

@@ -2296,7 +2296,7 @@ It does this by running periodic diff outputs against heuristically crafted rege
22962296

22972297
- [Grype](https://github.com/anchore/grype) — Vulnerability scanner for container images and filesystems. Developed by Anchore, it scans container images, directories, and archives for known vulnerabilities. Supports multiple image formats, SBOM integration, and VEX (Vulnerability Exploitability eXchange) for accurate vulnerability assessment. Works with various vulnerability databases and provides detailed reporting.
22982298

2299-
- [HasMySecretLeaked](https://gitguardian.com/hasmysecretleaked) :copyright: — HasMySecretLeaked is a project from GitGuardian that aims to help individual users and organizations search across 20 million exposed secrets to verify if their developer secrets have leaked on public repositories, gists, and issues on GitHub projects.
2299+
- **HasMySecretLeaked** :warning: :copyright: — HasMySecretLeaked is a project from GitGuardian that aims to help individual users and organizations search across 20 million exposed secrets to verify if their developer secrets have leaked on public repositories, gists, and issues on GitHub projects.
23002300

23012301
- **iblessing** :warning: — iblessing is an iOS security exploiting toolkit. It can be used for reverse engineering, binary analysis and vulnerability mining.
23022302

@@ -2313,7 +2313,7 @@ Kani verifies:
23132313

23142314
- [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
23152315

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

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

@@ -2461,7 +2461,7 @@ TruffleHog is an open source secret-scanning engine that resolves exposed secret
24612461

24622462
- [GitGuardian ggshield](https://www.gitguardian.com/ggshield) — ggshield is a CLI application that runs in your local environment or in a CI environment to help you detect more than 350+ types of secrets, as well as other potential security vulnerabilities or policy breaks affecting your codebase.
24632463

2464-
- [HasMySecretLeaked](https://gitguardian.com/hasmysecretleaked) :copyright: — HasMySecretLeaked is a project from GitGuardian that aims to help individual users and organizations search across 20 million exposed secrets to verify if their developer secrets have leaked on public repositories, gists, and issues on GitHub projects.
2464+
- **HasMySecretLeaked** :warning: :copyright: — HasMySecretLeaked is a project from GitGuardian that aims to help individual users and organizations search across 20 million exposed secrets to verify if their developer secrets have leaked on public repositories, gists, and issues on GitHub projects.
24652465

24662466

24672467
## More Collections

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 {

0 commit comments

Comments
 (0)