This PR contains the following updates: | Package | Type | Update | Change | Pending | |---|---|---|---|---| | [EnricoMi/publish-unit-test-result-action](https://redirect.github.com/EnricoMi/publish-unit-test-result-action) | action | minor | `v2.23.0` → `v2.24.0` | | | [actions/attest-build-provenance](https://redirect.github.com/actions/attest-build-provenance) | action | patch | `v4.1.0` → `v4.1.1` | | | [actions/checkout](https://redirect.github.com/actions/checkout) | action | patch | `v6.0.2` → `v6.0.3` | | | [actions/checkout](https://redirect.github.com/actions/checkout) | action | patch | `v6.0.1` → `v6.0.3` | | | [actions/create-github-app-token](https://redirect.github.com/actions/create-github-app-token) | action | minor | `v3.1.1` → `v3.2.0` | | | [actions/labeler](https://redirect.github.com/actions/labeler) | action | minor | `v6.0.1` → `v6.2.0` | | | [actions/setup-node](https://redirect.github.com/actions/setup-node) | action | minor | `v6.3.0` → `v6.5.0` | | | [actions/setup-python](https://redirect.github.com/actions/setup-python) | action | minor | `v6.2.0` → `v6.3.0` | | | [actions/upload-artifact](https://redirect.github.com/actions/upload-artifact) | action | patch | `v7.0.0` → `v7.0.1` | | | [aminya/setup-cpp](https://redirect.github.com/aminya/setup-cpp) | action | patch | `v1.8.0` → `v1.8.1` | | | [docker/login-action](https://redirect.github.com/docker/login-action) | action | minor | `v4.1.0` → `v4.4.0` | | | ghcr.io/llvm/amd64/ci-ubuntu-24.04-github-automation | container | digest | `82b5304` → `f419363` | | | ghcr.io/llvm/ci-ubuntu-24.04 | container | digest | `cc4fd65` → `26c16c2` | | | ghcr.io/llvm/ci-ubuntu-24.04-abi-tests | container | digest | `cb3aea3` → `a948062` | | | ghcr.io/llvm/ci-ubuntu-24.04-lint | container | digest | `91665a4` → `416874e` | | | ghcr.io/llvm/libc-ubuntu-24.04 | container | digest | `a902fb5` → `b9c8ea7` | | | [github/codeql-action](https://redirect.github.com/github/codeql-action) | action | minor | `v4.35.2` → `v4.37.0` | `v4.37.1` | | [hendrikmuhs/ccache-action](https://redirect.github.com/hendrikmuhs/ccache-action) | action | patch | `v1.2.22` → `v1.2.23` | | | [zizmorcore/zizmor-action](https://redirect.github.com/zizmorcore/zizmor-action) | action | minor | `v0.5.3` → `v0.6.0` | | (cherry picked from commit 24942433bc8a71b8aa459f802a0962089bb4dd22)
180 lines
6.9 KiB
YAML
180 lines
6.9 KiB
YAML
name: Comment on an issue
|
|
|
|
on:
|
|
workflow_run:
|
|
workflows:
|
|
- "Check code formatting"
|
|
- "Check for private emails used in PRs"
|
|
- "PR Request Release Note"
|
|
- "Code lint"
|
|
- "CI Checks"
|
|
- "Test Issue Write"
|
|
- "Check LLVM ABI annotations"
|
|
- "Diff test-suite codegen"
|
|
types:
|
|
- completed
|
|
|
|
permissions:
|
|
contents: read
|
|
|
|
jobs:
|
|
pr-comment:
|
|
runs-on: ubuntu-24.04
|
|
permissions:
|
|
pull-requests: write
|
|
if: >
|
|
(github.event.workflow_run.event == 'pull_request' ||
|
|
github.event.workflow_run.event == 'issue_comment') &&
|
|
(
|
|
github.event.workflow_run.conclusion == 'success' ||
|
|
github.event.workflow_run.conclusion == 'failure'
|
|
)
|
|
steps:
|
|
- name: Fetch Sources
|
|
uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
|
|
with:
|
|
persist-credentials: false
|
|
sparse-checkout: |
|
|
.github/workflows/unprivileged-download-artifact/action.yml
|
|
sparse-checkout-cone-mode: false
|
|
- name: 'Download artifact'
|
|
uses: ./.github/workflows/unprivileged-download-artifact
|
|
id: download-artifact
|
|
with:
|
|
run-id: ${{ github.event.workflow_run.id }}
|
|
artifact-name: workflow-args
|
|
|
|
- name: 'Comment on PR'
|
|
if: steps.download-artifact.outputs.artifact-ids != ''
|
|
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
|
|
env:
|
|
EVENT_TYPE: ${{ github.event.workflow_run.event }}
|
|
with:
|
|
github-token: ${{ secrets.GITHUB_TOKEN }}
|
|
script: |
|
|
var fs = require('fs');
|
|
var comments = []
|
|
var pr_number = 0
|
|
for (local_file of fs.readdirSync('.')) {
|
|
if (local_file.startsWith("comments")) {
|
|
comments.push(...JSON.parse(fs.readFileSync(local_file)))
|
|
}
|
|
// We can't trust a pr_number that comes from a pull_request event,
|
|
// because the pull_request author has full control over the
|
|
// triggering workflow and could put any number here.
|
|
if (process.env.EVENT_TYPE === "issue_comment" && local_file.startsWith("pr_number")) {
|
|
pr_number = parseInt(fs.readFileSync(local_file), 10)
|
|
}
|
|
}
|
|
if (!comments || comments.length == 0) {
|
|
return;
|
|
}
|
|
|
|
let runInfo = await github.rest.actions.getWorkflowRun({
|
|
owner: context.repo.owner,
|
|
repo: context.repo.repo,
|
|
run_id: context.payload.workflow_run.id
|
|
});
|
|
|
|
console.log(runInfo);
|
|
|
|
|
|
if (!pr_number) {
|
|
// Query to find the number of the pull request that triggered this job.
|
|
// The associated pull requests are based off of the branch name, so if
|
|
// you create a pull request for a branch, close it, and then create
|
|
// another pull request with the same branch, then this query will return
|
|
// two associated pull requests. This is why we have to fetch all the
|
|
// associated pull requests and then iterate through them to find the
|
|
// one that is open.
|
|
const gql_query = `
|
|
query($repo_owner : String!, $repo_name : String!, $branch: String!) {
|
|
repository(owner: $repo_owner, name: $repo_name) {
|
|
ref (qualifiedName: $branch) {
|
|
associatedPullRequests(first: 100) {
|
|
nodes {
|
|
baseRepository {
|
|
owner {
|
|
login
|
|
}
|
|
}
|
|
number
|
|
state
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
`
|
|
const gql_variables = {
|
|
repo_owner: runInfo.data.head_repository.owner.login,
|
|
repo_name: runInfo.data.head_repository.name,
|
|
branch: runInfo.data.head_branch
|
|
}
|
|
const gql_result = await github.graphql(gql_query, gql_variables);
|
|
console.log(gql_result);
|
|
// If the branch for the PR was deleted before this job has a chance
|
|
// to run, then the ref will be null. This can happen if someone:
|
|
// 1. Rebase the PR, which triggers some workflow.
|
|
// 2. Immediately merges the PR and deletes the branch.
|
|
// 3. The workflow finishes and triggers this job.
|
|
if (!gql_result.repository.ref) {
|
|
console.log("Ref has been deleted");
|
|
return;
|
|
}
|
|
console.log(gql_result.repository.ref.associatedPullRequests.nodes);
|
|
|
|
gql_result.repository.ref.associatedPullRequests.nodes.forEach((pr) => {
|
|
|
|
// The largest PR number is the one we care about. The only way
|
|
// to have more than one associated pull requests is if all the
|
|
// old pull requests are in the closed state.
|
|
if (pr.baseRepository.owner.login = context.repo.owner && pr.number > pr_number) {
|
|
pr_number = pr.number;
|
|
}
|
|
});
|
|
}
|
|
if (pr_number == 0) {
|
|
console.log("Error retrieving pull request number");
|
|
return;
|
|
}
|
|
|
|
await comments.forEach(function (comment) {
|
|
if (comment.id) {
|
|
// Security check: Ensure that this comment was created by
|
|
// the github-actions bot, so a malicious input won't overwrite
|
|
// a user's comment.
|
|
github.rest.issues.getComment({
|
|
owner: context.repo.owner,
|
|
repo: context.repo.repo,
|
|
comment_id: comment.id
|
|
}).then((old_comment) => {
|
|
console.log(old_comment);
|
|
if (old_comment.data.user.login != "github-actions[bot]") {
|
|
console.log("Invalid comment id: " + comment.id);
|
|
return;
|
|
}
|
|
github.rest.issues.updateComment({
|
|
owner: context.repo.owner,
|
|
repo: context.repo.repo,
|
|
issue_number: pr_number,
|
|
comment_id: comment.id,
|
|
body: comment.body
|
|
});
|
|
});
|
|
} else {
|
|
github.rest.issues.createComment({
|
|
owner: context.repo.owner,
|
|
repo: context.repo.repo,
|
|
issue_number: pr_number,
|
|
body: comment.body
|
|
});
|
|
}
|
|
});
|
|
|
|
- name: Dump comments file
|
|
if: >-
|
|
always() &&
|
|
steps.download-artifact.outputs.artifact-ids != ''
|
|
run: cat comments*
|