diff --git a/.github/workflows/multi-runs.yml b/.github/workflows/multi-runs.yml new file mode 100644 index 0000000..f77a52a --- /dev/null +++ b/.github/workflows/multi-runs.yml @@ -0,0 +1,35 @@ +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 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 eaa581d..3f79f27 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." @@ -58,16 +59,33 @@ 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 + 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 }} - sudo -u postgres psql -c "ALTER USER ${{ env.SCANCODEIO_DB_USER }} WITH encrypted password '${{ env.SCANCODEIO_DB_PASSWORD }}'" + 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 + - name: Install ScanCode.io (only if not already installed) + if: env.SCANCODEIO_IS_INSTALLED != 'true' shell: bash run: | if [ -z "${{ inputs.scancodeio-repo-branch }}" ]; then @@ -79,6 +97,7 @@ runs: fi - name: Run migrations to prepare the database + if: env.SCANCODEIO_IS_INSTALLED != 'true' shell: bash run: scanpipe migrate --verbosity 0 @@ -155,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