|
| 1 | +--- |
| 2 | +# SPDX-License-Identifier: Apache-2.0 |
| 3 | +# SPDX-FileCopyrightText: 2025 The Linux Foundation |
| 4 | + |
| 5 | +# python-audit-action |
| 6 | +name: "🐍 Python Dependency Audit" |
| 7 | +# yamllint disable-line rule:line-length |
| 8 | +description: "Check a Python project's dependencies for known security vulnerabilities" |
| 9 | + |
| 10 | +inputs: |
| 11 | + # Mandatory |
| 12 | + PYTHON_VERSION: |
| 13 | + description: "Python version used to perform audit" |
| 14 | + required: true |
| 15 | + # Optional |
| 16 | + ARTEFACT_NAME: |
| 17 | + description: "Build artefacts from previous job(s) have this name/label" |
| 18 | + required: false |
| 19 | + type: string |
| 20 | + ARTEFACT_PATH: |
| 21 | + description: "Build artefacts will be downloaded to this folder/directory" |
| 22 | + required: true |
| 23 | + type: string |
| 24 | + default: "dist" |
| 25 | + NEVER_FAIL: |
| 26 | + description: "Continue even when an audit fails" |
| 27 | + required: false |
| 28 | + default: false |
| 29 | + SUMMARY: |
| 30 | + description: "Whether to generate summary output" |
| 31 | + type: boolean |
| 32 | + required: false |
| 33 | + default: true |
| 34 | + PATH_PREFIX: |
| 35 | + description: "Directory location containing project code" |
| 36 | + type: string |
| 37 | + required: false |
| 38 | + default: "" |
| 39 | + |
| 40 | +runs: |
| 41 | + using: "composite" |
| 42 | + steps: |
| 43 | + - name: "Download build artefacts ⬇" |
| 44 | + # yamllint disable-line rule:line-length |
| 45 | + uses: actions/download-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2 |
| 46 | + with: |
| 47 | + name: "${{ inputs.artefact_name }}" |
| 48 | + path: "${{ inputs.artefact_path }}" |
| 49 | + if-no-files-found: error |
| 50 | + |
| 51 | + - name: "Setup Python ${{ inputs.python_version }}" |
| 52 | + # yamllint disable-line rule:line-length |
| 53 | + uses: actions/setup-python@0b93645e9fea7318ecaed2b359559ac225c90a2b # v5.3.0 |
| 54 | + with: |
| 55 | + python-version: ${{ inputs.python_version }} |
| 56 | + |
| 57 | + - name: "Install tooling and build products/dependencies" |
| 58 | + shell: bash |
| 59 | + run: | |
| 60 | + # Install tooling and build products/dependencies |
| 61 | + echo "Upgrading: pip, pipx, setuptools" |
| 62 | + python -m pip install -q --upgrade pip pipx setuptools |
| 63 | + echo "Installing built package(s) and dependencies" |
| 64 | + for WHEEL in ${{ inputs.artefact_path }}/*.whl; do |
| 65 | + echo "Installing: $WHEEL" |
| 66 | + pip install -q "$WHEEL" |
| 67 | + done |
| 68 | +
|
| 69 | + - name: "Install from Pipfile.lock/requirements.txt" |
| 70 | + shell: bash |
| 71 | + run: | |
| 72 | + # Export/install additional dependencies |
| 73 | + if [ -f "${{ inputs.path_prefix }}"Pipfile.lock ]; then |
| 74 | + echo "Exporting dependencies from: Pipfile.lock" |
| 75 | + pipx run pipfile-requirements ${{ inputs.path_prefix }}Pipfile.lock \ |
| 76 | + > ${{ inputs.path_prefix }}requirements.txt |
| 77 | + fi |
| 78 | + if [ -f "${{ inputs.path_prefix }}"requirements.txt ]; then |
| 79 | + echo "Installing dependencies from: requirements.txt" |
| 80 | + pip install -q -r requirements.txt |
| 81 | + fi |
| 82 | +
|
| 83 | + - name: "Auditing with: pypa/gh-action-pip-audit" |
| 84 | + # yamllint disable-line rule:line-length |
| 85 | + uses: pypa/gh-action-pip-audit@1220774d901786e6f652ae159f7b6bc8fea6d266 # v1.1.0 |
| 86 | + with: |
| 87 | + inputs: ${{ inputs.path_prefix }} |
| 88 | + summary: ${{ inputs.summary }} |
| 89 | + virtual-environment: env/ |
0 commit comments