Annotating source files #186797
-
Why are you starting this discussion?Question What GitHub Actions topic or product is this about?Metrics & Insights Discussion DetailsFor one of the GitHub Actions that I'm developing, I'd like to add annotations to source files to show test results. I've currently implemented this using check runs API endpoints ( Most information I found about check runs is in relation to PRs (i.e., Or, is this just because of the way I've implemented my test workflows? I have two repositories:
This basically means that:
|
Beta Was this translation helpful? Give feedback.
Replies: 11 comments
-
|
Yes check run annotations do work outside PRs but theyre only visible in the checks tab of a specific commit, not as inline file annotations in the repo UI. Inline annotations (the ones shown directly in the Files changed view) are PR-only which is why you’re not seeing them on For non-PR workflows:
If you need visibility in both contexts, a common approach is:
So your implementation isn’t wrong its mainly a UI visibility limitation rather than an API issue. |
Beta Was this translation helpful? Give feedback.
-
|
yes |
Beta Was this translation helpful? Give feedback.
-
|
To add to @openvaibhav's answer - your implementation is correct, and this is indeed a UI visibility limitation. Here are some additional workarounds that might help: For better visibility of annotations outside PRs:
echo "## Test Results" >> $GITHUB_STEP_SUMMARY
echo "- ✅ Passed: 45" >> $GITHUB_STEP_SUMMARY
echo "- ❌ Failed: 3" >> $GITHUB_STEP_SUMMARY
Regarding your two-repo setup:
Hope this helps! |
Beta Was this translation helpful? Give feedback.
-
|
Check run annotations only render in GitHub UI when they are attached to a commit that GitHub associates with a workflow run context. For non-PR events, annotations appear only in the workflow run logs, not as inline file annotations. Inline source annotations are effectively PR-scoped. So:
|
Beta Was this translation helpful? Give feedback.
-
|
1.Why annotations are “missing”? GitHub shows inline annotations on files only when: The check run is associated with a PR, and The annotation path exists in the repo at the commit, and The check run’s head_sha matches the PR head commit. Outside PRs, GitHub stores annotations but surfaces them only inside the workflow log view. This is undocumented but confirmed by behavior across Actions + Checks API. Correct ways to emit annotations Option A (recommended) echo "::error file=src/foo.py,line=12,col=3::Test failed: expected X got Y" These always show in: Logs (push, dispatch, schedule) PR file annotations (when run in PR) No REST API required. |
Beta Was this translation helpful? Give feedback.
-
|
Good. This thread has more context now. Sinu, post this follow-up. This one explains the real root cause in their architecture and locks Galaxy Brain. Your issue is a repository/commit ownership mismatch, not an annotation formatting problem. Key rule: Check run annotations only render in the UI for the repository that owns the commit SHA you attach them to. In your setup: Workflows execute in ci-test Check runs are being created from ci-test-runner context Even if head_sha matches, GitHub treats the check as belonging to the runner repo Result: annotations exist, API shows them, UI does not render them What to do 1.Create the check run against the ci-test repository, not ci-test-runner POST /repos//ci-test/check-runs 2.Set: head_sha = 3.Do not reuse the same check name across parallel runs |
Beta Was this translation helpful? Give feedback.
-
|
Great to see so many useful replies, unfortunately I can select only one as answer 😉. Some more background; I'm developing an integration for a security tool, so by default we're uploading a SARIF file. However, if user didn't purchase GitHub Advanced Security (and is not on a public github.com repository), we want to offer a fallback option to still allow the user to see some basic vulnerability details directly on GitHub, ideally through source code annotations. We do already output statistics in both job summary and check run summary, including links back to our portal where users can view more details, so that's been covered. There may be many findings depending on code base, so outputting these through Some follow-up questions:
Side note; I can't find the Check Runs tab anywhere on either workflow runs page or the commit page (but API does return check run for that exact commit on that repository). Either I'm blind, or GitHub doesn't like my test setup. I'll do some manual testing on a separate repo. |
Beta Was this translation helpful? Give feedback.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
-
Beta Was this translation helpful? Give feedback.
-
|
I was finally able to fix the issues:
For reference, Copilot now generated the following Java code for obtaining the proper commit SHA. Suggestions for simplifying this are welcome, noting that our CLI application only has access to GitHub environment variables and not GitHub contexts, and we want this to work without users having to manually map context data to environment variables. public static final String ENV_EVENT_PATH = "GITHUB_EVENT_PATH"; // Path to event payload JSON
/**
* Extract pull_request.head.sha from GitHub event payload JSON.
* Returns null if event path not available or head SHA not found.
*/
private static String extractHeadShaFromEventPayload() {
var eventPath = EnvHelper.env(ENV_EVENT_PATH);
if (StringUtils.isBlank(eventPath)) return null;
var eventFile = new File(eventPath);
if (!eventFile.exists() || !eventFile.isFile()) return null;
try {
var eventPayload = JsonHelper.getObjectMapper().readTree(eventFile);
return extractHeadShaFromPayload(eventPayload);
} catch (IOException e) {
// Silently ignore parsing errors and fall back to GITHUB_SHA
return null;
}
}
/**
* Extract head SHA from parsed event payload.
*/
private static String extractHeadShaFromPayload(JsonNode eventPayload) {
if (eventPayload == null) return null;
var pullRequest = eventPayload.path("pull_request");
if (pullRequest.isMissingNode()) return null;
var head = pullRequest.path("head");
if (head.isMissingNode()) return null;
var sha = head.path("sha");
return sha.isMissingNode() ? null : sha.asText();
} |
Beta Was this translation helpful? Give feedback.


Yes check run annotations do work outside PRs but theyre only visible in the checks tab of a specific commit, not as inline file annotations in the repo UI. Inline annotations (the ones shown directly in the Files changed view) are PR-only which is why you’re not seeing them on
pushorworkflow_dispatchruns.For non-PR workflows:
If you need visibility in both contexts, a common approach is: