From 022539a84ae7c9bcae01f9191da84260305bf1c7 Mon Sep 17 00:00:00 2001 From: tdruez Date: Mon, 20 Oct 2025 11:10:55 +0400 Subject: [PATCH 1/3] Make the action re-usable within a workflow job Signed-off-by: tdruez --- .github/workflows/multi-runs.yml | 36 ++++++++++++++++++++++++++++++++ action.yml | 23 ++++++++++++-------- 2 files changed, 50 insertions(+), 9 deletions(-) create mode 100644 .github/workflows/multi-runs.yml diff --git a/.github/workflows/multi-runs.yml b/.github/workflows/multi-runs.yml new file mode 100644 index 0000000..a41eac3 --- /dev/null +++ b/.github/workflows/multi-runs.yml @@ -0,0 +1,36 @@ +on: [push] + +jobs: + multi-runs: + runs-on: ubuntu-24.04 + name: Ensure the action can be executed multiple times + steps: + - name: Get the action.yml from the current branch + uses: actions/checkout@v4 + with: + sparse-checkout: action.yml + sparse-checkout-cone-mode: false + + - uses: actions/checkout@v4 + with: + path: scancode-inputs + + - uses: ./ + with: + project-name: "scan-1" + pipelines: "scan_codebase" + + - uses: ./ + with: + project-name: "scan-2" + pipelines: "scan_codebase" + + - name: Verify scanpipe and scancode commands availability + shell: bash + run: | + echo "Checking ScanCode CLI availability..." + which scanpipe || { echo "scanpipe not found in PATH"; exit 1; } + which scancode || { echo "scancode not found in PATH"; exit 1; } + echo "Versions:" + scanpipe --version + scancode --version diff --git a/action.yml b/action.yml index eaa581d..2705c5c 100644 --- a/action.yml +++ b/action.yml @@ -1,5 +1,6 @@ name: "ScanCode action" description: "Run ScanCode.io pipelines in your workflows" + inputs: pipelines: description: "Names of the pipelines (comma-separated) and in order." @@ -63,19 +64,23 @@ runs: shell: bash run: | sudo systemctl start postgresql.service - sudo -u postgres createuser --no-createrole --no-superuser --login --inherit --createdb ${{ env.SCANCODEIO_DB_USER }} - sudo -u postgres psql -c "ALTER USER ${{ env.SCANCODEIO_DB_USER }} WITH encrypted password '${{ env.SCANCODEIO_DB_PASSWORD }}'" - sudo -u postgres createdb --owner=scancodeio --encoding=UTF-8 ${{ env.SCANCODEIO_DB_NAME }} + sudo -u postgres createuser --no-createrole --no-superuser --login --inherit --createdb ${{ env.SCANCODEIO_DB_USER }} || true + sudo -u postgres psql -c "ALTER USER ${{ env.SCANCODEIO_DB_USER }} WITH ENCRYPTED PASSWORD '${{ env.SCANCODEIO_DB_PASSWORD }}'" || true + sudo -u postgres createdb --owner=scancodeio --encoding=UTF-8 ${{ env.SCANCODEIO_DB_NAME }} || true - - name: Install ScanCode.io + - name: Install ScanCode.io (only if not already installed) shell: bash run: | - if [ -z "${{ inputs.scancodeio-repo-branch }}" ]; then - echo "Installing the latest ScanCode.io release from PyPI" - pip install --upgrade scancodeio + if ! command -v scanpipe &> /dev/null; then + if [ -z "${{ inputs.scancodeio-repo-branch }}" ]; then + echo "Installing the latest ScanCode.io release from PyPI" + pip install --upgrade scancodeio + else + echo "Installing ScanCode.io from the GitHub branch: ${{ inputs.scancodeio-repo-branch }}" + pip install git+https://github.com/aboutcode-org/scancode.io.git@${{ inputs.scancodeio-repo-branch }} + fi else - echo "Installing ScanCode.io from the GitHub branch: ${{ inputs.scancodeio-repo-branch }}" - pip install git+https://github.com/aboutcode-org/scancode.io.git@${{ inputs.scancodeio-repo-branch }} + echo "ScanCode.io already installed, skipping installation." fi - name: Run migrations to prepare the database From 542a9d324957757fd20dd4c25c837521f900fffe Mon Sep 17 00:00:00 2001 From: tdruez Date: Mon, 20 Oct 2025 13:29:04 +0400 Subject: [PATCH 2/3] Refine the installation skips Signed-off-by: tdruez --- .github/workflows/multi-runs.yml | 3 +-- action.yml | 34 +++++++++++++++++++++----------- 2 files changed, 23 insertions(+), 14 deletions(-) diff --git a/.github/workflows/multi-runs.yml b/.github/workflows/multi-runs.yml index a41eac3..f77a52a 100644 --- a/.github/workflows/multi-runs.yml +++ b/.github/workflows/multi-runs.yml @@ -32,5 +32,4 @@ jobs: which scanpipe || { echo "scanpipe not found in PATH"; exit 1; } which scancode || { echo "scancode not found in PATH"; exit 1; } echo "Versions:" - scanpipe --version - scancode --version + 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}')" diff --git a/action.yml b/action.yml index 2705c5c..263cf7e 100644 --- a/action.yml +++ b/action.yml @@ -60,30 +60,40 @@ runs: echo "SCANCODEIO_DB_USER=scancodeio" >> $GITHUB_ENV echo "SCANCODEIO_DB_PASSWORD=scancodeio" >> $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 ${{ env.SCANCODEIO_DB_USER }} || true - sudo -u postgres psql -c "ALTER USER ${{ env.SCANCODEIO_DB_USER }} WITH ENCRYPTED PASSWORD '${{ env.SCANCODEIO_DB_PASSWORD }}'" || true - sudo -u postgres createdb --owner=scancodeio --encoding=UTF-8 ${{ env.SCANCODEIO_DB_NAME }} || true + sudo -u postgres createuser --no-createrole --no-superuser --login --inherit --createdb ${{ env.SCANCODEIO_DB_USER }} + sudo -u postgres psql -c "ALTER USER ${{ env.SCANCODEIO_DB_USER }} WITH ENCRYPTED PASSWORD '${{ env.SCANCODEIO_DB_PASSWORD }}'" + sudo -u postgres createdb --owner=scancodeio --encoding=UTF-8 ${{ env.SCANCODEIO_DB_NAME }} - name: Install ScanCode.io (only if not already installed) + if: env.SCANCODEIO_IS_INSTALLED != 'true' shell: bash run: | - if ! command -v scanpipe &> /dev/null; then - if [ -z "${{ inputs.scancodeio-repo-branch }}" ]; then - echo "Installing the latest ScanCode.io release from PyPI" - pip install --upgrade scancodeio - else - echo "Installing ScanCode.io from the GitHub branch: ${{ inputs.scancodeio-repo-branch }}" - pip install git+https://github.com/aboutcode-org/scancode.io.git@${{ inputs.scancodeio-repo-branch }} - fi + if [ -z "${{ inputs.scancodeio-repo-branch }}" ]; then + echo "Installing the latest ScanCode.io release from PyPI" + pip install --upgrade scancodeio else - echo "ScanCode.io already installed, skipping installation." + echo "Installing ScanCode.io from the GitHub branch: ${{ inputs.scancodeio-repo-branch }}" + pip install git+https://github.com/aboutcode-org/scancode.io.git@${{ inputs.scancodeio-repo-branch }} fi - name: Run migrations to prepare the database + if: env.SCANCODEIO_IS_INSTALLED != 'true' shell: bash run: scanpipe migrate --verbosity 0 From 2eb6c551225b2700676cc103e6e4d18a0413eb0c Mon Sep 17 00:00:00 2001 From: tdruez Date: Mon, 20 Oct 2025 13:46:35 +0400 Subject: [PATCH 3/3] Include the project name in case of multiple runs of the action Signed-off-by: tdruez --- action.yml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/action.yml b/action.yml index 263cf7e..3f79f27 100644 --- a/action.yml +++ b/action.yml @@ -59,6 +59,10 @@ runs: 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="${{ inputs.project-name }}" + SAFE_PROJECT_NAME="${SAFE_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 @@ -170,7 +174,8 @@ runs: uses: actions/upload-artifact@v4 id: artifact-upload-step with: - name: ${{ inputs.outputs-archive-name }} + # 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