diff --git a/.github/workflows/__call-common-lint.yml b/.github/workflows/__call-common-lint.yml index fe282b42..5feb30eb 100644 --- a/.github/workflows/__call-common-lint.yml +++ b/.github/workflows/__call-common-lint.yml @@ -668,6 +668,47 @@ jobs: echo "::remove-matcher owner=shellcheck-gcc::" exit ${error} + - name: PKGBUILD - find files + id: pkgbuild_files + if: always() + shell: bash + run: | + recipes=$(git ls-files -- ':(glob)**/PKGBUILD') + if [[ -n $recipes ]]; then + echo 'found=true' >> "$GITHUB_OUTPUT" + fi + + - name: PKGBUILD - ShellCheck + if: always() && steps.pkgbuild_files.outputs.found == 'true' + shell: bash + run: | + echo '::add-matcher::.github/matchers/shellcheck-gcc.json' + trap 'echo "::remove-matcher owner=shellcheck-gcc::"' EXIT + # makepkg consumes the recipe variables, supplies its own variables, and stops on command failures. + git ls-files -z -- ':(glob)**/PKGBUILD' | + xargs -0 shellcheck --shell=bash --format=gcc --exclude=SC2034,SC2154,SC2164 -- + + - name: PKGBUILD - namcap + if: always() && steps.pkgbuild_files.outputs.found == 'true' && runner.os == 'Linux' && runner.arch == 'X64' + shell: bash + run: | + image=$(docker build --quiet - <<'DOCKERFILE' + FROM archlinux:base + RUN pacman -Syu --noconfirm --needed namcap && pacman -Scc --noconfirm + DOCKERFILE + ) + + # namcap loads the recipe as Bash. Give it read-only sources and no network. + report=$(git ls-files -z -- ':(glob)**/PKGBUILD' | + docker run --rm -i --network=none --read-only --tmpfs /tmp \ + --cap-drop=ALL --security-opt=no-new-privileges --user 65534:65534 \ + --mount "type=bind,source=$GITHUB_WORKSPACE,target=/workspace,readonly" \ + --workdir /workspace "$image" xargs -0 namcap --) + printf '%s\n' "$report" + if grep -qE '^PKGBUILD( \([^)]*\))? E:' <<< "$report"; then + exit 1 + fi + - name: YAML - find files id: yaml_files if: always() diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 1d56c2ea..1c9c8f16 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -146,12 +146,14 @@ of the repository. The following table shows the labels and the corresponding te | `docker` | hadolint | | `github-action`, `github-workflow` | actionlint | | `jupyter`, `python` | flake8 | +| `PKGBUILD` | shellcheck, namcap | | `PowerShell` | PSScriptAnalyzer | | `rust` | rustfmt | | `shell` | shellcheck | | `yaml` | yamllint | Projects may have additional checks, `eslint` for example, depending on the project's requirements. +The shared workflow runs namcap on x64 Linux runners. #### Unit Testing We strive to have comprehensive unit tests for our projects, but this is still a work in progress for some projects.