Files
ncnn/.github/workflows/code-format-msg.yml
dependabot[bot] 078e5fed71 Bump actions/github-script from 8 to 9 (#6663)
Bumps [actions/github-script](https://github.com/actions/github-script) from 8 to 9.
- [Release notes](https://github.com/actions/github-script/releases)
- [Commits](https://github.com/actions/github-script/compare/v8...v9)

---
updated-dependencies:
- dependency-name: actions/github-script
  dependency-version: '9'
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-05-25 16:23:38 +08:00

111 lines
3.7 KiB
YAML

name: code-format-msg
on:
workflow_run:
workflows: [code-format]
types: [completed]
concurrency:
group: code-format-msg-${{ github.head_ref || github.run_id }}
permissions:
contents: read
pull-requests: write
jobs:
pr-context:
name: acquire-pr-context
runs-on: ubuntu-latest
outputs:
PR_HEADSHA: ${{ steps.set-pr-context.outputs.head-sha }}
PR_NUMBER: ${{ steps.set-pr-context.outputs.number }}
if: ${{ github.event.workflow_run.event == 'pull_request' }}
steps:
- name: get-pr-context
id: set-pr-context
env:
GH_TOKEN: ${{ github.token }}
PR_TARGET_REPO: ${{ github.repository }}
PR_BRANCH: |-
${{
(github.event.workflow_run.head_repository.owner.login != github.event.workflow_run.repository.owner.login)
&& format('{0}:{1}', github.event.workflow_run.head_repository.owner.login, github.event.workflow_run.head_branch)
|| github.event.workflow_run.head_branch
}}
run: |
gh pr view --repo "${PR_TARGET_REPO}" "${PR_BRANCH}" \
--json 'number,headRefOid' \
--jq '"number=\(.number)\nhead-sha=\(.headRefOid)"' \
>> $GITHUB_OUTPUT
remove-comment-if-success:
if: ${{ github.event.workflow_run.conclusion == 'success' }}
runs-on: ubuntu-latest
needs: [pr-context]
env:
PR_HEADSHA: ${{ needs.pr-context.outputs.PR_HEADSHA }}
PR_NUMBER: ${{ needs.pr-context.outputs.PR_NUMBER }}
steps:
- name: Remove existing "format check failed" comment
uses: actions/github-script@v9
with:
script: |
const owner = context.repo.owner;
const repo = context.repo.repo;
const { data: comments } = await github.rest.issues.listComments({
owner,
repo,
issue_number: ${{ env.PR_NUMBER }},
});
const targetComment = comments.find(comment =>
comment.body.includes("Please enable github action in **YOUR FORKED REPO** to make code-format workflow work")
);
if (targetComment) {
await github.rest.issues.deleteComment({
owner,
repo,
comment_id: targetComment.id,
});
console.log("Removed existing code-format failure comment.");
} else {
console.log("No existing format failure comment to remove.");
}
post-comment-if-failure:
if: ${{ github.event.workflow_run.conclusion == 'failure' }}
runs-on: ubuntu-latest
needs: [pr-context]
env:
PR_HEADSHA: ${{ needs.pr-context.outputs.PR_HEADSHA }}
PR_NUMBER: ${{ needs.pr-context.outputs.PR_NUMBER }}
steps:
- name: Post comment on failed code-format if not existing
uses: actions/github-script@v9
with:
script: |
const owner = context.repo.owner;
const repo = context.repo.repo;
const { data: comments } = await github.rest.issues.listComments({
owner,
repo,
issue_number: ${{ env.PR_NUMBER }},
});
const existingComment = comments.find(comment =>
comment.body.includes("Please enable github action in **YOUR FORKED REPO** to make code-format workflow work")
);
if (existingComment) {
console.log("A code-format failure comment already exists.");
} else {
await github.rest.issues.createComment({
owner,
repo,
issue_number: ${{ env.PR_NUMBER }},
body: "Please enable github action in **YOUR FORKED REPO** to make code-format workflow work",
});
console.log("Created code-format failure comment.");
}