-
Notifications
You must be signed in to change notification settings - Fork 26
120 lines (103 loc) · 4 KB
/
ci_license_diff.yml
File metadata and controls
120 lines (103 loc) · 4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# SPDX-FileCopyrightText: Copyright (c) 2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
name: License Diff
on:
workflow_call:
inputs:
base:
description: 'The comparison base used for the license diff'
required: false
default: ''
type: string
default_branch:
description: 'The repository default branch used as the fallback comparison base'
required: true
type: string
defaults:
run:
shell: bash
env:
UV_PYTHON_DOWNLOADS: never
jobs:
license-diff:
name: Run
runs-on: ubuntu-latest
timeout-minutes: 20
permissions:
contents: read
steps:
- name: Checkout
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
with:
fetch-depth: 0
- name: Load CI tool versions
id: ci-config
uses: ./.github/actions/load-ci-tool-versions
- uses: astral-sh/setup-uv@cec208311dfd045dd5311c1add060b2062131d57 # v8
with:
version: ${{ steps.ci-config.outputs.uv_version }}
enable-cache: true
cache-dependency-glob: ${{ github.workspace }}/uv.lock
- name: Install managed Python
run: |
set -e
UV_PYTHON_DOWNLOADS=manual uv python install --managed-python ${{ steps.ci-config.outputs.default_python_version }}
- uses: actions-rust-lang/setup-rust-toolchain@150fca883cd4034361b621bd4e6a9d34e5143606 # v1.15.4
with:
cache: false
toolchain: ${{ steps.ci-config.outputs.rust_version }}
- name: Install cargo-about
uses: taiki-e/install-action@c070f87102a1c75b3183910f391c1cb887fe13c8 # v2.77.6
with:
tool: cargo-about@${{ steps.ci-config.outputs.cargo_about_version }}
- name: Compare lockfile licenses
continue-on-error: true
env:
DEFAULT_BRANCH: ${{ inputs.default_branch }}
LICENSE_DIFF_BASE: ${{ inputs.base }}
run: |
set -euo pipefail
base_ref="${LICENSE_DIFF_BASE:-origin/${DEFAULT_BRANCH}}"
if [[ "$base_ref" =~ ^[0-9a-f]{40}$ || "$base_ref" == refs/tags/* ]]; then
compare_ref="$base_ref"
elif [[ "$base_ref" == refs/heads/* ]]; then
base_branch="${base_ref#refs/heads/}"
git fetch --no-tags origin "+refs/heads/${base_branch}:refs/remotes/origin/${base_branch}"
compare_ref="origin/${base_branch}"
else
base_branch="${base_ref#origin/}"
git fetch --no-tags origin "+refs/heads/${base_branch}:refs/remotes/origin/${base_branch}"
compare_ref="origin/${base_branch}"
fi
echo "Comparing lockfile licenses against ${compare_ref}"
set +e
uv run --no-project --python ${{ steps.ci-config.outputs.default_python_version }} python scripts/licensing/license_diff.py --base-ref "$compare_ref" > license-diff.md 2> license-diff.status
diff_status=$?
set -e
if [[ "$diff_status" -ne 0 ]]; then
echo "::warning title=License diff failed::license_diff.py exited with status ${diff_status}; see the step summary for captured output."
fi
cat license-diff.status >&2
cat license-diff.md
{
echo "## License Diff"
echo
echo "Compared against \`${compare_ref}\`."
echo
if [[ "$diff_status" -ne 0 ]]; then
echo "> License diff failed with exit code \`${diff_status}\`; this informational check does not block CI."
echo
fi
if [[ -s license-diff.md ]]; then
cat license-diff.md
else
echo "No license diff output was produced."
fi
echo
echo "<details><summary>Status output</summary>"
echo
echo '```text'
cat license-diff.status
echo '```'
echo "</details>"
} >> "$GITHUB_STEP_SUMMARY"