From a1e5395e35e08ebc9b3fd77b00687ed7e0c51d41 Mon Sep 17 00:00:00 2001 From: Zlatko Bratkovic Date: Tue, 19 Dec 2023 09:11:23 +0100 Subject: [PATCH] BUILD/MINOR: ci: add check to see if go packages have correct licenses --- .allowed_license_types | 1 + .github/workflows/actions.yml | 27 +++++++++++++++++++++++++++ .gitlab-ci.yml | 19 +++++++++++++++++++ 3 files changed, 47 insertions(+) create mode 100644 .allowed_license_types diff --git a/.allowed_license_types b/.allowed_license_types new file mode 100644 index 00000000..d8bba035 --- /dev/null +++ b/.allowed_license_types @@ -0,0 +1 @@ +MIT,BSD-2-Clause,BSD-3-Clause,Apache-2.0,ISC diff --git a/.github/workflows/actions.yml b/.github/workflows/actions.yml index 6835e431..726de059 100644 --- a/.github/workflows/actions.yml +++ b/.github/workflows/actions.yml @@ -77,6 +77,33 @@ jobs: with: file_or_dir: . config_file: .yamllint.yml + license: + name: license-check + needs: ["generate-specification","generate-models"] + runs-on: ubuntu-latest + steps: + - name: Check out code into the Go module directory + uses: actions/checkout@v3 + - name: Set up Go + uses: actions/setup-go@v3 + with: + go-version-file: 'go.mod' + - uses: actions/cache@v2 + with: + path: | + ~/.cache/go-build + ~/go/pkg/mod + key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} + restore-keys: | + ${{ runner.os }}-go- + - name: go-licenses install + run: go install github.com/google/go-licenses@latest + - name: Check Licenses + run: | + PROJECT="$(go list -m)" + ALLOWED_LICENSES="$(<.allowed_license_types)" + go-licenses report --ignore "$PROJECT" . + go-licenses check --allowed_licenses="$ALLOWED_LICENSES" --ignore "$PROJECT" . tidy: name: go mod tidy needs: ["generate-specification","generate-models"] diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 6f2feb16..59fe2780 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -92,6 +92,7 @@ tidy: lint: stage: lint + needs: ["build"] image: name: $CI_REGISTRY_GO/golang:$GO_VERSION entrypoint: [""] @@ -103,6 +104,24 @@ lint: - if: $CI_PIPELINE_SOURCE == 'merge_request_event' - if: $CI_PIPELINE_SOURCE == 'push' +license-check: + stage: lint + needs: ["build"] + image: + name: $CI_REGISTRY_GO/golang:$GO_VERSION + entrypoint: [""] + tags: + - go + script: + - go install github.com/google/go-licenses@latest + - PROJECT="$(go list -m)" + - ALLOWED_LICENSES="$(<.allowed_license_types)" + - go-licenses report --ignore "$PROJECT" . + - go-licenses check --allowed_licenses="$ALLOWED_LICENSES" --ignore "$PROJECT" . + rules: + - if: $CI_PIPELINE_SOURCE == 'merge_request_event' + - if: $CI_PIPELINE_SOURCE == 'push' + lint-commit-msg: stage: lint needs: ["build"]