summaryrefslogtreecommitdiffstats
path: root/.github/workflows/compliance
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--.github/workflows/compliance.yml20
-rwxr-xr-x.github/workflows/compliance/anonymize-license.pl11
-rwxr-xr-x.github/workflows/compliance/check-licenses.sh72
-rwxr-xr-x.github/workflows/compliance/ls-deps.pl24
4 files changed, 127 insertions, 0 deletions
diff --git a/.github/workflows/compliance.yml b/.github/workflows/compliance.yml
new file mode 100644
index 0000000..c094754
--- /dev/null
+++ b/.github/workflows/compliance.yml
@@ -0,0 +1,20 @@
+name: Compliance
+on:
+ push:
+ branches:
+ - master
+ pull_request: {}
+
+jobs:
+ licenses:
+ runs-on: ubuntu-latest
+ steps:
+ - run: sudo apt install -y moreutils
+
+ - uses: actions/setup-go@v2
+ with:
+ go-version: 1.18.x
+
+ - uses: actions/checkout@v2
+
+ - run: .github/workflows/compliance/check-licenses.sh
diff --git a/.github/workflows/compliance/anonymize-license.pl b/.github/workflows/compliance/anonymize-license.pl
new file mode 100755
index 0000000..573eba6
--- /dev/null
+++ b/.github/workflows/compliance/anonymize-license.pl
@@ -0,0 +1,11 @@
+#!/usr/bin/perl -pi
+
+use warnings;
+use strict;
+use autodie qw(:all);
+
+if (/^ ?(?:\w+ )?Copyright / || /^All rights reserved\.$/ || /^(?:The )?\S+ License(?: \(.+?\))?$/ || /^$/) {
+ $_ = ""
+}
+
+s/Google Inc\./the copyright holder/g
diff --git a/.github/workflows/compliance/check-licenses.sh b/.github/workflows/compliance/check-licenses.sh
new file mode 100755
index 0000000..63ff76f
--- /dev/null
+++ b/.github/workflows/compliance/check-licenses.sh
@@ -0,0 +1,72 @@
+#!/bin/bash
+
+set -eo pipefail
+
+find_license_file() {
+ MOD_NAME="$1"
+ LICENSE_DIR="vendor/$MOD_NAME"
+ LICENSE_FILES=({,../}{,UN}LICENSE{,.txt,.md})
+
+ for LICENSE_FILE in "${LICENSE_FILES[@]}"; do
+ LICENSE_FILE="${LICENSE_DIR}/$LICENSE_FILE"
+
+ if [ -e "$LICENSE_FILE" ]; then
+ echo "$LICENSE_FILE"
+ return
+ fi
+ done
+
+ echo "Module ${MOD_NAME}: license file missing in ${LICENSE_DIR}. Tried:" "${LICENSE_FILES[@]}" >&2
+ false
+}
+
+list_all_deps() {
+ for MAIN_MOD in ./cmd/*; do
+ go list -deps "$MAIN_MOD"
+ done
+}
+
+COMPATIBLE_LINE=$(($LINENO + 2))
+
+COMPATIBLE=(
+ # public domain
+ 3cee2c43614ad4572d9d594c81b9348cf45ed5ac # vendor/github.com/vbauerster/mpb/v6/UNLICENSE
+ # MIT
+ 66d504eb2f162b9cbf11b07506eeed90c6edabe1 # vendor/github.com/cespare/xxhash/v2/LICENSE.txt
+ 1513ff663e946fdcadb630bed670d253b8b22e1e # vendor/github.com/davecgh/go-spew/spew/../LICENSE
+ 90a1030e6314df9a898e5bfbdb4c6176d0a1f81c # vendor/github.com/jmoiron/sqlx/LICENSE
+ # BSD-2
+ 8762249b76928cb6995b98a95a9396c5aaf104f3 # vendor/github.com/go-redis/redis/v8/LICENSE
+ d550c89174b585d03dc67203952b38372b4ce254 # vendor/github.com/pkg/errors/LICENSE
+ # BSD-3
+ b23b967bba92ea3c5ccde9962027cd70400865eb # vendor/github.com/google/uuid/LICENSE
+ 604b38b184689a3db06a0617216d52a95aea10d8 # vendor/github.com/pmezard/go-difflib/difflib/../LICENSE
+ # MPLv2
+ 0a2b84dd9b124c4d95dd24418c3e84fd870cc0ac # vendor/github.com/go-sql-driver/mysql/LICENSE
+)
+
+MY_DIR="$(dirname "$0")"
+
+go mod vendor
+
+for MOD_NAME in $(list_all_deps | "${MY_DIR}/ls-deps.pl"); do
+ LICENSE_FILE="$(find_license_file "$MOD_NAME")"
+
+ "${MY_DIR}/anonymize-license.pl" "$LICENSE_FILE"
+ tr -d ., <"$LICENSE_FILE" | tr \\n\\t ' ' | sponge "$LICENSE_FILE"
+ perl -p0 -i -e 's/ +/ /g; s/ +$//; $_ = lc' "$LICENSE_FILE"
+
+ for SHA1 in "${COMPATIBLE[@]}"; do
+ if sha1sum -c <<<"$SHA1 $LICENSE_FILE" >/dev/null 2>&1; then
+ continue 2
+ fi
+ done
+
+ echo "Module ${MOD_NAME}: unknown license. Run 'go mod vendor' (or see below), verify by yourself whether" \
+ "$LICENSE_FILE is GPLv2 compatible and (if yes) update the license text hashes list at ${0}:$COMPATIBLE_LINE" \
+ "and eventually .github/workflows/compliance/anonymize-license.pl:7" >&2
+
+ sha1sum "$LICENSE_FILE"
+ head "$LICENSE_FILE"
+ false
+done
diff --git a/.github/workflows/compliance/ls-deps.pl b/.github/workflows/compliance/ls-deps.pl
new file mode 100755
index 0000000..a7a033a
--- /dev/null
+++ b/.github/workflows/compliance/ls-deps.pl
@@ -0,0 +1,24 @@
+#!/usr/bin/perl
+
+use warnings;
+use strict;
+use autodie qw(:all);
+
+my @mods = <>;
+chomp @mods;
+s~^vendor/~~ for @mods;
+
+@mods = grep m~^[^./]+\.~, @mods;
+@mods = grep !m~^golang\.org/x(?:/|$)~, @mods;
+@mods = grep !m~^github\.com/icinga/icingadb(?:/|$)~, @mods;
+@mods = sort @mods;
+
+my $lastMod = undef;
+
+for (@mods) {
+ # prefixed with last mod (e.g. "go.uber.org/zap/buffer" after "go.uber.org/zap"), so redundant
+ next if defined($lastMod) && /$lastMod/;
+
+ $lastMod = '^' . quotemeta("$_/");
+ print "$_\n"
+}