Skip to content

Commit 0def5ca

Browse files
authored
Make the action re-usable within a workflow job (#26)
Signed-off-by: tdruez <[email protected]>
1 parent a54be50 commit 0def5ca

File tree

2 files changed

+58
-3
lines changed

2 files changed

+58
-3
lines changed

.github/workflows/multi-runs.yml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
on: [push]
2+
3+
jobs:
4+
multi-runs:
5+
runs-on: ubuntu-24.04
6+
name: Ensure the action can be executed multiple times
7+
steps:
8+
- name: Get the action.yml from the current branch
9+
uses: actions/checkout@v4
10+
with:
11+
sparse-checkout: action.yml
12+
sparse-checkout-cone-mode: false
13+
14+
- uses: actions/checkout@v4
15+
with:
16+
path: scancode-inputs
17+
18+
- uses: ./
19+
with:
20+
project-name: "scan-1"
21+
pipelines: "scan_codebase"
22+
23+
- uses: ./
24+
with:
25+
project-name: "scan-2"
26+
pipelines: "scan_codebase"
27+
28+
- name: Verify scanpipe and scancode commands availability
29+
shell: bash
30+
run: |
31+
echo "Checking ScanCode CLI availability..."
32+
which scanpipe || { echo "scanpipe not found in PATH"; exit 1; }
33+
which scancode || { echo "scancode not found in PATH"; exit 1; }
34+
echo "Versions:"
35+
scanpipe shell -c "import scancodeio; from scancode_config import __version__ as scancode_version;print(f'ScanCode.io version: {scancodeio.__version__}');print(f'ScanCode-toolkit version: v{scancode_version}')"

action.yml

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
name: "ScanCode action"
22
description: "Run ScanCode.io pipelines in your workflows"
3+
34
inputs:
45
pipelines:
56
description: "Names of the pipelines (comma-separated) and in order."
@@ -58,16 +59,33 @@ runs:
5859
echo "SCANCODEIO_DB_NAME=scancodeio" >> $GITHUB_ENV
5960
echo "SCANCODEIO_DB_USER=scancodeio" >> $GITHUB_ENV
6061
echo "SCANCODEIO_DB_PASSWORD=scancodeio" >> $GITHUB_ENV
62+
# Sanitize project name for artifact usage
63+
SAFE_PROJECT_NAME="${{ inputs.project-name }}"
64+
SAFE_PROJECT_NAME="${SAFE_PROJECT_NAME//[^a-zA-Z0-9._-]/_}"
65+
echo "SAFE_PROJECT_NAME=$SAFE_PROJECT_NAME" >> $GITHUB_ENV
66+
67+
- name: Detect if ScanCode.io is already installed
68+
shell: bash
69+
run: |
70+
if command -v scanpipe &> /dev/null; then
71+
echo "ScanCode.io already installed."
72+
echo "SCANCODEIO_IS_INSTALLED=true" >> $GITHUB_ENV
73+
else
74+
echo "ScanCode.io not found."
75+
echo "SCANCODEIO_IS_INSTALLED=false" >> $GITHUB_ENV
76+
fi
6177
6278
- name: Start and setup the PostgreSQL service
79+
if: env.SCANCODEIO_IS_INSTALLED != 'true'
6380
shell: bash
6481
run: |
6582
sudo systemctl start postgresql.service
6683
sudo -u postgres createuser --no-createrole --no-superuser --login --inherit --createdb ${{ env.SCANCODEIO_DB_USER }}
67-
sudo -u postgres psql -c "ALTER USER ${{ env.SCANCODEIO_DB_USER }} WITH encrypted password '${{ env.SCANCODEIO_DB_PASSWORD }}'"
84+
sudo -u postgres psql -c "ALTER USER ${{ env.SCANCODEIO_DB_USER }} WITH ENCRYPTED PASSWORD '${{ env.SCANCODEIO_DB_PASSWORD }}'"
6885
sudo -u postgres createdb --owner=scancodeio --encoding=UTF-8 ${{ env.SCANCODEIO_DB_NAME }}
6986
70-
- name: Install ScanCode.io
87+
- name: Install ScanCode.io (only if not already installed)
88+
if: env.SCANCODEIO_IS_INSTALLED != 'true'
7189
shell: bash
7290
run: |
7391
if [ -z "${{ inputs.scancodeio-repo-branch }}" ]; then
@@ -79,6 +97,7 @@ runs:
7997
fi
8098
8199
- name: Run migrations to prepare the database
100+
if: env.SCANCODEIO_IS_INSTALLED != 'true'
82101
shell: bash
83102
run: scanpipe migrate --verbosity 0
84103

@@ -155,7 +174,8 @@ runs:
155174
uses: actions/upload-artifact@v4
156175
id: artifact-upload-step
157176
with:
158-
name: ${{ inputs.outputs-archive-name }}
177+
# Include the project name in case of multiple runs of the action
178+
name: ${{ inputs.outputs-archive-name }}-${{ env.SAFE_PROJECT_NAME }}
159179
path: ${{ env.PROJECT_WORK_DIRECTORY }}/output/*
160180
overwrite: true
161181

0 commit comments

Comments
 (0)