-
Notifications
You must be signed in to change notification settings - Fork 4
/
action.yml
250 lines (247 loc) · 12.7 KB
/
action.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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
name: 'Get SPDX license overview'
description: 'Get SPDX license overview'
author: "Forest Keepers"
branding:
icon: "activity"
color: "green"
outputs:
spdx-file:
description: "spdx-license file"
value: ${{ steps.spdx-ort.outputs.spdx-file }} ${{ steps.spdx-tree.outputs.spdx-file }} ${{ steps.spdx-blackduck.outputs.spdx-file }}
ort-file:
description: "ort-license file"
value: ${{ steps.spdx.outputs.ort-file }}
inputs:
project:
description: "project"
required: true
default: 'spdx-builder'
spdx-builder-version:
description: "spdx-builder-version"
required: true
default: 'v0.9.2'
mode:
description: "Scan mode. Can be 'ort', 'blackduck' or 'tree'"
required: true
default: 'ort'
scanner-url:
description: "scanner-url (license-scanner)"
required: false
bombase-url:
description: "bombase-url (in case of mode: 'tree')"
required: false
upload-url:
description: "upload-url (f.e. BOM-bar)"
required: false
# ORT specific inputs
ort-version:
description: "philipssoftware/ort version (in case of mode: 'ort')"
required: false
default: '2021-11-24'
ort-file:
description: "Specifies an ort-file to override ORT scanning in this action. (in case of mode: 'ort')"
required: false
# tree specific inputs
tree:
description: "file with tree input (in case of mode: 'tree')"
required: false
format:
description: "format input (in case of mode: 'tree')"
required: false
# blackduck specific inputs
blackduck-url:
description: "Blackduck url (in case of mode: 'blackduck')"
required: false
blackduck-token:
description: "Blackduck token (in case of mode: 'blackduck')"
required: false
blackduck-project:
description: "Blackduck project (in case of mode: 'blackduck')"
required: false
blackduck-version:
description: "Blackduck version (in case of mode: 'blackduck')"
required: false
optional-arguments:
description: "Optional arguments like `--tree`, `--release`, `--force` and `--custom`"
required: false
capture-stdout-file:
description: "Capture stdout in a file. When given, this will be used as the filename of the output"
required: false
runs:
using: "composite"
steps:
- name: Scan with ORT
run: |
[ "${MODE}" != 'ort' ] && { echo "mode is not 'ort' so don't perform this step"; exit 0; }
[ -n "${ORT_FILE}" ] && { echo "We have our own ORT_FILE so we don't need to scan it here"; exit 0; }
# Allow ORT to fail. When one repository can't be found, the rest still makes sense to analyse
echo "--------------------------------------------------------------------"
echo " Running ORT scanner"
echo "--------------------------------------------------------------------"
set +e
docker run -v ${{ github.workspace }}:/project philipssoftware/ort:${{ inputs.ort-version}} --info analyze -f JSON -i /project -o /project/ort
set -e
shell: bash
env:
ORT_FILE: ${{ inputs.ort-file }}
MODE: ${{ inputs.mode }}
OPTIONAL_ARGUMENTS: ${{ inputs.optional-arguments }}
- name: Create SPDX file with ORT
id: spdx-ort
run: |
[ "${MODE}" != 'ort' ] && { echo "mode is not 'ort' so don't perform this step"; exit 0; }
echo "--------------------------------------------------------------------"
echo " Creating SPDX file for ${PROJECT}. "
echo "--------------------------------------------------------------------"
echo " Inputs: "
echo " PROJECT : ${PROJECT} "
echo " SCANNER_URL : ${SCANNER_URL} "
echo " UPLOAD_URL : ${UPLOAD_URL} "
echo " ORT_FILE : ${ORT_FILE} "
echo " OPTIONAL_ARGUMENTS : ${OPTIONAL_ARGUMENTS} "
echo "--------------------------------------------------------------------"
echo ""
echo "--------------------------------------------------------------------"
echo " Downloading spdx-builder"
echo "--------------------------------------------------------------------"
curl -L https://github.com/philips-software/spdx-builder/releases/download/${{ inputs.spdx-builder-version }}/spdx-builder.jar -o spdx-builder.jar
echo "--------------------------------------------------------------------"
echo " Set SCANNER_ARG"
echo "--------------------------------------------------------------------"
[ -z "$SCANNER_URL" ] && SCANNER_ARG="" || SCANNER_ARG="--scanner ${SCANNER_URL}"
echo " SCANNER_ARG: ${SCANNER_ARG}"
echo "--------------------------------------------------------------------"
echo " Set input-file"
echo "--------------------------------------------------------------------"
[ -n "$ORT_FILE" ] && INPUT_FILE=${ORT_FILE} || INPUT_FILE="ort/analyzer-result.json"
echo " INPUT_FILE: ${INPUT_FILE}"
echo "--------------------------------------------------------------------"
echo " Set UPLOAD_ARG"
echo "--------------------------------------------------------------------"
[ -z "$UPLOAD_URL" ] && UPLOAD_ARG="" || UPLOAD_ARG="--upload ${UPLOAD_URL}"
echo " UPLOAD_ARG: ${UPLOAD_ARG}"
echo "--------------------------------------------------------------------"
echo " Set OPTIONAL_ARG"
echo "--------------------------------------------------------------------"
[ -z "$OPTIONAL_ARGUMENTS" ] && OPTIONAL_ARG="" || OPTIONAL_ARG="${OPTIONAL_ARGUMENTS}"
echo " OPTIONAL_ARG: ${OPTIONAL_ARG}"
echo "--------------------------------------------------------------------"
echo " Running SPDX-builder"
echo "--------------------------------------------------------------------"
java -jar spdx-builder.jar ort -c .spdx-builder.yml -o ${PROJECT}.spdx ${INPUT_FILE} ${SCANNER_ARG} ${UPLOAD_ARG} ${OPTIONAL_ARG}
echo "--------------------------------------------------------------------"
echo "Finished!"
echo "--------------------------------------------------------------------"
echo "::set-output name=spdx-file::${PROJECT}.spdx"
echo "::set-output name=ort-file::${INPUT_FILE}"
env:
PROJECT: ${{ inputs.project }}
SCANNER_URL: ${{ inputs.scanner-url }}
ORT_FILE: ${{ inputs.ort-file }}
UPLOAD_URL: ${{ inputs.upload-url }}
MODE: ${{ inputs.mode }}
OPTIONAL_ARGUMENTS: ${{ inputs.optional-arguments }}
shell: bash
- name: Create SPDX file with tree
id: spdx-tree
run: |
[ "${MODE}" != 'tree' ] && { echo "mode is not 'tree' so don't perform this step"; exit 0; }
echo "--------------------------------------------------------------------"
echo " Creating SPDX file for ${PROJECT} based on tree import."
echo "--------------------------------------------------------------------"
echo " Inputs: "
echo " PROJECT : ${PROJECT} "
echo " BOMBASE_URL : ${BOMBASE_URL} "
echo " UPLOAD_URL : ${UPLOAD_URL} "
echo " TREE : ${TREE} "
echo " FORMAT : ${FORMAT} "
echo " OPTIONAL_ARGUMENTS : ${OPTIONAL_ARGUMENTS} "
echo "--------------------------------------------------------------------"
echo ""
echo "--------------------------------------------------------------------"
echo " Downloading spdx-builder"
echo "--------------------------------------------------------------------"
curl -L https://github.com/philips-software/spdx-builder/releases/download/${{ inputs.spdx-builder-version }}/spdx-builder.jar -o spdx-builder.jar
echo "--------------------------------------------------------------------"
echo " Set BOMBASE_ARG"
echo "--------------------------------------------------------------------"
[ -z "$BOMBASE_URL" ] && BOMBASE_ARG="" || BOMBASE_ARG="--bombase ${BOMBASE_URL}"
echo " BOMBASE_ARG: ${BOMBASE_ARG}"
echo "--------------------------------------------------------------------"
echo " Set UPLOAD_ARG"
echo "--------------------------------------------------------------------"
[ -z "$UPLOAD_URL" ] && UPLOAD_ARG="" || UPLOAD_ARG="--upload ${UPLOAD_URL}"
echo " UPLOAD_ARG: ${UPLOAD_ARG}"
echo "--------------------------------------------------------------------"
echo " Set OPTIONAL_ARG"
echo "--------------------------------------------------------------------"
[ -z "$OPTIONAL_ARGUMENTS" ] && OPTIONAL_ARG="" || OPTIONAL_ARG="${OPTIONAL_ARGUMENTS}"
echo " OPTIONAL_ARG: ${OPTIONAL_ARG}"
echo "--------------------------------------------------------------------"
echo " Running SPDX-builder"
echo "--------------------------------------------------------------------"
cat "${TREE}" | java -jar spdx-builder.jar tree -f ${FORMAT} -c .spdx-builder.yml -o ${PROJECT}.spdx ${BOMBASE_ARG} ${UPLOAD_ARG} ${OPTIONAL_ARG}
echo "--------------------------------------------------------------------"
echo "Finished!"
echo "--------------------------------------------------------------------"
echo "::set-output name=spdx-file::${PROJECT}.spdx"
env:
PROJECT: ${{ inputs.project }}
BOMBASE_URL: ${{ inputs.bombase-url }}
TREE: ${{ inputs.tree }}
FORMAT: ${{ inputs.format }}
UPLOAD_URL: ${{ inputs.upload-url }}
MODE: ${{ inputs.mode }}
OPTIONAL_ARGUMENTS: ${{ inputs.optional-arguments }}
shell: bash
- name: Create SPDX file with blackduck
id: spdx-blackduck
run: |
[ "${MODE}" != 'blackduck' ] && { echo "mode is not 'blackduck' so don't perform this step"; exit 0; }
echo "--------------------------------------------------------------------"
echo " Creating SPDX file for ${PROJECT} based on blackduck import."
echo "--------------------------------------------------------------------"
echo " Inputs: "
echo " PROJECT : ${PROJECT} "
echo " BLACKDUCK_PROJECT : ${BLACKUCK_PROJECT} "
echo " BLACKDUCK_VERSION : ${BLACKUCK_VERSION} "
echo " BLACKDUCK_URL : ${BLACKUCK_URL} "
echo " BLACKDUCK_TOKEN : ${BLACKUCK_TOKEN} "
echo " OPTIONAL_ARGUMENTS : ${OPTIONAL_ARGUMENTS} "
echo " CAPTURE_STDOUT_FILE : ${CAPTURE_STDOUT_FILE} "
echo "--------------------------------------------------------------------"
echo ""
echo "--------------------------------------------------------------------"
echo " Downloading spdx-builder"
echo "--------------------------------------------------------------------"
curl -L https://github.com/philips-software/spdx-builder/releases/download/${{ inputs.spdx-builder-version }}/spdx-builder.jar -o spdx-builder.jar
echo "--------------------------------------------------------------------"
echo " Set OPTIONAL_ARG"
echo "--------------------------------------------------------------------"
[ -z "$OPTIONAL_ARGUMENTS" ] && OPTIONAL_ARG="" || OPTIONAL_ARG="${OPTIONAL_ARGUMENTS}"
echo " OPTIONAL_ARG: ${OPTIONAL_ARG}"
echo "--------------------------------------------------------------------"
echo " Running SPDX-builder"
echo "--------------------------------------------------------------------"
set -x
if [ -z ${CAPTURE_STDOUT_FILE} ]; then
echo "no capture"
java -jar spdx-builder.jar blackduck -o ${PROJECT}.spdx --url ${BLACKDUCK_URL} --token ${BLACKDUCK_TOKEN} ${BLACKDUCK_PROJECT} ${BLACKDUCK_VERSION} ${OPTIONAL_ARG}
else
echo "with capture"
java -jar spdx-builder.jar blackduck -o ${PROJECT}.spdx --url ${BLACKDUCK_URL} --token ${BLACKDUCK_TOKEN} ${BLACKDUCK_PROJECT} ${BLACKDUCK_VERSION} ${OPTIONAL_ARG} > ${CAPTURE_STDOUT_FILE} 2>&1
fi
echo "--------------------------------------------------------------------"
echo "Finished!"
echo "--------------------------------------------------------------------"
echo "::set-output name=spdx-file::${PROJECT}.spdx"
env:
PROJECT: ${{ inputs.project }}
MODE: ${{ inputs.mode }}
BLACKDUCK_PROJECT: ${{ inputs.blackduck-project }}
BLACKDUCK_VERSION: ${{ inputs.blackduck-version }}
BLACKDUCK_URL: ${{ inputs.blackduck-url }}
BLACKDUCK_TOKEN: ${{ inputs.blackduck-token }}
OPTIONAL_ARGUMENTS: ${{ inputs.optional-arguments }}
CAPTURE_STDOUT_FILE: ${{ inputs.capture-stdout-file }}
shell: bash