Skip to content

Commit 022539a

Browse files
committed
Make the action re-usable within a workflow job
Signed-off-by: tdruez <[email protected]>
1 parent a54be50 commit 022539a

File tree

2 files changed

+50
-9
lines changed

2 files changed

+50
-9
lines changed

.github/workflows/multi-runs.yml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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 --version
36+
scancode --version

action.yml

Lines changed: 14 additions & 9 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."
@@ -63,19 +64,23 @@ runs:
6364
shell: bash
6465
run: |
6566
sudo systemctl start postgresql.service
66-
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 }}'"
68-
sudo -u postgres createdb --owner=scancodeio --encoding=UTF-8 ${{ env.SCANCODEIO_DB_NAME }}
67+
sudo -u postgres createuser --no-createrole --no-superuser --login --inherit --createdb ${{ env.SCANCODEIO_DB_USER }} || true
68+
sudo -u postgres psql -c "ALTER USER ${{ env.SCANCODEIO_DB_USER }} WITH ENCRYPTED PASSWORD '${{ env.SCANCODEIO_DB_PASSWORD }}'" || true
69+
sudo -u postgres createdb --owner=scancodeio --encoding=UTF-8 ${{ env.SCANCODEIO_DB_NAME }} || true
6970
70-
- name: Install ScanCode.io
71+
- name: Install ScanCode.io (only if not already installed)
7172
shell: bash
7273
run: |
73-
if [ -z "${{ inputs.scancodeio-repo-branch }}" ]; then
74-
echo "Installing the latest ScanCode.io release from PyPI"
75-
pip install --upgrade scancodeio
74+
if ! command -v scanpipe &> /dev/null; then
75+
if [ -z "${{ inputs.scancodeio-repo-branch }}" ]; then
76+
echo "Installing the latest ScanCode.io release from PyPI"
77+
pip install --upgrade scancodeio
78+
else
79+
echo "Installing ScanCode.io from the GitHub branch: ${{ inputs.scancodeio-repo-branch }}"
80+
pip install git+https://github.com/aboutcode-org/scancode.io.git@${{ inputs.scancodeio-repo-branch }}
81+
fi
7682
else
77-
echo "Installing ScanCode.io from the GitHub branch: ${{ inputs.scancodeio-repo-branch }}"
78-
pip install git+https://github.com/aboutcode-org/scancode.io.git@${{ inputs.scancodeio-repo-branch }}
83+
echo "ScanCode.io already installed, skipping installation."
7984
fi
8085
8186
- name: Run migrations to prepare the database

0 commit comments

Comments
 (0)