Skip to content

Commit 6cebf8d

Browse files
authored
Add workflow examples using the d2d and docker pipelines #4 (#5)
Signed-off-by: tdruez <[email protected]>
1 parent 4828c60 commit 6cebf8d

File tree

6 files changed

+98
-17
lines changed

6 files changed

+98
-17
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
on: [push]
2+
3+
jobs:
4+
scan-codebase:
5+
runs-on: ubuntu-22.04
6+
name: Analyze a Docker image with ScanCode.io
7+
steps:
8+
- uses: nexB/scancode-action@alpha
9+
with:
10+
pipelines: "analyze_docker_image"
11+
input-urls:
12+
https://github.com/nexB/scancode.io-tutorial/releases/download/sample-images/30-alpine-nickolashkraus-staticbox-latest.tar
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
on: [push]
2+
3+
jobs:
4+
scan-codebase:
5+
runs-on: ubuntu-22.04
6+
name: Map deploy to develop with ScanCode.io
7+
steps:
8+
- uses: nexB/scancode-action@alpha
9+
with:
10+
pipelines: "map_deploy_to_develop"
11+
input-urls:
12+
https://github.com/nexB/scancode.io/raw/main/scanpipe/tests/data/d2d/jars/from-flume-ng-node-1.9.0.zip#from
13+
https://github.com/nexB/scancode.io/raw/main/scanpipe/tests/data/d2d/jars/to-flume-ng-node-1.9.0.zip#to
14+
env:
15+
PURLDB_URL: https://public.purldb.io/

.github/workflows/scan-codebase.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ on: [push]
22

33
jobs:
44
scan-codebase:
5-
runs-on: ubuntu-latest
5+
runs-on: ubuntu-22.04
66
name: Scan codebase with ScanCode.io
77
steps:
88
- uses: actions/checkout@v4
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ on: [push]
22

33
jobs:
44
scan-codebase:
5-
runs-on: ubuntu-latest
5+
runs-on: ubuntu-22.04
66
name: Scan package with ScanCode.io
77
steps:
88
- name: Download repository archive to scancode-inputs/ directory
99
run: |
1010
wget --directory-prefix=scancode-inputs https://github.com/${GITHUB_REPOSITORY}/archive/${GITHUB_REF}.zip
1111
- uses: nexB/scancode-action@alpha
1212
with:
13-
pipelines: "scan_package"
13+
pipelines: "scan_single_package"

README.md

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ Run [ScanCode.io](https://github.com/nexB/scancode.io) pipelines from your Workf
1818
- [Run a specific pipeline](#run-a-specific-pipeline)
1919
- [Run multiple pipelines](#run-multiple-pipelines)
2020
- [Choose the output formats](#choose-the-output-formats)
21+
- [Provide download URLs inputs](#provide-download-urls-inputs)
2122
- [Fetch pipelines inputs](#fetch-pipelines-inputs)
2223
- [Define a custom project name](#define-a-custom-project-name)
2324
- [Where does the scan results go?](#where-does-the-scan-results-go)
@@ -49,22 +50,32 @@ steps:
4950
# The list of output formats to generate.
5051
# Default is 'json xlsx spdx cyclonedx'
5152
output-formats:
52-
53+
5354
# Relative path within the $GITHUB_WORKSPACE for pipeline inputs.
5455
# Default is 'scancode-inputs'
5556
inputs-path:
5657

58+
# Provide one or more URLs to download for the pipeline run execution
59+
input-urls:
60+
5761
# Name of the project.
5862
# Default is 'scancode-action'
5963
project-name:
6064

65+
# Name of the outputs archive.
66+
# Default is 'scancode-outputs'
67+
outputs-archive-name:
68+
6169
# Python version that will be installed to run ScanCode.io
6270
# Default is '3.11'
6371
python-version:
6472
```
6573
6674
## Examples
6775
76+
See https://github.com/nexB/scancode-action/tree/main/.github/workflows for Workflows
77+
examples.
78+
6879
### Scan repo codebase
6980
7081
```yaml
@@ -113,6 +124,17 @@ For details on setting up and configuring your own instance, please refer to the
113124
output-formats: "json xlsx spdx cyclonedx"
114125
```
115126

127+
### Provide download URLs inputs
128+
129+
```yaml
130+
- uses: nexB/scancode-action@alpha
131+
with:
132+
pipelines: "map_deploy_to_develop"
133+
input-urls:
134+
https://domain.url/source.zip#from
135+
https://domain.url/binaries.zip#to
136+
```
137+
116138
### Fetch pipelines inputs
117139

118140
```yaml
@@ -136,5 +158,5 @@ For details on setting up and configuring your own instance, please refer to the
136158

137159
Upon completion of the workflow, you can **find the scan results** in the dedicated
138160
**artifacts section** at the bottom of the workflow summary page.
139-
Look for a file named `scanpipe-outputs` in that section.
161+
Look for a file named `scancode-outputs` in that section.
140162
This file contains the outputs generated by the `scancode-action`.

action.yml

Lines changed: 44 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,16 @@ inputs:
1010
inputs-path:
1111
description: "Relative path within the $GITHUB_WORKSPACE for pipeline inputs"
1212
default: "${{ github.workspace }}/scancode-inputs"
13+
input-urls:
14+
description: 'Provide one or more URLs to download for the pipeline run execution'
15+
required: false
16+
default: ""
1317
project-name:
1418
description: "Name of the project"
1519
default: "scancode-action"
20+
outputs-archive-name:
21+
description: "Name of the outputs archive"
22+
default: "scancode-outputs"
1623
python-version:
1724
description: "Python version"
1825
default: "3.11"
@@ -28,29 +35,49 @@ runs:
2835
shell: bash
2936
run: |
3037
echo "SECRET_KEY=$(openssl rand -base64 32)" >> $GITHUB_ENV
31-
echo "SCANCODEIO_DB_ENGINE=django.db.backends.sqlite3" >> $GITHUB_ENV
32-
echo "SCANCODEIO_DB_NAME=sqlite3.db" >> $GITHUB_ENV
38+
echo "SCANCODEIO_DB_NAME=scancodeio" >> $GITHUB_ENV
39+
echo "SCANCODEIO_DB_USER=scancodeio" >> $GITHUB_ENV
40+
echo "SCANCODEIO_DB_PASSWORD=scancodeio" >> $GITHUB_ENV
41+
42+
- name: Start and setup the PostgreSQL service
43+
shell: bash
44+
run: |
45+
sudo systemctl start postgresql.service
46+
sudo -u postgres createuser --no-createrole --no-superuser --login --inherit --createdb ${{ env.SCANCODEIO_DB_USER }}
47+
sudo -u postgres psql -c "ALTER USER ${{ env.SCANCODEIO_DB_USER }} WITH encrypted password '${{ env.SCANCODEIO_DB_PASSWORD }}'"
48+
sudo -u postgres createdb --owner=scancodeio --encoding=UTF-8 ${{ env.SCANCODEIO_DB_NAME }}
3349
3450
- name: Install ScanCode.io
3551
shell: bash
3652
run: |
37-
pip install scancodeio
53+
pip install --upgrade scancodeio
3854
scanpipe migrate
3955
40-
- name: Generate pipelines CLI arguments
56+
- name: Generate `--pipeline` CLI arguments
4157
shell: bash
4258
run: |
4359
IFS=',' read -ra PIPELINES <<< "${{ inputs.pipelines }}"
44-
options=""
60+
PIPELINE_CLI_ARGS=""
4561
for pipeline in "${PIPELINES[@]}"; do
46-
options+="--pipeline $pipeline "
62+
PIPELINE_CLI_ARGS+=" --pipeline $pipeline"
63+
done
64+
echo "PIPELINE_CLI_ARGS=${PIPELINE_CLI_ARGS}" >> $GITHUB_ENV
65+
66+
- name: Generate `--input-url` CLI arguments
67+
shell: bash
68+
run: |
69+
INPUT_URL_CLI_ARGS=""
70+
for url in ${{ inputs.input-urls }}; do
71+
INPUT_URL_CLI_ARGS+=" --input-url $url"
4772
done
48-
echo "PIPELINE_CLI_ARGS=${options}" >> $GITHUB_ENV
73+
echo "INPUT_URL_CLI_ARGS=${INPUT_URL_CLI_ARGS}" >> $GITHUB_ENV
4974
50-
- name: Create project with ${{ inputs.pipelines }} pipelines
75+
- name: Create project
5176
shell: bash
5277
run: |
53-
scanpipe create-project ${{ inputs.project-name }} ${{ env.PIPELINE_CLI_ARGS }}
78+
scanpipe create-project ${{ inputs.project-name }} \
79+
${{ env.PIPELINE_CLI_ARGS }} \
80+
${{ env.INPUT_URL_CLI_ARGS }}
5481
5582
- name: Set project work directory in the environment
5683
shell: bash
@@ -61,7 +88,12 @@ runs:
6188
6289
- name: Copy input files to project work directory
6390
shell: bash
64-
run: cp -r ${{ inputs.inputs-path }}/* ${{ env.PROJECT_WORK_DIRECTORY }}/input/
91+
run: |
92+
SOURCE_PATH="${{ inputs.inputs-path }}"
93+
DESTINATION_PATH="${{ env.PROJECT_WORK_DIRECTORY }}/input/"
94+
if [ -d "$SOURCE_PATH" ]; then
95+
cp -r "$SOURCE_PATH"/* "$DESTINATION_PATH"
96+
fi
6597
6698
- name: Run the pipelines
6799
shell: bash
@@ -70,7 +102,7 @@ runs:
70102
- name: Generate outputs
71103
id: scanpipe
72104
shell: bash
73-
run: scanpipe output
105+
run: scanpipe output
74106
--project ${{ inputs.project-name }}
75107
--format ${{ inputs.output-formats }}
76108
--no-color
@@ -79,5 +111,5 @@ runs:
79111
uses: actions/upload-artifact@v4
80112
id: artifact-upload-step
81113
with:
82-
name: scanpipe-outputs
114+
name: ${{ inputs.outputs-archive-name }}
83115
path: ${{ env.PROJECT_WORK_DIRECTORY }}/output/*

0 commit comments

Comments
 (0)