From 342b640b4b91be3d0e311bb722744530777a8a44 Mon Sep 17 00:00:00 2001 From: Kefu Chai Date: Fri, 7 Feb 2025 09:59:04 +0800 Subject: [PATCH 1/2] .github: skip license check when no relevant files changed Skip the license header check step in `check-license-header.yaml` workflow when no files with configured extensions were changed in the pull request. Previously, the workflow would fail in this case since the --files argument requires at least one file path: ``` check-license.py: error: argument --files: expected at least one argument ``` Add `if` condition to only run the check when steps.changed-files.outputs.files is not empty. Signed-off-by: Kefu Chai --- .github/workflows/check-license-header.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/check-license-header.yaml b/.github/workflows/check-license-header.yaml index 6db2147e0a..7a4cd84688 100644 --- a/.github/workflows/check-license-header.yaml +++ b/.github/workflows/check-license-header.yaml @@ -28,6 +28,7 @@ jobs: echo "files=$(git diff --name-only --diff-filter=A ${{ github.event.pull_request.base.sha }} ${{ github.sha }} | tr '\n' ' ')" >> $GITHUB_OUTPUT - name: Check license headers + if: steps.changed-files.outputs.files != '' run: | .github/scripts/check-license.py \ --files ${{ steps.changed-files.outputs.files }} \ From 06b4abce56889702b16083f839bf94d46ef52281 Mon Sep 17 00:00:00 2001 From: Kefu Chai Date: Fri, 7 Feb 2025 16:05:11 +0800 Subject: [PATCH 2/2] .github: grant write permissions for PR comments in license check workflow Grant write permissions to the check-license-header workflow to enable commenting on pull requests. This fixes the "Resource not accessible by integration" HTTP error that occurred when the workflow attempted to create comments. The permission is required according to GitHub's API documentation for creating issue comments. see also https://docs.github.com/en/rest/issues/comments?apiVersion=2022-11-28#create-an-issue-comment Signed-off-by: Kefu Chai --- .github/workflows/check-license-header.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/check-license-header.yaml b/.github/workflows/check-license-header.yaml index 7a4cd84688..f05f7d1109 100644 --- a/.github/workflows/check-license-header.yaml +++ b/.github/workflows/check-license-header.yaml @@ -14,6 +14,8 @@ jobs: check-license-headers: name: Check License Headers runs-on: ubuntu-latest + permissions: + pull-requests: write steps: - name: Checkout code