-
Notifications
You must be signed in to change notification settings - Fork 18
/
.gitlab-ci-check-license.yml
118 lines (114 loc) · 3.94 KB
/
.gitlab-ci-check-license.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# .gitlab-ci-check-license.yml
#
# This gitlab-ci template runs license tests
#
# Add it to the project in hand through Gitlab's include functionality.
#
# include:
# - project: 'Northern.tech/Mender/mendertesting'
# file: '.gitlab-ci-check-license.yml'
#
# If the repository includes enterprise (aka, non-Open-Source) Go lang code, you
# can specify the first git commit SHA of the enterprise code, also known as
# forking commit, setting the FIRST_ENT_COMMIT env variable.
#
# You can add known license files setting the KNOWN_LICENSE_FILES env variable
# to a list of space separated files to include to the list of auto-detected
# license files.
#
# With regards to source code files, you can exclude files via regular
# expression with the variable LICENSE_HEADERS_IGNORE_FILES_REGEXP.
#
# test:check-license:
# variables:
# FIRST_ENT_COMMIT: "<sha>"
# KNOWN_LICENSE_FILES: "path/to/README.md path/to-another/LICENSE.md"
# LICENSE_HEADERS_IGNORE_FILES_REGEXP: '\./exclude-this/.*\.py'
#
stages:
- test
test:check-license:
tags:
- hetzner-amd-beefy
stage: test
needs: []
rules:
- exists:
- licenses.csv
when: never
- when: always
image: ${CI_DEPENDENCY_PROXY_DIRECT_GROUP_IMAGE_PREFIX}/alpine
variables:
GIT_STRATEGY: clone # clone entire repo instead of reusing workspace
GIT_DEPTH: 0 # avoid shallow clone, this test requires full git history
before_script:
# Install dependencies
- apk add --no-cache git bash perl-utils
# Rename the branch we're on, so that it's not in the way for the
# subsequent fetch. It's ok if this fails, it just means we're not on any
# branch.
- git branch -m temp-branch || true
# Git trick: Fetch directly into our local branches instead of remote
# branches.
- git fetch -f origin 'refs/heads/*:refs/heads/*'
# Get last remaining tags, if any.
- git fetch --tags origin
- if [ "$CI_PROJECT_NAME" = "mendertesting" ]; then
- SCRIPT_PATH=$PWD
- else
- git clone --depth=1 https://github.com/mendersoftware/mendertesting /tmp/mendertesting
- SCRIPT_PATH=/tmp/mendertesting
- fi
script:
# Check licenses
- $SCRIPT_PATH/check_license.sh
test:check-license:golang:
image: ${CI_DEPENDENCY_PROXY_DIRECT_GROUP_IMAGE_PREFIX}/golang:1.21-alpine
tags:
- hetzner-amd-beefy
stage: test
rules:
- exists:
- licenses.csv
when: always
- exists:
- LIC_FILES_CHKSUM.sha256
when: never
needs: []
before_script:
- go install github.com/google/go-licenses@latest
- apk add --no-cache git
- git clone --no-tags --depth=1 --single-branch https://github.com/mendersoftware/mendertesting /tmp/mendertesting
script:
- go-licenses report . --ignore github.com/mendersoftware --template /tmp/mendertesting/go_licenses_format.tpl > licenses.csv
- git diff --exit-code
test:check-license-source:
tags:
- hetzner-amd-beefy
stage: test
needs: []
image: ${CI_DEPENDENCY_PROXY_DIRECT_GROUP_IMAGE_PREFIX}/alpine
variables:
GIT_STRATEGY: clone # clone entire repo instead of reusing workspace
GIT_DEPTH: 0 # avoid shallow clone, this test requires full git history
before_script:
# Install dependencies
- apk add --no-cache git bash perl-utils grep
# Rename the branch we're on, so that it's not in the way for the
# subsequent fetch. It's ok if this fails, it just means we're not on any
# branch.
- git branch -m temp-branch || true
# Git trick: Fetch directly into our local branches instead of remote
# branches.
- git fetch -f origin 'refs/heads/*:refs/heads/*'
# Get last remaining tags, if any.
- git fetch --tags origin
- if [ "$CI_PROJECT_NAME" = "mendertesting" ]; then
- SCRIPT_PATH=$PWD
- else
- git clone --depth=1 https://github.com/mendersoftware/mendertesting /tmp/mendertesting
- SCRIPT_PATH=/tmp/mendertesting
- fi
script:
# Check licenses
- $SCRIPT_PATH/check_license_source_files.sh