Skip to content
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 28 additions & 7 deletions .github/workflows/license-eyes.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,36 @@ jobs:
with:
ref: ${{ github.event.pull_request.head.sha }}

- name: Fetch base branch for diff
if: github.event_name == 'pull_request_target'
Comment thread
hello-stephen marked this conversation as resolved.
run: git fetch --no-tags --depth=1 origin ${{ github.base_ref }}

- name: Get changed files
if: github.event_name == 'pull_request_target'
id: changed-files
uses: tj-actions/changed-files@v45
with:
separator: "\n"
run: |
base_sha=$(git rev-parse FETCH_HEAD)
if ! all=$(git diff --name-only "${base_sha}..HEAD" 2>/dev/null); then
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using ${base_sha}..HEAD here compares the PR head against the current tip of the base branch, not against the PR merge base. If master advances after the branch is cut, files changed only on the base branch show up as M here and get copied into added_modified, so the incremental license check can fail on unrelated files. This needs merge-base semantics (... or equivalent), with the existing fallback to .licenserc.yaml when shallow history cannot resolve the merge base.

echo "config_file=.licenserc.yaml" >> "$GITHUB_OUTPUT"
exit 0
fi
if echo "$all" | grep -qxF '.licenserc.yaml'; then
echo "config_file=.licenserc.yaml" >> "$GITHUB_OUTPUT"
exit 0
fi
{
echo "added_modified<<EOF"
git diff --name-only --diff-filter=ACMR "${base_sha}..HEAD"
echo "EOF"
} >> "$GITHUB_OUTPUT"
echo "config_file=.licenserc-incremental.yaml" >> "$GITHUB_OUTPUT"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

config_file is set to .licenserc-incremental.yaml unconditionally here, even when git diff --diff-filter=ACMR returned no files. In a delete-only PR, Generate incremental licenserc is skipped, the incremental file is never created, and Check License still tries to read it. Please only set the incremental config when added_modified is non-empty, or skip the license step entirely for delete-only PRs.


- name: Generate incremental licenserc
if: github.event_name == 'pull_request_target' && steps.changed-files.outputs.all_changed_files != ''
if: >-
github.event_name == 'pull_request_target' &&
steps.changed-files.outputs.added_modified != ''
env:
CHANGED_FILES: ${{ steps.changed-files.outputs.all_changed_files }}
CHANGED_FILES: ${{ steps.changed-files.outputs.added_modified }}
run: |
python3 - <<'EOF'
import yaml, os
Expand All @@ -76,9 +95,11 @@ jobs:
EOF

- name: Check License
if: github.event_name != 'pull_request_target' || steps.changed-files.outputs.all_changed_files != ''
if: >-
github.event_name != 'pull_request_target' ||
steps.changed-files.outputs.config_file != ''
uses: apache/skywalking-eyes@v0.8.0
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
config: ${{ github.event_name == 'pull_request_target' && '.licenserc-incremental.yaml' || '.licenserc.yaml' }}
config: ${{ steps.changed-files.outputs.config_file || '.licenserc.yaml' }}
Loading