Skip to content

Commit fae55f3

Browse files
committed
ci(common): include library solidity and host library in the spdx license check
1 parent edf6bc2 commit fae55f3

File tree

6 files changed

+104
-11
lines changed

6 files changed

+104
-11
lines changed

.github/workflows/gateway-contracts-integrity-checks.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ jobs:
3232
gw-contracts:
3333
- .github/workflows/gateway-contracts-integrity-checks.yml
3434
- gateway-contracts/**
35+
- ci/check_spdx_licenses.sh
36+
- ci/contracts_bindings_update.py
3537
contract-integrity-checks:
3638
name: gateway-contracts-integrity-checks/contract-integrity-checks (bpr)
3739
needs: check-changes

.github/workflows/host-contracts-integrity-checks.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ jobs:
3232
host-contracts:
3333
- .github/workflows/host-contracts-integrity-checks.yml
3434
- host-contracts/**
35+
- ci/check_spdx_licenses.sh
36+
- ci/contracts_bindings_update.py
3537
3638
contract-integrity-checks:
3739
name: host-contracts-integrity-checks/contract-integrity-checks (bpr)
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# This workflow verifies that:
2+
# - Dependency licenses compliance
3+
name: library-solidity-integrity-checks
4+
5+
on:
6+
pull_request:
7+
8+
permissions: {}
9+
10+
concurrency:
11+
group: library-solidity-integrity-checks-${{ github.ref }}
12+
cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}
13+
14+
jobs:
15+
check-changes:
16+
name: library-solidity-integrity-checks/check-changes
17+
permissions:
18+
contents: 'read' # Required to checkout repository code
19+
runs-on: ubuntu-latest
20+
outputs:
21+
changes-library-solidity: ${{ steps.filter.outputs.library-solidity }}
22+
steps:
23+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
24+
with:
25+
persist-credentials: 'false'
26+
- uses: dorny/paths-filter@de90cc6fb38fc0963ad72b210f1f284cd68cea36 # v3.0.2
27+
id: filter
28+
with:
29+
filters: |
30+
library-solidity:
31+
- .github/workflows/library-solidity-integrity-checks.yml
32+
- library-solidity/**
33+
- ci/check_spdx_licenses.sh
34+
35+
contract-integrity-checks:
36+
name: library-solidity-integrity-checks/contract-integrity-checks (bpr)
37+
needs: check-changes
38+
if: ${{ needs.check-changes.outputs.changes-library-solidity == 'true' }}
39+
permissions:
40+
contents: 'read' # Required to checkout repository code
41+
runs-on: ubuntu-latest
42+
steps:
43+
- name: Checkout project
44+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
45+
with:
46+
persist-credentials: 'false'
47+
48+
- name: Check SPDX license headers
49+
working-directory: library-solidity
50+
run: make check-spdx-headers

ci/check_spdx_licenses.sh

Lines changed: 44 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,52 @@
44
set -euo pipefail
55

66
EXPECTED_LICENSE="BSD-3-Clause-Clear"
7-
CONTRACTS_DIR="${1:-contracts}"
87
EXIT_CODE=0
8+
DIRS=()
9+
EXCLUDES=()
910

10-
while IFS= read -r -d '' file; do
11-
first_line=$(head -n 1 "$file")
12-
if [[ "$first_line" != "// SPDX-License-Identifier: ${EXPECTED_LICENSE}" ]]; then
13-
echo "ERROR: Wrong or missing license in $file"
14-
echo " Found: $first_line"
15-
echo " Expected: // SPDX-License-Identifier: ${EXPECTED_LICENSE}"
16-
EXIT_CODE=1
17-
fi
18-
done < <(find "$CONTRACTS_DIR" -name '*.sol' -print0 | sort -z)
11+
# Parse arguments
12+
while [[ $# -gt 0 ]]; do
13+
case "$1" in
14+
--exclude)
15+
EXCLUDES+=("$2")
16+
shift 2
17+
;;
18+
*)
19+
DIRS+=("$1")
20+
shift
21+
;;
22+
esac
23+
done
24+
25+
# Default to contracts/ if no directories specified
26+
if [[ ${#DIRS[@]} -eq 0 ]]; then
27+
DIRS=("contracts")
28+
fi
29+
30+
for dir in "${DIRS[@]}"; do
31+
while IFS= read -r -d '' file; do
32+
# Check if file matches any exclude pattern
33+
skip=false
34+
for exclude in ${EXCLUDES[@]+"${EXCLUDES[@]}"}; do
35+
if [[ "$file" == *"$exclude"* ]]; then
36+
skip=true
37+
break
38+
fi
39+
done
40+
if "$skip"; then
41+
continue
42+
fi
43+
44+
first_line=$(head -n 1 "$file")
45+
if [[ "$first_line" != "// SPDX-License-Identifier: ${EXPECTED_LICENSE}" ]]; then
46+
echo "ERROR: Wrong or missing license in $file"
47+
echo " Found: $first_line"
48+
echo " Expected: // SPDX-License-Identifier: ${EXPECTED_LICENSE}"
49+
EXIT_CODE=1
50+
fi
51+
done < <(find "$dir" -name '*.sol' -print0 | sort -z)
52+
done
1953

2054
if [ "$EXIT_CODE" -eq 0 ]; then
2155
echo "All Solidity files use SPDX-License-Identifier: ${EXPECTED_LICENSE}"

host-contracts/Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,9 @@ lint-bindings:
6161
update-conformance: update-bindings update-selectors
6262

6363
# Make sure all Solidity contracts use the expected SPDX license identifier (BSD-3-Clause-Clear)
64+
# We also check lib/ but exclude external dependencies (forge-std, OpenZeppelin-derived FhevmECDSA).
6465
check-spdx-headers:
65-
bash ../ci/check_spdx_licenses.sh contracts
66+
bash ../ci/check_spdx_licenses.sh contracts lib --exclude forge-std --exclude cryptography/FhevmECDSA.sol
6667

6768
# Conform to pre-commit checks
6869
conformance: prettier update-conformance

library-solidity/Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Make sure all Solidity source files use the expected SPDX license identifier (BSD-3-Clause-Clear).
2+
# We check lib/ and config/ but exclude external dependencies (OpenZeppelin-derived FhevmECDSA).
3+
check-spdx-headers:
4+
bash ../ci/check_spdx_licenses.sh lib config --exclude cryptography/FhevmECDSA.sol

0 commit comments

Comments
 (0)