Skip to content

Commit e94ed48

Browse files
committed
chore(common): introduce integrity check for contract licenses
1 parent aa25e2e commit e94ed48

File tree

5 files changed

+40
-0
lines changed

5 files changed

+40
-0
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,10 @@ jobs:
7272
working-directory: gateway-contracts
7373
run: make check-mocks
7474

75+
- name: Check SPDX license headers
76+
working-directory: gateway-contracts
77+
run: make check-spdx-headers
78+
7579
- name: Check licenses compliance
7680
working-directory: gateway-contracts
7781
run: make check-licenses

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,3 +68,7 @@ jobs:
6868
- name: Check contract selectors are up-to-date
6969
working-directory: host-contracts
7070
run: make check-selectors
71+
72+
- name: Check SPDX license headers
73+
working-directory: host-contracts
74+
run: make check-spdx-headers

ci/check_spdx_licenses.sh

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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+
CONTRACTS_DIR="${1:-contracts}"
8+
EXIT_CODE=0
9+
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)
19+
20+
if [ "$EXIT_CODE" -eq 0 ]; then
21+
echo "All Solidity files use SPDX-License-Identifier: ${EXPECTED_LICENSE}"
22+
fi
23+
24+
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: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,5 +60,9 @@ 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+
check-spdx-headers:
65+
bash ../ci/check_spdx_licenses.sh contracts
66+
6367
# Conform to pre-commit checks
6468
conformance: prettier update-conformance

0 commit comments

Comments
 (0)