[Flang] Github action to check for integration tests #221766
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-github-workflow
Author: Kiran Chandramohan (kiranchandramohan)
<details>
<summary>Changes</summary>
---
Full diff: https://github.com/llvm/llvm-project/pull/221766.diff
1 Files Affected:
````````````diff --git a/.github/workflows/flang-integration-test-check.yml b/.github/workflows/flang-integration-test-check.yml
new file mode 100644
index 0000000000000..452b650db0beb
--- /dev/null
+++ b/.github/workflows/flang-integration-test-check.yml
@@ -0,0 +1,104 @@
+name: Flang integration test check
+
+on:
+ pull_request_target:
+ types: [opened, synchronize, reopened]
+ paths:
+ - "flang/test/**"
+
+# This workflow only inspects file patches through the GitHub API. In
+# particular, it must not check out or execute code from the pull request.
+permissions:
+ contents: read
+ pull-requests: write
+
+jobs:
+ check-for-full-pipeline-tests:
+ runs-on: ubuntu-24.04
+ steps:
+ - name: Check for new full-pipeline test invocations
+ uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
+ with:
+ script: |
+ const marker = "<!-- flang-integration-test-check -->";
+ const pr = context.payload.pull_request;
+
+ const files = await github.paginate(
+ github.rest.pulls.listFiles,
+ {
+ owner: context.repo.owner,
+ repo: context.repo.repo,
+ pull_number: pr.number,
+ per_page: 100,
+ },
+ );
+
+ const findings = [];
+ for (const file of files) {
+ if (!file.filename.startsWith("flang/test/") || !file.patch)
+ continue;
+
+ // Only report newly added uses. Existing full-pipeline tests do
+ // not need to be justified again when an unrelated line changes.
+ const addsEmitLLVM = file.patch.split("\n").some(
+ line => /^\+(?!\+\+)/.test(line) && /\bRUN:/.test(line) &&
+ /(^|\s)-emit-llvm(?=\s|=|$)/.test(line),
+ );
+ if (addsEmitLLVM)
+ findings.push(`- \`${file.filename}\``);
+ }
+
+ const comments = await github.paginate(
+ github.rest.issues.listComments,
+ {
+ owner: context.repo.owner,
+ repo: context.repo.repo,
+ issue_number: pr.number,
+ per_page: 100,
+ },
+ );
+ const previous = comments.find(
+ comment => comment.user.type === "Bot" && comment.body.includes(marker),
+ );
+
+ if (findings.length === 0) {
+ if (previous) {
+ await github.rest.issues.deleteComment({
+ owner: context.repo.owner,
+ repo: context.repo.repo,
+ comment_id: previous.id,
+ });
+ }
+ return;
+ }
+
+ const body = [
+ marker,
+ "This pull request adds a Flang test invocation that exercises the compiler " +
+ "pipeline through LLVM IR generation:",
+ "",
+ findings.join("\n"),
+ "",
+ "Please consider whether the same behavior can be covered by a focused test " +
+ "that stops at the relevant compiler stage. If LLVM IR generation is " +
+ "necessary, add a nearby, test-specific comment explaining why. See the " +
+ "[Flang integration test guidance](https://github.com/llvm/llvm-project/blob/main/flang/test/Integration/README.md).",
+ "",
+ "_This is an informational reminder; it does not fail the workflow._",
+ ].join("\n");
+
+ if (previous) {
+ await github.rest.issues.updateComment({
+ owner: context.repo.owner,
+ repo: context.repo.repo,
+ comment_id: previous.id,
+ body,
+ });
+ } else {
+ await github.rest.issues.createComment({
+ owner: context.repo.owner,
+ repo: context.repo.repo,
+ issue_number: pr.number,
+ body,
+ });
+ }
</details>
zizmor /
use of fundamentally insecure workflow trigger: pull_request_target is almost always used insecurely
LGTM.
Thanks
I'm running a couple of checks for this, please wait for my comment before merging.
Why can't we use the existing issue comment workflow to avoid this?
Requested changes.
Thanks @boomanaiden154 for the suggestion. Assuming you meant https://github.com/llvm/llvm-project/blob/main/.github/workflows/issue-write.yml. I will have a look to see whether i can modify the PR to use this.
The change in this file needs to land in a separate PR if you want to test the flang-integration-test-check workflow in this PR.
The detector re-flags tests it has already accepted, which contradicts the comment directly above it. Because a reindent or an added option appears as a removed/added pair, the + side alone still matches. Two patches that produce a reminder today:
@@ -1,2 +1,2 @@
-! RUN: %flang_fc1 -emit-llvm %s -o -
+! RUN: %flang_fc1 -emit-llvm %s -o -
@@ -1,2 +1,2 @@
-! RUN: %flang_fc1 -emit-llvm %s -o -
+! RUN: %flang_fc1 -emit-llvm -O2 %s -o -
Neither adds an invocation; the first only reindents and the second adds an option. Over the 2868 commits touching flang/test since 2024-01-01, the current rule flags 310 file-touches against 235 for a net count, and every one of the ~75 differences is an edit to an invocation that already existed.
The same block is where three other things are worth fixing at once, hence a single suggestion.
-emit-llvm-bc and -emit-obj are missed. -emit-llvm-bc is excluded only as an artifact of the (?=\s|=|$) lookahead, yet it is real (flang -fc1 -emit-llvm-bc succeeds) and is what flang/test/Integration/OpenMP/host-ir-flag.f90:9 uses. -emit-obj drives the pipeline further still.
lit DEFINE: and REDEFINE: lines are invisible. They carry the only in-tree DEFINE'd -emit-llvm invocations, including two Integration/ tests this regex cannot see at all. flang/test/Integration/unroll-loops.f90 is one: its command lives on a DEFINE: line and its RUN lines only expand the substitution.
The filename is interpolated into a code span unescaped. A path containing a backtick closes that span, so the remainder of the path is rendered as Markdown rather than shown literally. Given a file added at the first path below, the current code emits the second line, in which the team handle has escaped the code span and posts as a live mention authored by github-actions[bot]:
flang/test/Integration/a`@llvm/pr-subscribers-flang`b.f90
- `flang/test/Integration/a`@llvm/pr-subscribers-flang`b.f90`
Counting flag tokens rather than lines also handles two invocations joined by && on a single RUN line. Two limits are worth stating in the comment, which is why the suggestion spells them out: removing a DEFINE:d invocation cancels detection of an added RUN: that carries one, and a rewritten invocation is not distinguished from a replaced one.
// lit directives that can carry a compiler invocation, and the flags
// that drive the pipeline at least as far as LLVM IR generation.
const directive = /\b(RUN|DEFINE|REDEFINE):/;
const fullPipeline = /(^|\s)(-emit-llvm(-bc)?|-emit-obj)(?=\s|=|$)/g;
// Only report net-new uses. Reindenting an existing line, or adding an
// option to it, shows up as a removed/added pair, so count both sides.
// Heuristic: counts flag tokens rather than lines, and cannot tell a
// rewritten invocation from a replaced one.
const lines = file.patch.split("\n");
const countFlags = line =>
directive.test(line) ? (line.match(fullPipeline) || []).length : 0;
const total = (ls, sign) => ls.filter(line => sign.test(line))
.reduce((n, line) => n + countFlags(line), 0);
if (total(lines, /^\+(?!\+\+)/) > total(lines, /^-(?!--)/))
findings.push(`- \`${file.filename.replace(/[`\r\n]/g, "'")}\``);
Measured with the harness in the review summary, before → after: reindent create → no-op; added -O2 create → no-op; -emit-obj no-op → create; -emit-llvm-bc no-op → create; DEFINE: no-op → create; a genuinely new RUN: ... -emit-llvm stays create; and the injected path above comes back with the backticks replaced by apostrophes, so it stays inert. I also ran the real refactor in 6cb71d7e85d5, which turns four RUN: ... -emit-llvm lines into two DEFINE:d ones: the current rule flags that NFC commit, a per-directive counter also flags it, and a single token counter correctly does not.
Small hardening on the lookup, now that it is the thing standing between this workflow and someone else's comment.
comment.user.login throws if user is null, and comment.body.includes throws if body is null; either one fails the run. Measured on the current code:
comment with null body → TypeError: Cannot read properties of null (reading 'includes')
comment with null user → TypeError: Cannot read properties of null (reading 'login')
startsWith is also strictly tighter than includes and costs nothing here, since both bodies this workflow writes begin with the marker. It keeps the guard robust against any future github-actions[bot] comment that happens to quote a patch containing the marker — pr-code-format.yml and pr-code-lint.yml both post diffs under that same login.
const previous = comments.find(
comment => comment.user && comment.user.login === "github-actions[bot]" &&
typeof comment.body === "string" && comment.body.startsWith(marker),
);
With this, both cases above become clean no-ops and the existing behaviour is unchanged: the workflow's own comment is still found and updated, and this PR's real comment payload still yields no match.
Worth adding a concurrency group and a timeout here. synchronize fires per push and pushes arrive in bursts, and there is no comment id on the create path, so two overlapping runs each upload an artifact and issue-write.yml runs twice, creating two reminder comments. I measured that on the previous revision's direct-write code as two createComment calls from two interleaved runs; the artifact hand-off moves where it happens but not whether it can.
pr-code-format.yml sets both, keyed the same way:
runs-on: ubuntu-24.04
timeout-minutes: 10
# Overlapping runs would each upload an artifact and each create a comment,
# so serialize rather than cancel: an in-flight upload cannot be retracted.
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number }}
cancel-in-progress: false
I would suggest cancel-in-progress: false rather than pr-code-format.yml's true: cancellation is asynchronous and cannot retract an upload that is already in flight, whereas serializing is essentially free for a job that runs in seconds. Since the script reads live PR state by number, whichever run goes last leaves the correct final state, so only overlap matters and not ordering.
Minor: files the API gives no patch for are skipped silently, so the reminder can be a false negative with nothing indicating it. listFiles omits patch for very large and binary files and caps out at 3000 entries.
if (!file.filename.startsWith("flang/test/"))
continue;
if (!file.patch) {
// The API omits `patch` for very large or binary files, and caps
// listFiles at 3000 entries. Say so rather than skipping silently.
core.notice(`Not checked (no patch text from the API): ${file.filename}`);
continue;
}
Splitting the condition also makes the two reasons for skipping distinguishable. Measured: a file entry with no patch still produces no comment, and now also emits Not checked (no patch text from the API): flang/test/Integration/big.f90 in the run log.
These are all AI generated comments, but I found them interesting enough to share.
OK. I have created https://github.com/llvm/llvm-project/pull/225500
Added the timeout in https://github.com/llvm/llvm-project/pull/221766/changes/34c0d9f3c7040b599067f61068b306b6c0880b8f
Left out the concurrency part. It seems serializing the Flang jobs does not wait for their separate issue-write.yml jobs. Two sequential Flang runs can still prepare “create comment” artifacts before either writer posts.
These are all AI generated comments, but I found them interesting enough to share.
Thanks @eugeneepshteyn for all the suggestions. I believe, I have added all your suggestions except for the concurrency part. Since the PR changed before your comments, i was not able to apply your suggestions directly in Github. I have added you as co-author in the summary since you had several inline code suggestions.
LGTM, thank you!
LGTM. It would be nice if we could test this before landing, but that can sometimes be difficult.
<!-- flang-integration-test-check -->
No additional full-pipeline test invocations were detected under flang/test/.
tstellar
kiranchandramohan
Adds a GitHub Actions workflow that comments on pull requests introducing -emit-llvm RUN lines under flang/test/ (integration tests). The informational reminder encourages focused tests, or a nearby explanation when LLVM IR generation is necessary. It updates or removes its comment as the PR changes.
The workflow uses pull_request_target to comment on fork PRs, inspects patches only through the GitHub API, and never checks out or executes PR code. It runs only in llvm/llvm-project, with write permission scoped to the commenting job. Also suppresses the zizmor warning for the intentional API-only use of pull_request_target, which never executes PR code and follows the existing security model in new-prs.yml.
Discussed in https://discourse.llvm.org/t/removing-or-reducing-redundant-messages-in-integration-tests/91591
Assisted-by: Codex
Co-authored-by: Eugene Epshteyn <eepshteyn@nvidia.com>