-
-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathaction.yml
More file actions
251 lines (228 loc) · 8.88 KB
/
Copy pathaction.yml
File metadata and controls
251 lines (228 loc) · 8.88 KB
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
251
name: "ScanCode action"
description: "Run ScanCode.io pipelines in your workflows"
inputs:
pipelines:
description: "Names of the pipelines (comma-separated) and in order."
default: "scan_codebase"
output-formats:
description: "Output formats"
default: "json xlsx spdx cyclonedx"
inputs-path:
description: "Relative path within the $GITHUB_WORKSPACE for pipeline inputs"
default: "scancode-inputs"
input-urls:
description: "Provide one or more URLs to download for the pipeline run execution."
required: false
default: ""
project-name:
description: "Name of the project."
default: "scancode-action"
outputs-archive-name:
description: "Name of the outputs archive."
default: "scancode-outputs"
check-compliance:
description: |
Check for compliance issues in the project.
Exits with a non-zero status if compliance issues are detected.
required: false
default: "false"
compliance-fail-level:
description: "Failure level for compliance check. Options: ERROR, WARNING, MISSING."
required: false
default: "ERROR"
compliance-fail-on-vulnerabilities:
description: |
Exit with a non-zero status if known vulnerabilities are detected in discovered
packages and dependencies.
required: false
default: "false"
python-version:
description: "Python version."
default: "3.13"
scancodeio-repo-branch:
description: "Branch to install ScanCode.io from the GitHub repository (optional)"
required: false
default: ""
scancodeio-extras:
description: "ScanCode.io optional dependencies (comma-separated) (optional)."
required: false
default: ""
runs:
using: "composite"
steps:
- name: Set up Python
uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0
with:
python-version: ${{ inputs.python-version }}
- name: Set up environment
shell: bash
env:
INPUT_PROJECT_NAME: ${{ inputs.project-name }}
run: |
echo "SECRET_KEY=$(openssl rand -base64 32)" >> "$GITHUB_ENV"
echo "SCANCODEIO_DB_NAME=scancodeio" >> "$GITHUB_ENV"
echo "SCANCODEIO_DB_USER=scancodeio" >> "$GITHUB_ENV"
echo "SCANCODEIO_DB_PASSWORD=scancodeio" >> "$GITHUB_ENV"
# Sanitize project name for artifact usage
SAFE_PROJECT_NAME="${INPUT_PROJECT_NAME//[^a-zA-Z0-9._-]/_}"
echo "SAFE_PROJECT_NAME=$SAFE_PROJECT_NAME" >> "$GITHUB_ENV"
- name: Detect if ScanCode.io is already installed
shell: bash
run: |
if command -v scanpipe &> /dev/null; then
echo "ScanCode.io already installed."
echo "SCANCODEIO_IS_INSTALLED=true" >> "$GITHUB_ENV"
else
echo "ScanCode.io not found."
echo "SCANCODEIO_IS_INSTALLED=false" >> "$GITHUB_ENV"
fi
- name: Start and setup the PostgreSQL service
if: env.SCANCODEIO_IS_INSTALLED != 'true'
shell: bash
run: |
sudo systemctl start postgresql.service
sudo -u postgres createuser --no-createrole --no-superuser --login --inherit --createdb "$SCANCODEIO_DB_USER"
sudo -u postgres psql -c "ALTER USER $SCANCODEIO_DB_USER WITH ENCRYPTED PASSWORD '$SCANCODEIO_DB_PASSWORD'"
sudo -u postgres createdb --owner=scancodeio --encoding=UTF-8 "$SCANCODEIO_DB_NAME"
- name: Generate scancodeio pip install argument
if: env.SCANCODEIO_IS_INSTALLED != 'true'
shell: bash
env:
INPUT_EXTRAS: ${{ inputs.scancodeio-extras }}
run: |
SCANCODEIO_PIP_PACKAGE_ARG="scancodeio"
TRIMMED_EXTRAS="$(echo "$INPUT_EXTRAS" | tr -d '[:space:]')"
if [ -n "$TRIMMED_EXTRAS" ]; then
SCANCODEIO_PIP_PACKAGE_ARG+="[$TRIMMED_EXTRAS]"
fi
echo "SCANCODEIO_PIP_PACKAGE_ARG=${SCANCODEIO_PIP_PACKAGE_ARG}" >> "$GITHUB_ENV"
- name: Install ScanCode.io (only if not already installed)
if: env.SCANCODEIO_IS_INSTALLED != 'true'
shell: bash
env:
INPUT_REPO_BRANCH: ${{ inputs.scancodeio-repo-branch }}
run: |
if [ -z "$INPUT_REPO_BRANCH" ]; then
echo "Installing the latest ${SCANCODEIO_PIP_PACKAGE_ARG} release from PyPI"
pip install --upgrade "$SCANCODEIO_PIP_PACKAGE_ARG"
else
echo "Installing ${SCANCODEIO_PIP_PACKAGE_ARG} from the GitHub branch: $INPUT_REPO_BRANCH"
pip install "${SCANCODEIO_PIP_PACKAGE_ARG} @ git+https://github.com/aboutcode-org/scancode.io.git@${INPUT_REPO_BRANCH}"
fi
- name: Run migrations to prepare the database
if: env.SCANCODEIO_IS_INSTALLED != 'true'
shell: bash
run: scanpipe migrate --verbosity 0
- name: Generate `--pipeline` CLI arguments
shell: bash
env:
INPUT_PIPELINES: ${{ inputs.pipelines }}
run: |
IFS=',' read -ra PIPELINES <<< "$INPUT_PIPELINES"
PIPELINE_CLI_ARGS=""
for pipeline in "${PIPELINES[@]}"; do
PIPELINE_CLI_ARGS+=" --pipeline $pipeline"
done
echo "PIPELINE_CLI_ARGS=${PIPELINE_CLI_ARGS}" >> "$GITHUB_ENV"
- name: Generate `--input-url` CLI arguments
shell: bash
env:
INPUT_URLS: ${{ inputs.input-urls }}
run: |
INPUT_URL_CLI_ARGS=""
for url in $INPUT_URLS; do
if [[ "$url" =~ ^(https?|docker|pkg): ]]; then
INPUT_URL_CLI_ARGS+=" --input-url $url"
else
echo "::warning::Skipping unsupported URL scheme: $url"
fi
done
echo "INPUT_URL_CLI_ARGS=${INPUT_URL_CLI_ARGS}" >> "$GITHUB_ENV"
- name: Create project
shell: bash
env:
INPUT_PROJECT_NAME: ${{ inputs.project-name }}
run: |
scanpipe create-project "$INPUT_PROJECT_NAME" \
$PIPELINE_CLI_ARGS \
$INPUT_URL_CLI_ARGS
- name: Set project work directory in the environment
shell: bash
env:
INPUT_PROJECT_NAME: ${{ inputs.project-name }}
run: |
project_status=$(scanpipe status --project "$INPUT_PROJECT_NAME")
work_directory=$(echo "$project_status" | grep -oP 'Work directory:\s*\K[^\n]+')
echo "PROJECT_WORK_DIRECTORY=$work_directory" >> "$GITHUB_ENV"
- name: Copy input files to project work directory
if: ${{ !inputs.input-urls }}
shell: bash
env:
INPUT_INPUTS_PATH: ${{ inputs.inputs-path }}
WORKSPACE: ${{ github.workspace }}
run: |
SOURCE_PATH="$INPUT_INPUTS_PATH"
[[ "$SOURCE_PATH" != /* ]] && SOURCE_PATH="${WORKSPACE}/$SOURCE_PATH"
# Prevent path traversal outside the workspace
REAL_SOURCE=$(realpath -m "$SOURCE_PATH")
REAL_WORKSPACE=$(realpath "$WORKSPACE")
if [[ "$REAL_SOURCE" != "$REAL_WORKSPACE"* ]]; then
echo "::error::inputs-path resolves outside the workspace. Aborting."
exit 1
fi
DESTINATION_PATH="${PROJECT_WORK_DIRECTORY}/input/"
mkdir -p "$DESTINATION_PATH"
if [ -d "$SOURCE_PATH" ]; then
if [ "$(ls -A "$SOURCE_PATH")" ]; then
echo "Copying contents of directory: $SOURCE_PATH -> $DESTINATION_PATH"
cp -r "$SOURCE_PATH"/* "$DESTINATION_PATH"
else
echo "Input directory '$SOURCE_PATH' is empty, nothing to copy."
fi
elif [[ -f "$SOURCE_PATH" ]]; then
echo "Copying file: $SOURCE_PATH -> $DESTINATION_PATH"
cp "$SOURCE_PATH" "$DESTINATION_PATH"
fi
echo ""
echo "Input files now in: $DESTINATION_PATH"
ls -lh "$DESTINATION_PATH"
- name: Run the pipelines
shell: bash
env:
INPUT_PROJECT_NAME: ${{ inputs.project-name }}
run: scanpipe execute --project "$INPUT_PROJECT_NAME" --no-color
- name: Generate outputs
id: scanpipe
shell: bash
env:
INPUT_PROJECT_NAME: ${{ inputs.project-name }}
INPUT_OUTPUT_FORMATS: ${{ inputs.output-formats }}
run: |
scanpipe output \
--project "$INPUT_PROJECT_NAME" \
--format $INPUT_OUTPUT_FORMATS
- name: Upload outputs
uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f # v7.0.0
id: artifact-upload-step
with:
# Include the project name in case of multiple runs of the action
name: ${{ inputs.outputs-archive-name }}-${{ env.SAFE_PROJECT_NAME }}
path: ${{ env.PROJECT_WORK_DIRECTORY }}/output/*
overwrite: true
- name: Check compliance
if: inputs.check-compliance == 'true'
shell: bash
env:
INPUT_PROJECT_NAME: ${{ inputs.project-name }}
INPUT_FAIL_LEVEL: ${{ inputs.compliance-fail-level }}
INPUT_FAIL_ON_VULNS: ${{ inputs.compliance-fail-on-vulnerabilities }}
run: |
cmd=(
scanpipe check-compliance
--project "$INPUT_PROJECT_NAME"
--fail-level "$INPUT_FAIL_LEVEL"
)
if [[ "$INPUT_FAIL_ON_VULNS" == "true" ]]; then
cmd+=(--fail-on-vulnerabilities)
fi
"${cmd[@]}"