From 5f322385bd77e12ecd7fd3a90ff7c18ccf82417b Mon Sep 17 00:00:00 2001 From: MetaMiku Date: Mon, 2 Nov 2026 02:22:31 +0800 Subject: [PATCH 1/2] =?UTF-8?q?ci:=20=E5=A2=9E=E5=8A=A0=E8=B5=84=E6=BA=90?= =?UTF-8?q?=E5=8C=85=E6=A3=80=E6=9F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 推送和 PR 时用编辑器的 scripts/checkResourcePack.ts 检查资源包,有错误时失败,警告只提示。 --- .github/workflows/check-resource.yml | 40 ++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 .github/workflows/check-resource.yml diff --git a/.github/workflows/check-resource.yml b/.github/workflows/check-resource.yml new file mode 100644 index 0000000..aad9951 --- /dev/null +++ b/.github/workflows/check-resource.yml @@ -0,0 +1,40 @@ +name: Check Resource Pack + +on: + push: + branches: ["**"] + pull_request: + workflow_dispatch: + +permissions: + contents: read + +concurrency: + group: check-${{ github.event.pull_request.number || github.ref }} + cancel-in-progress: true + +jobs: + check: + name: 资源包检查 + runs-on: ubuntu-latest + timeout-minutes: 10 + + steps: + - name: Checkout + uses: actions/checkout@v7 + with: + persist-credentials: false + + - name: Checkout editor + uses: actions/checkout@v7 + with: + repository: MetaMystia/MetaMystia-ResourceEx-Editor + path: .editor + persist-credentials: false + + - uses: actions/setup-node@v7 + with: + node-version: 24 + + - name: Check + run: node .editor/scripts/checkResourcePack.ts . From a6cbc46cb08322685442fc6d051fc51c122b1486 Mon Sep 17 00:00:00 2001 From: MetaMiku Date: Mon, 2 Nov 2026 02:38:16 +0800 Subject: [PATCH 2/2] =?UTF-8?q?ci:=20=E5=9C=A8=20PR=20=E4=B8=AD=E8=AF=84?= =?UTF-8?q?=E8=AE=BA=E8=B5=84=E6=BA=90=E5=8C=85=E6=A3=80=E6=9F=A5=E7=BB=93?= =?UTF-8?q?=E6=9E=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 检查上传报告,comment-check-resource.yml 在检查结束后发布或更新 PR 评论;fork 的 PR 也适用。 --- .github/workflows/check-resource.yml | 20 ++++++- .github/workflows/comment-check-resource.yml | 59 ++++++++++++++++++++ 2 files changed, 78 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/comment-check-resource.yml diff --git a/.github/workflows/check-resource.yml b/.github/workflows/check-resource.yml index aad9951..a741639 100644 --- a/.github/workflows/check-resource.yml +++ b/.github/workflows/check-resource.yml @@ -37,4 +37,22 @@ jobs: node-version: 24 - name: Check - run: node .editor/scripts/checkResourcePack.ts . + run: | + mkdir -p check-report + node .editor/scripts/checkResourcePack.ts . --report check-report/report.md + + # 供 comment-check-resource.yml 在 PR 中发布结果。 + - name: Save PR number + if: ${{ !cancelled() && github.event_name == 'pull_request' }} + env: + PR_NUMBER: ${{ github.event.pull_request.number }} + run: echo "$PR_NUMBER" > check-report/pr-number + + - name: Upload report + if: ${{ !cancelled() && github.event_name == 'pull_request' }} + uses: actions/upload-artifact@v7 + with: + name: resource-pack-check + path: check-report/ + if-no-files-found: ignore + retention-days: 7 diff --git a/.github/workflows/comment-check-resource.yml b/.github/workflows/comment-check-resource.yml new file mode 100644 index 0000000..c55208e --- /dev/null +++ b/.github/workflows/comment-check-resource.yml @@ -0,0 +1,59 @@ +name: Comment Resource Pack Check + +# 来自 fork 的 PR 拿不到写权限,检查结束后在这里发布结果。 +# 本 workflow 不检出、不运行 PR 中的代码,只读取检查上传的报告。 +on: + workflow_run: + workflows: [Check Resource Pack] + types: [completed] + +permissions: + actions: read + pull-requests: write + +jobs: + comment: + name: 发布检查结果 + if: >- + github.event.workflow_run.event == 'pull_request' && + (github.event.workflow_run.conclusion == 'success' || + github.event.workflow_run.conclusion == 'failure') + runs-on: ubuntu-latest + timeout-minutes: 5 + + steps: + - name: Comment + env: + GH_TOKEN: ${{ github.token }} + HEAD_SHA: ${{ github.event.workflow_run.head_sha }} + RUN_ID: ${{ github.event.workflow_run.id }} + RUN_URL: ${{ github.event.workflow_run.html_url }} + run: | + set -euo pipefail + if ! gh run download "$RUN_ID" --repo "$GITHUB_REPOSITORY" --name resource-pack-check --dir report \ + || [ ! -f report/report.md ] || [ ! -f report/pr-number ]; then + echo "没有检查报告,跳过。" + exit 0 + fi + + # 报告由 PR 中的 workflow 生成,只在头提交一致的 PR 下评论。 + pr=$(cat report/pr-number) + if [[ ! "$pr" =~ ^[0-9]+$ ]]; then + echo "PR 编号无效。" + exit 1 + fi + if [ "$(gh pr view "$pr" --repo "$GITHUB_REPOSITORY" --json headRefOid --jq .headRefOid)" != "$HEAD_SHA" ]; then + echo "PR 已有新提交,跳过。" + exit 0 + fi + + marker='' + { echo "$marker"; cat report/report.md; echo; echo "[运行详情]($RUN_URL)"; } > body.md + id=$(gh api --paginate "repos/$GITHUB_REPOSITORY/issues/$pr/comments" \ + --jq ".[] | select(.user.login == \"github-actions[bot]\" and (.body | startswith(\"$marker\"))) | .id" \ + | sed -n 1p) + if [ -n "$id" ]; then + gh api -X PATCH "repos/$GITHUB_REPOSITORY/issues/comments/$id" -F body=@body.md > /dev/null + else + gh api "repos/$GITHUB_REPOSITORY/issues/$pr/comments" -F body=@body.md > /dev/null + fi