Skip to content

Commit b7bb514

Browse files
authored
Merge of #2154
2 parents 3c5136f + fae55f3 commit b7bb514

File tree

7 files changed

+133
-0
lines changed

7 files changed

+133
-0
lines changed

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

Lines changed: 6 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
@@ -72,6 +74,10 @@ jobs:
7274
working-directory: gateway-contracts
7375
run: make check-mocks
7476

77+
- name: Check SPDX license headers
78+
working-directory: gateway-contracts
79+
run: make check-spdx-headers
80+
7581
- name: Check licenses compliance
7682
working-directory: gateway-contracts
7783
run: make check-licenses

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

Lines changed: 6 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)
@@ -68,3 +70,7 @@ jobs:
6870
- name: Check contract selectors are up-to-date
6971
working-directory: host-contracts
7072
run: make check-selectors
73+
74+
- name: Check SPDX license headers
75+
working-directory: host-contracts
76+
run: make check-spdx-headers
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: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
#!/usr/bin/env bash
2+
# Check that all Solidity contracts use the expected SPDX license identifier.
3+
4+
set -euo pipefail
5+
6+
EXPECTED_LICENSE="BSD-3-Clause-Clear"
7+
EXIT_CODE=0
8+
DIRS=()
9+
EXCLUDES=()
10+
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
53+
54+
if [ "$EXIT_CODE" -eq 0 ]; then
55+
echo "All Solidity files use SPDX-License-Identifier: ${EXPECTED_LICENSE}"
56+
fi
57+
58+
exit "$EXIT_CODE"

gateway-contracts/Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,10 @@ deploy-setup-contracts:
106106
ensure-addresses:
107107
ENV_PATH=$(ENV_PATH) npx ts-node scripts/ensure_proxy_addresses.ts
108108

109+
# Make sure all Solidity contracts use the expected SPDX license identifier (BSD-3-Clause-Clear)
110+
check-spdx-headers:
111+
bash ../ci/check_spdx_licenses.sh contracts
112+
109113
# Make sure we only use allowed licenses for dependencies
110114
# Full list of SPDX identifiers can be found here: https://spdx.org/licenses/
111115
# The following packages are exceptionally excluded from the check:

host-contracts/Makefile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,5 +60,10 @@ lint-bindings:
6060
# Update auto-generated files for conformance checks
6161
update-conformance: update-bindings update-selectors
6262

63+
# 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).
65+
check-spdx-headers:
66+
bash ../ci/check_spdx_licenses.sh contracts lib --exclude forge-std --exclude cryptography/FhevmECDSA.sol
67+
6368
# Conform to pre-commit checks
6469
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)