-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds check for oss license in source files (#4)
- Loading branch information
1 parent
563965b
commit 3ef3afb
Showing
3 changed files
with
82 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
name: "Lint documentation and find typos" | ||
description: "Standardize documentation and prose with different linters" | ||
|
||
inputs: | ||
file-patterns: | ||
description: “Patterns to look in source files, comma separated” | ||
required: true | ||
|
||
license: | ||
description: “Open-source license to enforce” | ||
default: "mit" | ||
required: true | ||
|
||
runs: | ||
using: "composite" | ||
steps: | ||
- name: Check licenses on source files | ||
shell: bash | ||
run: ./src/license-enforcer.sh $GITHUB_WORKSPACE ${{ inputs.file-patterns }} ${{ inputs.license }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
#!/usr/bin/env bash | ||
# Copyright 2023 Dotanuki Labs | ||
# SPDX-License-Identifier: MIT | ||
|
||
# shellcheck disable=SC2046 | ||
|
||
set -eo pipefail | ||
|
||
# https://github.com/google/addlicense | ||
readonly image="ghcr.io/google/addlicense" | ||
|
||
readonly target_folder="$1" | ||
readonly sources="$2" | ||
readonly license="$3" | ||
|
||
require_docker() { | ||
if (! docker stats --no-stream >/dev/null); then | ||
echo "Docker is required for this check" | ||
echo | ||
exit 1 | ||
fi | ||
} | ||
|
||
check_license_on_files() { | ||
local extension="$1" | ||
|
||
echo "→ Checking licenses for $files files" | ||
|
||
docker run --rm -v "${target_folder}:/src" "$image" \ | ||
-c "Dotanuki Labs" \ | ||
-l "$license" \ | ||
-check $(find . -type f -name "$extension") | ||
} | ||
|
||
report_missing_licenses() { | ||
echo | ||
echo "There are files with missing ($license) license" | ||
echo | ||
exit 1 | ||
} | ||
|
||
enforce_license_for_file_patterns() { | ||
IFS=" " read -r -a files <<<"$(echo "$sources" | sed "s/,/[:space:]/g" | xargs)" | ||
|
||
for type in "${files[@]}"; do | ||
check_license_on_files "$type" || report_missing_licenses | ||
done | ||
} | ||
|
||
echo | ||
echo "🔥 Enforcing open-source license on source files" | ||
echo | ||
|
||
require_docker | ||
enforce_license_for_file_patterns | ||
|
||
echo | ||
echo "✅ All good!" | ||
echo |