diff --git a/.claude/skills/adopt-workflow-parts/SKILL.md b/.claude/skills/adopt-workflow-parts/SKILL.md index a66ebae..b3bb981 100644 --- a/.claude/skills/adopt-workflow-parts/SKILL.md +++ b/.claude/skills/adopt-workflow-parts/SKILL.md @@ -88,7 +88,7 @@ Safety before convenience, and fewer dependencies over more. - `istarci run ` retries a run that must run again (daemon restart, change to `~/.istarci/config.yml`), never right after a commit. - A command over the 600 second tool limit is moved to the background, against the foreground rule: `timeout 590 istarci wait` then call it again while the run is going. -- `.istarci.yml` of a consumer sets the runner image per job (`ghcr.io/devpro/debian-node-playwright` for browser tests), +- `.istarci.yml` of a consumer sets the runner image per job (`ghcr.io/devpro/ubuntu-node-playwright` for browser tests), the jobs needing Docker, and `skipJobs` for jobs that must never run on the developer machine (kind's privileged node, a QEMU registration in the kernel). - The global ignores of image scans live in `~/.istarci/config.yml`, each with a reason and an expiry. diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3a460f6..0eff562 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -555,6 +555,21 @@ jobs: fi done + # A Windows image is built on the Windows runner alone, and a CI run pushes nothing. + test-windows-container-publication: + name: "Test / Container publication reusable workflow, a Windows image without push" + uses: ./.github/workflows/reusable-container-publication.yml + with: + push: false + scan: true + scan-path: C:\Windows\System32\drivers\etc + image-definition: test/fixtures/container/windows/Dockerfile + image-path: localhost + image-name: windows-test + image-tag: ${{ github.run_id }} + image-platform: "" + windows-runner: windows-2025 + test-container-build-push-arm64: name: "Test / Container build-push action on an arm64 runner" runs-on: ubuntu-24.04-arm @@ -731,6 +746,31 @@ jobs: jq -e '.bomFormat == "CycloneDX" and (.components | length > 0)' sbom-image-test.cdx.json jq -e '[.packages[].name] | index("playwright-fixture") and (index("node-fixture") | not)' sbom-exclude-test.spdx.json + test-syft-generate-sbom-windows: + name: "Test / Syft generate-sbom action on Windows" + runs-on: windows-2025 + timeout-minutes: 20 + steps: + - name: Clone repository + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false + - name: Generate SBOM for a directory, one folder left out + uses: ./actions/syft/generate-sbom + with: + exclude-paths: node + target-path: test/fixtures + output-file: sbom-exclude-test.spdx.json + upload-artifact: "false" + # PowerShell reads the JSON, as a Windows runner image may lack jq. + - name: Verify SBOM was generated + shell: pwsh + run: | + syft version + if ($LASTEXITCODE -ne 0) { exit 1 } + $names = (Get-Content -Raw sbom-exclude-test.spdx.json | ConvertFrom-Json).packages.name + if (-not ($names -contains 'playwright-fixture') -or ($names -contains 'node-fixture')) { exit 1 } + test-trivy-scan: name: "Test / Trivy scan action" runs-on: ubuntu-latest @@ -791,17 +831,29 @@ jobs: scan-type: config target: test/fixtures/terraform ignore-file: test/fixtures/trivy/missing.yaml - - name: Verify SARIF report was generated and the findings failed the scans + # The metadata of an installed Python package, a version with known vulnerabilities, stands for the binaries and packages of a directory. + - name: Scan the installed packages of a directory with Trivy + uses: ./actions/trivy/scan + with: + scan-type: rootfs + target: test/fixtures/trivy/rootfs + format: json + output-file: trivy-rootfs.json + severity: HIGH,CRITICAL + - name: Verify the reports were generated and the findings failed the scans env: EXPIRED_OUTCOME: ${{ steps.trivy-expired.outcome }} FINDING_OUTCOME: ${{ steps.trivy-finding.outcome }} MISSING_IGNORE_FILE_OUTCOME: ${{ steps.trivy-missing-ignore-file.outcome }} run: | jq -e '.version == "2.1.0"' trivy-test.sarif + jq -e '[.Results[] | select(.Type == "python-pkg") | .Vulnerabilities[].VulnerabilityID] | any(. == "CVE-2019-11324")' trivy-rootfs.json [ "$FINDING_OUTCOME" = failure ] [ "$EXPIRED_OUTCOME" = failure ] [ "$MISSING_IGNORE_FILE_OUTCOME" = failure ] + # The fixture locks the latest release of hashicorp/local, so a "Vulnerable provider" warning on it comes from the Go version and modules HashiCorp built it with. + # It is expected, shows the provider scan works, and goes away with a new release of the provider once the lock files are updated with terraform init -upgrade. test-terraform-quality: name: "Test / Terraform quality reusable workflow" uses: ./.github/workflows/reusable-terraform-quality.yml @@ -838,6 +890,14 @@ jobs: secrets: sonar-token: ${{ secrets.SONAR_TOKEN }} + # The fixture mixes a project of the old format restored from packages.config and an SDK one, as .NET Framework code being migrated does. + test-windows-dotnet-framework-quality: + name: "Test / .NET Framework quality reusable workflow" + uses: ./.github/workflows/reusable-dotnet-framework-quality.yml + with: + solution: Fixture.Framework.sln + working-directory: test/fixtures/dotnet-framework + test-dotnet-build-test: name: "Test / .NET build-test action writes results, coverage and reports" runs-on: ubuntu-latest @@ -1057,7 +1117,7 @@ jobs: FIXTURE_VALUE=extra mongodb-enabled: true task-enabled: true - terraform-version: 1.17.1 + terraform-version: 1.17.2 test-script: test:coverage working-directory: test/fixtures/node diff --git a/.github/workflows/reusable-container-publication.yml b/.github/workflows/reusable-container-publication.yml index 8c97dc6..fdadd3b 100644 --- a/.github/workflows/reusable-container-publication.yml +++ b/.github/workflows/reusable-container-publication.yml @@ -1,6 +1,7 @@ name: Reusable - Container publication # description: | # Builds a new container image with Docker and pushes it to a registry +# With push false, the images are only built, so a CI pipeline checks the packaging with the same code, and no credentials # Make sure to add (needed by cosign): # ``` # permissions: @@ -16,6 +17,21 @@ on: type: string required: false default: "docker.io" + push: + description: Push the images and put them under the tag, which is otherwise left to a later run, the registry credentials being then not read + type: boolean + required: false + default: true + scan: + description: Scan the Windows image with Grype once built, failing on a critical vulnerability, which needs push false since a pushed image is removed from the runner + type: boolean + required: false + default: false + scan-path: + description: Folder of the Windows image the scan reads alone (for example C:\app), in seconds, the whole image when empty, which takes minutes for the gigabytes of its base layers + type: string + required: false + default: "" create-latest: description: "Create latest tag?" type: boolean @@ -43,7 +59,7 @@ on: type: string required: true image-platform: - description: Platforms to build, emulated with QEMU on operating-system, unless arm64-runner is set + description: Linux platforms to build, emulated with QEMU on operating-system, unless arm64-runner is set, none when empty type: string required: false default: "linux/amd64,linux/arm64" @@ -52,6 +68,11 @@ on: type: string required: false default: "" + windows-runner: + description: Windows runner label building windows/amd64 (for example "windows-2025"), for the Windows version of that runner, put under the tag beside the Linux platforms, none when empty + type: string + required: false + default: "" job-name: description: Job name type: string @@ -79,11 +100,11 @@ on: default: "." secrets: container-registry-username: - description: Container registry username - required: true + description: Container registry username, needed to push + required: false container-registry-password: - description: Container registry password - required: true + description: Container registry password, needed to push + required: false secret-vars: description: "Additional environment variables" required: false @@ -91,9 +112,11 @@ on: jobs: build-emulated: name: ${{ inputs.job-name }} build (emulated) - if: ${{ inputs.arm64-runner == '' }} + if: ${{ inputs.arm64-runner == '' && inputs.image-platform != '' }} runs-on: ${{ inputs.operating-system }} timeout-minutes: ${{ inputs.timeout-minutes }} + outputs: + digest: ${{ steps.build.outputs.digest }} steps: - name: Set secret variables shell: bash @@ -121,6 +144,7 @@ jobs: path: workflow-parts persist-credentials: false - name: Login to container registry + if: ${{ inputs.push }} env: REGISTRY: ${{ inputs.container-registry }} REGISTRY_USERNAME: ${{ secrets.container-registry-username }} @@ -132,13 +156,15 @@ jobs: uses: ./workflow-parts/actions/qemu/setup with: platforms: ${{ inputs.image-platform }} - # The action puts the platforms together under the tag once each is pushed. + # The action puts the platforms together under the tag once each is pushed, and the Windows image joins them later under another one. - name: Build and push container image + id: build uses: ./workflow-parts/actions/container/build-push with: + push: ${{ inputs.push }} image-definition: ${{ inputs.image-definition }} image-repository: ${{ env.IMAGE_REPOSITORY }} - image-tag: ${{ inputs.image-tag }} + image-tag: ${{ inputs.windows-runner != '' && format('{0}-linux', inputs.image-tag) || inputs.image-tag }} platforms: ${{ inputs.image-platform }} build-arguments: ${{ inputs.extra-build-arguments }} working-directory: ${{ inputs.working-directory }} @@ -177,6 +203,7 @@ jobs: path: workflow-parts persist-credentials: false - name: Login to container registry + if: ${{ inputs.push }} env: REGISTRY: ${{ inputs.container-registry }} REGISTRY_USERNAME: ${{ secrets.container-registry-username }} @@ -186,6 +213,7 @@ jobs: id: build uses: ./workflow-parts/actions/container/build-push with: + push: ${{ inputs.push }} image-definition: ${{ inputs.image-definition }} image-repository: ${{ env.IMAGE_REPOSITORY }} image-tag: ${{ inputs.image-tag }}-linux-amd64 @@ -227,6 +255,7 @@ jobs: path: workflow-parts persist-credentials: false - name: Login to container registry + if: ${{ inputs.push }} env: REGISTRY: ${{ inputs.container-registry }} REGISTRY_USERNAME: ${{ secrets.container-registry-username }} @@ -236,6 +265,7 @@ jobs: id: build uses: ./workflow-parts/actions/container/build-push with: + push: ${{ inputs.push }} image-definition: ${{ inputs.image-definition }} image-repository: ${{ env.IMAGE_REPOSITORY }} image-tag: ${{ inputs.image-tag }}-linux-arm64 @@ -243,12 +273,62 @@ jobs: build-arguments: ${{ inputs.extra-build-arguments }} working-directory: ${{ inputs.working-directory }} + # The Windows engine builds only its own platform, on the Windows version of its runner. + build-windows: + name: ${{ inputs.job-name }} build (windows/amd64) + if: ${{ inputs.windows-runner != '' }} + runs-on: ${{ inputs.windows-runner }} + timeout-minutes: ${{ inputs.timeout-minutes }} + outputs: + digest: ${{ steps.build.outputs.digest }} + steps: + - name: Clone repository + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false + - name: Checkout workflow parts + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + repository: devpro/github-workflow-parts + # The caller being this repository, the actions under test are those of the commit under test. + ref: ${{ github.repository == 'devpro/github-workflow-parts' && github.sha || inputs.workflow-parts-version }} + path: workflow-parts + persist-credentials: false + - name: Login to container registry + if: ${{ inputs.push }} + shell: pwsh + env: + REGISTRY: ${{ inputs.container-registry }} + REGISTRY_USERNAME: ${{ secrets.container-registry-username }} + REGISTRY_PASSWORD: ${{ secrets.container-registry-password }} + run: | + $env:REGISTRY_PASSWORD | docker login $env:REGISTRY --username $env:REGISTRY_USERNAME --password-stdin + exit $LASTEXITCODE + - name: Build and push container image under the tag of its platform + id: build + uses: ./workflow-parts/actions/container/build-push + with: + push: ${{ inputs.push }} + image-definition: ${{ inputs.image-definition }} + image-repository: ${{ env.IMAGE_REPOSITORY }} + image-tag: ${{ inputs.image-tag }}-windows-amd64 + platforms: windows/amd64 + build-arguments: ${{ inputs.extra-build-arguments }} + working-directory: ${{ inputs.working-directory }} + # Grype rather than Trivy, which finds no package in a Windows image, where Grype reads the version of every .NET assembly and Windows binary. + - name: Scan container image with Grype + if: ${{ inputs.scan }} + uses: ./workflow-parts/actions/grype/scan + with: + image: ${{ env.IMAGE_REPOSITORY }}:${{ inputs.image-tag }}-windows-amd64 + image-path: ${{ inputs.scan-path }} + # The platforms built on runners of their own are only put under the tag here, so that the image a tag names is complete. publication: name: ${{ inputs.job-name }} - needs: [build-emulated, build-amd64, build-arm64] + needs: [build-emulated, build-amd64, build-arm64, build-windows] # One build path is skipped by design, which an implicit success() would take for a failure. - if: ${{ !cancelled() && !contains(needs.*.result, 'failure') }} + if: ${{ inputs.push && !cancelled() && !contains(needs.*.result, 'failure') }} runs-on: ${{ inputs.operating-system }} timeout-minutes: ${{ inputs.timeout-minutes }} steps: @@ -261,15 +341,19 @@ jobs: path: workflow-parts persist-credentials: false - name: Login to container registry + if: ${{ inputs.push }} env: REGISTRY: ${{ inputs.container-registry }} REGISTRY_USERNAME: ${{ secrets.container-registry-username }} REGISTRY_PASSWORD: ${{ secrets.container-registry-password }} run: echo "$REGISTRY_PASSWORD" | docker login "$REGISTRY" --username "$REGISTRY_USERNAME" --password-stdin - name: Tag the image of every platform - if: ${{ inputs.arm64-runner != '' }} + if: ${{ inputs.arm64-runner != '' || inputs.windows-runner != '' }} env: - DIGESTS: ${{ needs.build-amd64.outputs.digest }} ${{ needs.build-arm64.outputs.digest }} + # A build skipped by design gives no digest, so only the builds that ran are put together. + DIGESTS: >- + ${{ needs.build-amd64.outputs.digest }} ${{ needs.build-arm64.outputs.digest }} + ${{ inputs.windows-runner != '' && needs.build-emulated.outputs.digest || '' }} ${{ needs.build-windows.outputs.digest }} run: | sources=() for digest in $DIGESTS; do diff --git a/.github/workflows/reusable-dotnet-framework-quality.yml b/.github/workflows/reusable-dotnet-framework-quality.yml new file mode 100644 index 0000000..c0523ae --- /dev/null +++ b/.github/workflows/reusable-dotnet-framework-quality.yml @@ -0,0 +1,77 @@ +name: Reusable - .NET Framework quality + +on: + workflow_call: + inputs: + solution: + description: Solution or project file, relative to the working directory + type: string + required: true + configuration: + description: Build configuration + type: string + required: false + default: Release + test-assembly-filter: + description: File name pattern of the test assemblies, searched in the bin folders of the configuration, no test being run when empty + type: string + required: false + default: "*.Tests.dll" + job-name: + description: Job name + type: string + required: false + default: Quality + timeout-minutes: + description: Minutes the job may run before it is cancelled + type: number + required: false + default: 30 + operating-system: + description: Windows runner with Visual Studio + type: string + required: false + default: windows-2025 + workflow-parts-version: + description: GitHub workflow parts version (branch/tag/SHA). Should match the ref/tag/SHA the caller pinned for this reusable workflow itself. Ignored when the caller is this repository, whose checkout already holds the actions under test. + type: string + required: false + default: main + working-directory: + description: Working directory + type: string + required: false + default: "." + +jobs: + dotnet-framework-quality: + name: ${{ inputs.job-name }} + runs-on: ${{ inputs.operating-system }} + timeout-minutes: ${{ inputs.timeout-minutes }} + steps: + - name: Clone repository + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false + - name: Checkout workflow parts + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + repository: devpro/github-workflow-parts + # The caller being this repository, the actions under test are those of the commit under test. + ref: ${{ github.repository == 'devpro/github-workflow-parts' && github.sha || inputs.workflow-parts-version }} + path: workflow-parts + persist-credentials: false + - name: Build & test + uses: ./workflow-parts/actions/dotnet-framework/build-test + with: + solution: ${{ inputs.solution }} + configuration: ${{ inputs.configuration }} + test-assembly-filter: ${{ inputs.test-assembly-filter }} + working-directory: ${{ inputs.working-directory }} + - name: Archive test results + if: always() + uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2 + with: + name: dotnet-framework-test-results + path: ${{ inputs.working-directory }}/report/ + if-no-files-found: ignore diff --git a/.github/workflows/reusable-markup-lint.yml b/.github/workflows/reusable-markup-lint.yml index bd4fdac..3157c7f 100644 --- a/.github/workflows/reusable-markup-lint.yml +++ b/.github/workflows/reusable-markup-lint.yml @@ -38,7 +38,7 @@ jobs: with: persist-credentials: false - name: Lint Markdown files - run: npx --yes markdownlint-cli2@0.24.0 "**/*.md" + run: npx --yes markdownlint-cli2@0.24.1 "**/*.md" - name: Lint YAML files run: pipx run --spec yamllint==1.38.0 yamllint . - name: Lint shell scripts diff --git a/.github/workflows/reusable-terraform-quality.yml b/.github/workflows/reusable-terraform-quality.yml index 7e3ed85..ddce2c8 100644 --- a/.github/workflows/reusable-terraform-quality.yml +++ b/.github/workflows/reusable-terraform-quality.yml @@ -14,7 +14,7 @@ on: required: false default: 30 working-directory: - description: "Working directory" + description: "Folder searched for Terraform configurations, where a directory under a modules folder is a module and any other one a root configuration" type: string required: false default: "." @@ -23,6 +23,11 @@ on: type: string required: false default: "ubuntu-latest" + severity: + description: "Comma-separated severities the Trivy scans of the code and of the providers report" + type: string + required: false + default: "HIGH,CRITICAL" workflow-parts-version: description: "GitHub workflow parts version (branch/tag/SHA). Should match the ref/tag/SHA the caller pinned for this reusable workflow itself. Ignored when the caller is this repository, whose checkout already holds the actions under test." type: string @@ -50,24 +55,159 @@ jobs: ref: ${{ github.repository == 'devpro/github-workflow-parts' && github.sha || inputs.workflow-parts-version }} path: workflow-parts persist-credentials: false - - name: Cache Terraform plugins - uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0 - with: - path: | - ~/.terraform.d/plugin-cache - key: terraform-${{ hashFiles('**/.terraform.lock.hcl') }} + # Tracked files only, which leaves out the checkout of the workflow parts, the .terraform folders and what the repository ignores. + # A directory under a modules folder is a module, any other one a root configuration: a project, an example or a sample. + - name: Find Terraform configurations + run: | + list="${RUNNER_TEMP}/terraform-configurations.tsv" + git ls-files -z -- '*.tf' | xargs -0 -r -n 1 dirname | sort -u | while IFS= read -r dir; do + if [[ "/${dir}/" == */modules/* ]]; then + printf 'module\t%s\n' "$dir" + else + printf 'project\t%s\n' "$dir" + fi + done > "$list" + if [ ! -s "$list" ]; then + echo "::error::No tracked Terraform file under ${INPUT_WORKING_DIRECTORY}" + exit 1 + fi + cat "$list" + env: + INPUT_WORKING_DIRECTORY: ${{ inputs.working-directory }} - name: Install terraform uses: ./workflow-parts/actions/terraform/setup + # Each check runs whatever the one before it found, so a single run reports them all. - name: Check Terraform format - run: terraform fmt -recursive -check - - name: Terraform Init - run: terraform init -backend=false - - name: Terraform Validate - run: terraform validate + if: success() || failure() + run: | + failed=() + while IFS=$'\t' read -r _ dir; do + terraform fmt -check -diff "$dir" || failed+=("$dir") + done < "${RUNNER_TEMP}/terraform-configurations.tsv" + if [ ${#failed[@]} -gt 0 ]; then + printf '::error::terraform fmt found unformatted files in %s\n' "${failed[@]}" + exit 1 + fi + # A root configuration is applied with its dependency lock file, so the lock file is committed and must match its constraints. + # A module is called by others, whose lock file wins, so a lock file of its own is never used. + - name: Validate Terraform configurations + if: success() || failure() + run: | + # Every configuration shares one download of each provider. + # The folder is not kept between runs, so the provider scan sees exactly the providers of this run. + export TF_PLUGIN_CACHE_DIR="${RUNNER_TEMP}/terraform-plugin-cache" + mkdir -p "$TF_PLUGIN_CACHE_DIR" + failed=() + while IFS=$'\t' read -r kind dir; do + echo "::group::${kind} ${dir}" + init_args=(-backend=false -input=false) + lock_file_tracked=false + if git ls-files --error-unmatch -- "${dir}/.terraform.lock.hcl" > /dev/null 2>&1; then + lock_file_tracked=true + fi + if [ "$kind" = project ]; then + if [ "$lock_file_tracked" = true ]; then + init_args+=(-lockfile=readonly) + else + echo "::warning::Root configuration ${dir} has no committed .terraform.lock.hcl" + fi + elif [ "$lock_file_tracked" = true ]; then + echo "::warning::Module ${dir} commits a .terraform.lock.hcl its callers never use" + fi + if ! { terraform -chdir="$dir" init "${init_args[@]}" && terraform -chdir="$dir" validate; }; then + failed+=("$dir") + fi + echo "::endgroup::" + done < "${RUNNER_TEMP}/terraform-configurations.tsv" + if [ ${#failed[@]} -gt 0 ]; then + printf '::error::terraform validate failed in %s\n' "${failed[@]}" + exit 1 + fi + # Read from the lock file of every configuration, written by validate where none is committed, so a module pinning an old version shows too. + # A newer major version is a warning, as its upgrade changes the code; a newer minor or patch version is a notice. + - name: Check provider versions + if: success() || failure() + run: | + providers="${RUNNER_TEMP}/terraform-providers.tsv" + while IFS=$'\t' read -r _ dir; do + if [ -f "${dir}/.terraform.lock.hcl" ]; then + awk -v dir="$dir" -F '"' '/^provider "/ { source = $2 } /^ version *=/ { print source "\t" $2 "\t" dir }' "${dir}/.terraform.lock.hcl" + fi + done < "${RUNNER_TEMP}/terraform-configurations.tsv" | sort -u > "$providers" + declare -A latest + while IFS=$'\t' read -r source version dirs; do + host="${source%%/*}" + address="${source#*/}" + if [ "$host" != registry.terraform.io ]; then + echo "::notice::${source} ${version} is not checked, as only registry.terraform.io is queried" + continue + fi + if [ -z "${latest[$address]+set}" ]; then + # Stable releases only, as the latest version the registry gives may be a prerelease. + latest[$address]="$(curl -fsSL --retry 3 "https://registry.terraform.io/v1/providers/${address}/versions" \ + | jq -r '[.versions[].version | select(test("^[0-9]+\\.[0-9]+\\.[0-9]+$"))] | sort_by(split(".") | map(tonumber)) | last // empty' || true)" + fi + newest="${latest[$address]}" + if [ -z "$newest" ]; then + echo "::notice::No stable release of ${address} found on the registry" + elif [ "$version" != "$newest" ] && [ "$(printf '%s\n' "$version" "$newest" | sort -V | tail -n 1)" = "$newest" ]; then + if [ "${version%%.*}" -lt "${newest%%.*}" ]; then + echo "::warning title=Outdated provider::${address} ${version} is a major version behind ${newest}, in ${dirs}" + else + echo "::notice title=Outdated provider::${address} ${version} is behind ${newest}, in ${dirs}" + fi + fi + done < <(awk -F '\t' '{ key = $1 "\t" $2; if (key in dirs) dirs[key] = dirs[key] ", " $3; else dirs[key] = $3 } END { for (key in dirs) print key "\t" dirs[key] }' "$providers" | sort) + # A provider is a Go binary run with the credentials of the deployment, so the vulnerabilities of its Go version and modules count. + - name: Scan providers with Trivy + if: success() || failure() + uses: ./workflow-parts/actions/trivy/scan + with: + scan-type: rootfs + target: ${{ runner.temp }}/terraform-plugin-cache + format: json + output-file: ${{ runner.temp }}/terraform-providers-trivy.json + severity: ${{ inputs.severity }} + # Reported as warnings, as fixing them means upgrading a provider, often to a new major version. + - name: Report provider vulnerabilities + if: success() || failure() + run: | + report="${RUNNER_TEMP}/terraform-providers-trivy.json" + if [ ! -f "$report" ]; then + echo "::warning::No provider scan report, see the Trivy step" + exit 0 + fi + jq -r ' + .Results[]? | select((.Vulnerabilities // []) | length > 0) + | (.Target | split("/")) as $path + | (.Vulnerabilities | map(.Severity)) as $severities + | (.Vulnerabilities | map(select(.Severity == "CRITICAL") | .VulnerabilityID) | unique) as $critical + | [($path[1:3] | join("/")), $path[3], + ($severities | map(select(. == "CRITICAL")) | length), ($severities | map(select(. == "HIGH")) | length), ($severities | length), + ($critical + (.Vulnerabilities | map(.VulnerabilityID) | unique - $critical) | .[0:5] | join(", "))] + | @tsv' "$report" | sort > "${RUNNER_TEMP}/terraform-providers-vulnerabilities.tsv" + if [ ! -s "${RUNNER_TEMP}/terraform-providers-vulnerabilities.tsv" ]; then + echo "No ${SEVERITY} vulnerability in the providers" + exit 0 + fi + { + echo "### Provider vulnerabilities (${SEVERITY})" + echo + echo "| Provider | Version | Critical | High | Among them |" + echo "|---|---|---|---|---|" + } >> "$GITHUB_STEP_SUMMARY" + while IFS=$'\t' read -r address version critical high total ids; do + echo "::warning title=Vulnerable provider::${address} ${version} has ${total} vulnerabilities, ${critical} critical and ${high} high (${ids})" + echo "| ${address} | ${version} | ${critical} | ${high} | ${ids} |" >> "$GITHUB_STEP_SUMMARY" + done < "${RUNNER_TEMP}/terraform-providers-vulnerabilities.tsv" + env: + SEVERITY: ${{ inputs.severity }} # Checkov is a static code analysis tool for infrastructure as code (IaC) and also a software composition analysis (SCA) tool for images and open source packages - name: Run Checkov + if: success() || failure() run: | - pipx run --spec checkov==3.3.30 checkov -d . \ + pipx run --spec checkov==3.4.5 checkov -d . \ + --skip-path workflow-parts \ --soft-fail \ --output cli --output sarif \ --output-file-path console,results.sarif @@ -88,30 +228,107 @@ jobs: uses: ./workflow-parts/actions/tflint/setup with: # ref. https://github.com/terraform-linters/tflint/releases - tflint-version: v0.65.0 - - name: Initialize TFLint - run: tflint --init --recursive + tflint-version: v0.66.0 + # Each configuration is linted from inside it, with the nearest .tflint.hcl up to the working directory, + # so one file at the root serves every configuration and a directory can still have its own. + - name: Run TFLint + if: success() || failure() + run: | + used="${RUNNER_TEMP}/tflint-configurations.txt" + : > "$used" + failed=() + while IFS=$'\t' read -r _ dir; do + echo "::group::${dir}" + config_args=() + search="$dir" + while true; do + if [ -f "${search}/.tflint.hcl" ]; then + echo "Configuration: ${search}/.tflint.hcl" + config_args=(--config "${PWD}/${search}/.tflint.hcl") + echo "${search}/.tflint.hcl" >> "$used" + break + fi + if [ "$search" = . ]; then + echo "Configuration: TFLint defaults" + break + fi + search="$(dirname "$search")" + done + if ! { tflint --chdir="$dir" "${config_args[@]}" --init && tflint --chdir="$dir" "${config_args[@]}" --format compact; }; then + failed+=("$dir") + fi + echo "::endgroup::" + done < "${RUNNER_TEMP}/terraform-configurations.tsv" + if [ ${#failed[@]} -gt 0 ]; then + printf '::error::TFLint failed in %s\n' "${failed[@]}" + exit 1 + fi env: # ref. https://github.com/terraform-linters/tflint/blob/master/docs/user-guide/plugins.md#avoiding-rate-limiting GITHUB_TOKEN: ${{ github.token }} - - name: Run TFLint - run: tflint --recursive --format compact + # A plugin is pinned to an exact version, which TFLint requires, so nothing tells when it falls behind. + # A newer major version, or a newer minor one before 1.0, is a warning, as it may bring rules that raise new findings. + - name: Check TFLint plugin versions + if: success() || failure() + run: | + used="${RUNNER_TEMP}/tflint-configurations.txt" + if [ ! -s "$used" ]; then + exit 0 + fi + sort -u "$used" | while IFS= read -r config; do + awk -F '"' ' + /^plugin "/ { name = $2; source = ""; version = "" } + /^ source *=/ { source = $2 } + /^ version *=/ { version = $2 } + /^}/ { if (name != "" && source != "" && version != "") print name "\t" source "\t" version; name = "" } + ' "$config" | while IFS=$'\t' read -r name source version; do + repository="${source#github.com/}" + auth=() + if [ -n "$GITHUB_TOKEN" ]; then + auth=(-H "Authorization: Bearer ${GITHUB_TOKEN}") + fi + # The latest release leaves out prereleases and drafts. + newest="$(curl -fsSL --retry 3 "${auth[@]}" "https://api.github.com/repos/${repository}/releases/latest" | jq -r '.tag_name // empty' || true)" + newest="${newest#v}" + if [ -z "$newest" ]; then + echo "::notice::No release of ${source} found on GitHub" + continue + fi + if [ "$version" = "$newest" ] || [ "$(printf '%s\n' "$version" "$newest" | sort -V | tail -n 1)" != "$newest" ]; then + echo "TFLint plugin ${name} ${version} is the latest release, in ${config}" + continue + fi + IFS=. read -r major minor _ <<< "$version" + IFS=. read -r newest_major newest_minor _ <<< "$newest" + if [ "$major" != "$newest_major" ] || { [ "$major" = 0 ] && [ "$minor" != "$newest_minor" ]; }; then + echo "::warning title=Outdated TFLint plugin::${name} ${version} is a breaking release behind ${newest}, in ${config}" + else + echo "::notice title=Outdated TFLint plugin::${name} ${version} is behind ${newest}, in ${config}" + fi + done + done + env: + GITHUB_TOKEN: ${{ github.token }} + # An action step ignores the default working directory, hence the explicit target. - name: Run Trivy IaC scan + if: success() || failure() uses: ./workflow-parts/actions/trivy/scan with: scan-type: config - target: . + target: ${{ inputs.working-directory }} + skip-dirs: workflow-parts format: sarif output-file: trivy-results.sarif - severity: HIGH,CRITICAL + severity: ${{ inputs.severity }} - name: Upload SARIF as artifact uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2 if: always() with: name: security-results path: | - results.sarif + ${{ inputs.working-directory }}/results.sarif trivy-results.sarif + ${{ runner.temp }}/terraform-providers-trivy.json retention-days: 14 env: TF_IN_AUTOMATION: true diff --git a/.istarci.yml b/.istarci.yml index 6a9b5e3..3f6d6bb 100644 --- a/.istarci.yml +++ b/.istarci.yml @@ -1,12 +1,12 @@ runner: images: "test-dotnet-*": ghcr.io/devpro/ubuntu-dotnet:latest - test-npm-publish: ghcr.io/devpro/debian-node:latest - test-playwright-install: ghcr.io/devpro/debian-node-playwright:latest - test-node-quality-npm: ghcr.io/devpro/debian-node-playwright:latest - test-node-quality-pnpm: ghcr.io/devpro/debian-node:latest - test-node-quality-sonar: ghcr.io/devpro/debian-node-playwright:latest - test-npm-publication: ghcr.io/devpro/debian-node:latest + test-npm-publish: ghcr.io/devpro/ubuntu-node:latest + test-playwright-install: ghcr.io/devpro/ubuntu-node-playwright:latest + test-node-quality-npm: ghcr.io/devpro/ubuntu-node-playwright:latest + test-node-quality-pnpm: ghcr.io/devpro/ubuntu-node:latest + test-node-quality-sonar: ghcr.io/devpro/ubuntu-node-playwright:latest + test-npm-publication: ghcr.io/devpro/ubuntu-node:latest test-go-lint-govulncheck-scan: registry.suse.com/bci/golang:1.27 docker: ["test-container-scan-on-base*", "test-cosign-sign*", "test-container-build-push*"] sonarqube: true diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index e45afeb..fe83310 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -15,3 +15,8 @@ IstarCI runs them on an arm64 machine, emulated on an amd64 one with a `qemu-aar `test/run_static_checks.sh` runs actionlint, shellcheck on the scripts of the composite actions, and the conventions of `test/check_workflow_parts.py`. A part no CI job can exercise is listed in `UNTESTED_PARTS` of that file, with the reason. + +## Check for updates + +`scripts/check_updates.sh` lists the pinned GitHub Actions, tools, Python and npm packages and locked Terraform providers that have a newer stable release upstream. +A new version input needs its source in `SOURCES` of that script, which reports it as unknown otherwise. diff --git a/README.md b/README.md index 532f31f..7f7257b 100644 --- a/README.md +++ b/README.md @@ -21,6 +21,7 @@ Containers: .NET: - [Ensure the quality of the code](.github/workflows/reusable-dotnet-quality.yml) +- [Ensure the quality of .NET Framework code on Windows](.github/workflows/reusable-dotnet-framework-quality.yml) Git: @@ -56,8 +57,9 @@ Terraform: Containers: -- [Build and push an image for one or more platforms](actions/container/build-push/action.yml) +- [Build and push an image for one or more Linux platforms, or for Windows](actions/container/build-push/action.yml) - [Sign an image with Cosign](actions/cosign/sign/action.yml) +- [Scan a Windows image with Grype](actions/grype/scan/action.yml) - [Setup QEMU to build images for other platforms](actions/qemu/setup/action.yml) - [Scan an image or a directory with Trivy](actions/trivy/scan/action.yml) - [Setup Trivy](actions/trivy/setup/action.yml) @@ -66,6 +68,7 @@ Containers: - [Build, test the code and analyze it with Sonar](actions/dotnet/build-test-sonar/action.yml) - [Build and test the code](actions/dotnet/build-test/action.yml) +- [Build and test .NET Framework code on Windows](actions/dotnet-framework/build-test/action.yml) - [Install the SDK, lint the code and restore NuGet packages](actions/dotnet/install-lint-restore/action.yml) - [Package the projects and push them to a NuGet registry](actions/dotnet/pack-push/action.yml) diff --git a/actions/container/build-push/action.yml b/actions/container/build-push/action.yml index ce0772a..e8d68ec 100644 --- a/actions/container/build-push/action.yml +++ b/actions/container/build-push/action.yml @@ -3,7 +3,9 @@ description: | Builds a container image with the BuildKit of the Docker daemon for one or more platforms and pushes it under a tag, each platform of several being pushed under a tag of its own first, then put together under the tag. The registry login is left to the job, which holds the credentials. - Linux runners only (for example ubuntu-latest or ubuntu-24.04-arm). + With push false, the image is only built and left in the daemon, so a pipeline checks the packaging without publishing it. + Linux runners (for example ubuntu-latest or ubuntu-24.04-arm) build Linux platforms, + a Windows runner (for example windows-2025) builds windows/amd64 alone, for the Windows version of the runner. inputs: image-definition: @@ -16,13 +18,17 @@ inputs: description: Tag to push, the tag of each platform of several being this one followed by the platform (1.0.1-linux-arm64 for instance) required: true platforms: - description: Comma-separated platforms to build (a platform other than the runner's own needs the Setup QEMU action first) + description: Comma-separated platforms to build (a platform other than the runner's own needs the Setup QEMU action first), or windows/amd64 alone on a Windows runner required: false default: "linux/amd64" build-arguments: description: Build arguments, one KEY=value per line required: false default: "" + push: + description: Push the image, which is otherwise built only and left in the daemon, with no digest + required: false + default: "true" working-directory: description: Directory the build runs from, relative to the workspace, which a composite action does not take from the defaults of the calling job required: false @@ -30,8 +36,8 @@ inputs: outputs: digest: - description: Digest of the pushed image, a manifest list when several platforms were built - value: ${{ steps.build.outputs.digest }} + description: Digest of the pushed image, a manifest list when several platforms were built, empty when not pushed + value: ${{ steps.build.outputs.digest || steps.build-windows.outputs.digest }} runs: using: "composite" @@ -41,6 +47,7 @@ runs: # It pushes no image by digest alone and builds one platform at a time on the classic image store, so each platform gets a tag. - name: Build and push container image id: build + if: ${{ inputs.platforms != 'windows/amd64' }} shell: bash working-directory: ${{ inputs.working-directory }} env: @@ -49,6 +56,7 @@ runs: IMAGE_TAG: ${{ inputs.image-tag }} PLATFORMS: ${{ inputs.platforms }} BUILD_ARGUMENTS: ${{ inputs.build-arguments }} + PUSH: ${{ inputs.push }} run: | build_args=() while IFS= read -r argument; do @@ -58,6 +66,11 @@ runs: # Builds and pushes one platform under a tag, and prints the digest of what was pushed. build_push() { local platform="$1" ref="$2" metadata digest + if [[ "$PUSH" != true ]]; then + docker buildx build --builder default --file "$IMAGE_DEFINITION" --platform "$platform" \ + --tag "$ref" "${build_args[@]}" . >&2 + return 0 + fi metadata="$(mktemp)" docker buildx build --builder default --file "$IMAGE_DEFINITION" --platform "$platform" \ --tag "$ref" --push --metadata-file "$metadata" "${build_args[@]}" . >&2 @@ -72,6 +85,15 @@ runs: } IFS=',' read -ra platform_list <<< "$PLATFORMS" + if [[ "$PUSH" != true ]]; then + for platform in "${platform_list[@]}"; do + ref="${IMAGE_REPOSITORY}:${IMAGE_TAG}" + [ "${#platform_list[@]}" -gt 1 ] && ref="${ref}-${platform//\//-}" + build_push "$platform" "$ref" + echo "Built ${ref}, not pushed" + done + exit 0 + fi if [ "${#platform_list[@]}" -eq 1 ]; then digest="$(build_push "${platform_list[0]}" "${IMAGE_REPOSITORY}:${IMAGE_TAG}")" else @@ -86,3 +108,43 @@ runs: fi echo "Pushed ${IMAGE_REPOSITORY}:${IMAGE_TAG}@${digest}" echo "digest=$digest" >> "$GITHUB_OUTPUT" + # The Windows engine has no BuildKit, so the classic builder builds the image, for the platform of the engine only. + - name: Build and push Windows container image + id: build-windows + if: ${{ inputs.platforms == 'windows/amd64' }} + shell: pwsh + working-directory: ${{ inputs.working-directory }} + env: + DOCKER_BUILDKIT: "0" + IMAGE_DEFINITION: ${{ inputs.image-definition }} + IMAGE_REPOSITORY: ${{ inputs.image-repository }} + IMAGE_TAG: ${{ inputs.image-tag }} + BUILD_ARGUMENTS: ${{ inputs.build-arguments }} + PUSH: ${{ inputs.push }} + run: | + $ref = "${env:IMAGE_REPOSITORY}:${env:IMAGE_TAG}" + $buildArgs = @('build', '--file', $env:IMAGE_DEFINITION, '--tag', $ref) + foreach ($argument in ($env:BUILD_ARGUMENTS -split "`r?`n")) { + if ($argument) { $buildArgs += @('--build-arg', $argument) } + } + & docker @buildArgs . + if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE } + if ($env:PUSH -ne 'true') { + Write-Output "Built $ref, not pushed" + exit 0 + } + docker push $ref + if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE } + # Docker Hub names its repositories without the registry, and an image built here holds only the digest of its push. + $repoDigest = docker image inspect $ref --format '{{range .RepoDigests}}{{println .}}{{end}}' | + Where-Object { $_ } | Select-Object -First 1 + # The daemon keeps the image it built, which the registry now holds. + docker image rm $ref *> $null + $digest = ($repoDigest -split '@')[-1] + if ($digest -notlike 'sha256:*') { + Write-Error "The push reported no digest for $ref" + exit 1 + } + Write-Output "Pushed ${ref}@${digest}" + "digest=$digest" >> $env:GITHUB_OUTPUT + exit 0 diff --git a/actions/dotnet-framework/build-test/action.yml b/actions/dotnet-framework/build-test/action.yml new file mode 100644 index 0000000..290156c --- /dev/null +++ b/actions/dotnet-framework/build-test/action.yml @@ -0,0 +1,76 @@ +name: Build and test .NET Framework code +description: | + Restores, builds and tests a .NET Framework solution with the MSBuild and the VSTest of Visual Studio, found with vswhere. + Packages listed in packages.config files are restored by MSBuild, so neither nuget.exe nor a setup action is needed. + The test results are written in the report folder of the working directory. + Windows runners only (for example windows-2025). + +inputs: + solution: + description: Solution or project file, relative to the working directory + required: true + configuration: + description: Build configuration + required: false + default: Release + test-assembly-filter: + description: File name pattern of the test assemblies, searched in the bin folders of the configuration, no test being run when empty + required: false + default: "*.Tests.dll" + working-directory: + description: Directory of the code, relative to the workspace, which a composite action does not take from the defaults of the calling job + required: false + default: "." + +runs: + using: "composite" + steps: + # Visual Studio is installed on the runner but not on the PATH, and vswhere is the way Microsoft documents to find it. + - name: Find MSBuild and VSTest + shell: pwsh + run: | + $vswhere = Join-Path ${env:ProgramFiles(x86)} 'Microsoft Visual Studio\Installer\vswhere.exe' + $msbuild = & $vswhere -latest -products * -requires Microsoft.Component.MSBuild -find 'MSBuild\**\Bin\MSBuild.exe' | Select-Object -First 1 + $vstest = & $vswhere -latest -products * -find '**\TestWindow\vstest.console.exe' | Select-Object -First 1 + if (-not $msbuild) { + Write-Error 'No MSBuild found by vswhere' + exit 1 + } + Write-Output "MSBuild: $msbuild" + Write-Output "VSTest: $vstest" + "MSBUILD_PATH=$msbuild" >> $env:GITHUB_ENV + "VSTEST_PATH=$vstest" >> $env:GITHUB_ENV + # RestorePackagesConfig lets the restore target read packages.config files, which it otherwise leaves to nuget.exe. + - name: Restore and build + shell: pwsh + working-directory: ${{ inputs.working-directory }} + env: + SOLUTION: ${{ inputs.solution }} + CONFIGURATION: ${{ inputs.configuration }} + run: | + & $env:MSBUILD_PATH $env:SOLUTION -restore -p:RestorePackagesConfig=true "-p:Configuration=$env:CONFIGURATION" -maxCpuCount -nologo + exit $LASTEXITCODE + - name: Test + if: ${{ inputs.test-assembly-filter != '' }} + shell: pwsh + working-directory: ${{ inputs.working-directory }} + env: + CONFIGURATION: ${{ inputs.configuration }} + TEST_ASSEMBLY_FILTER: ${{ inputs.test-assembly-filter }} + run: | + # Only the assembly a project builds in its own bin folder is kept, as copies in obj or beside a referencing project would run the same tests twice. + $output = "^(?.+)\\bin\\$([regex]::Escape($env:CONFIGURATION))(\\[^\\]+)?$" + $assemblies = @(Get-ChildItem -Path . -Recurse -File -Filter $env:TEST_ASSEMBLY_FILTER | + Where-Object { $_.Directory.FullName -match $output -and (Test-Path (Join-Path $Matches.project "$($_.BaseName).csproj")) } | + ForEach-Object { $_.FullName }) + if ($assemblies.Count -eq 0) { + Write-Error "No test assembly matching $env:TEST_ASSEMBLY_FILTER in a bin\$env:CONFIGURATION folder" + exit 1 + } + if (-not $env:VSTEST_PATH) { + Write-Error 'No VSTest found by vswhere' + exit 1 + } + $results = Join-Path (Get-Location) 'report\TestResults' + & $env:VSTEST_PATH @assemblies /Logger:trx "/ResultsDirectory:$results" + exit $LASTEXITCODE diff --git a/actions/dotnet/build-test-sonar/action.yml b/actions/dotnet/build-test-sonar/action.yml index 07b7436..deda606 100644 --- a/actions/dotnet/build-test-sonar/action.yml +++ b/actions/dotnet/build-test-sonar/action.yml @@ -45,7 +45,7 @@ inputs: sonarscanner-version: description: Version of the Sonar scanner for .NET (check latest from https://www.nuget.org/packages/dotnet-sonarscanner) required: false - default: "12.0.0" + default: "12.1.0" sonar-token: description: Sonar token for login required: false @@ -59,7 +59,7 @@ runs: using: "composite" steps: - name: Set up JDK for Sonar - uses: actions/setup-java@77dd5b2ce225ea11469928ac317850245a74ae78 # v6.2.0 + uses: actions/setup-java@d1374f8ac74474200d16ef8ecee22c7ae7a51880 # v6.3.0 with: java-version: ${{ inputs.java-version }} distribution: "zulu" diff --git a/actions/dotnet/install-lint-restore/action.yml b/actions/dotnet/install-lint-restore/action.yml index bc936c8..e0bd6fb 100644 --- a/actions/dotnet/install-lint-restore/action.yml +++ b/actions/dotnet/install-lint-restore/action.yml @@ -9,7 +9,7 @@ inputs: reportgenerator-version: description: Version of ReportGenerator (check latest from https://www.nuget.org/packages/dotnet-reportgenerator-globaltool) required: false - default: "5.5.12" + default: "5.6.0" working-directory: description: Directory of the .NET code, relative to the workspace, which a composite action does not take from the defaults of the calling job required: false diff --git a/actions/goreleaser/setup/action.yml b/actions/goreleaser/setup/action.yml index ffa04ee..79574d6 100644 --- a/actions/goreleaser/setup/action.yml +++ b/actions/goreleaser/setup/action.yml @@ -8,7 +8,7 @@ inputs: goreleaser-version: description: Version of GoReleaser to install (check latest from https://github.com/goreleaser/goreleaser/releases) required: false - default: "2.20.0" + default: "2.20.2" runs: using: "composite" diff --git a/actions/grype/scan/action.yml b/actions/grype/scan/action.yml new file mode 100644 index 0000000..8a75ca5 --- /dev/null +++ b/actions/grype/scan/action.yml @@ -0,0 +1,104 @@ +name: Scan with Grype +description: | + Installs Grype by downloading the official binary from its GitHub release and verifying its SHA256 checksum, + then scans a container image of the local Docker engine for vulnerabilities (replacement for anchore/scan-action, + to reduce third-party GitHub Action supply-chain risk). + Windows x64 runners only (for example windows-2025), where Grype reads the version of every .NET assembly and Windows binary of an image in which Trivy finds no package. + +inputs: + grype-version: + description: Version of Grype to install (check latest from https://github.com/anchore/grype/releases) + required: false + default: "0.121.3" + image: + description: Reference of the image to scan, in the local Docker engine + required: true + image-path: + description: Folder of the image to scan alone (for example C:\app), the whole image when empty + required: false + default: "" + fail-on: + description: Lowest severity that fails the scan (negligible, low, medium, high, critical), none when empty + required: false + default: "critical" + +runs: + using: "composite" + steps: + - name: Install Grype + shell: pwsh + env: + GRYPE_VERSION: ${{ inputs.grype-version }} + run: | + $ErrorActionPreference = 'Stop' + # A progress bar redrawn in a CI log only adds lines, and slows the download down. + $ProgressPreference = 'SilentlyContinue' + # Downloaded into a directory of its own, since the repository may hold a file or a directory named like the binary. + $directory = New-Item -ItemType Directory -Path (Join-Path $env:RUNNER_TEMP "grype-$([guid]::NewGuid())") + $archive = "grype_${env:GRYPE_VERSION}_windows_amd64.zip" + $checksums = "grype_${env:GRYPE_VERSION}_checksums.txt" + $baseUrl = "https://github.com/anchore/grype/releases/download/v${env:GRYPE_VERSION}" + + Write-Output "Downloading Grype binary and checksums..." + Invoke-WebRequest -Uri "$baseUrl/$archive" -OutFile (Join-Path $directory $archive) + Invoke-WebRequest -Uri "$baseUrl/$checksums" -OutFile (Join-Path $directory $checksums) + + Write-Output "Verifying checksum..." + $line = Get-Content (Join-Path $directory $checksums) | Where-Object { $_ -match " $([regex]::Escape($archive))$" } + $expected = if ($line) { ($line -split '\s+')[0] } else { '' } + $actual = (Get-FileHash -Path (Join-Path $directory $archive) -Algorithm SHA256).Hash + if (-not $expected -or $expected -ne $actual) { + Write-Error "Checksum verification failed!" + exit 1 + } + Write-Output "Verification successful!" + + Expand-Archive -Path (Join-Path $directory $archive) -DestinationPath $directory + # Installed where the job owns the directory, so no administrator right is needed, on a hosted runner or in a container. + $bin = Join-Path $env:RUNNER_TEMP 'bin' + New-Item -ItemType Directory -Path $bin -Force | Out-Null + Move-Item -Path (Join-Path $directory 'grype.exe') -Destination $bin -Force + Remove-Item -Path $directory -Recurse -Force + Add-Content -Path $env:GITHUB_PATH -Value $bin + & (Join-Path $bin 'grype.exe') version + exit $LASTEXITCODE + - name: Scan container image with Grype + shell: pwsh + env: + IMAGE: ${{ inputs.image }} + IMAGE_PATH: ${{ inputs.image-path }} + FAIL_ON: ${{ inputs.fail-on }} + run: | + $copy = Join-Path $env:RUNNER_TEMP "grype-$([guid]::NewGuid())" + $nameArgs = @() + if ($env:IMAGE_PATH) { + # A folder is copied out of a container never started, in seconds, where saving a Windows image takes minutes for its gigabytes of base layers. + $container = docker create $env:IMAGE + if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE } + docker cp "${container}:$env:IMAGE_PATH" $copy + $code = $LASTEXITCODE + docker rm $container | Out-Null + if ($code -ne 0) { exit $code } + $target = "dir:$copy" + # A folder has no name of its own, so the findings are named after the image. + $nameArgs = @('--name', $env:IMAGE) + } else { + # The image is read from an archive, so the scan needs no access of its own to the engine. + $copy = "$copy.tar" + docker save --output $copy $env:IMAGE + if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE } + $target = "docker-archive:$copy" + } + + # Every finding is printed, and only those at or above the severity given fail the scan. + $grypeArgs = @($target, '--output', 'table') + $nameArgs + if ($env:FAIL_ON) { + $grypeArgs += @('--fail-on', $env:FAIL_ON) + } + Write-Output "Running: grype $($grypeArgs -join ' ')" + grype @grypeArgs + $code = $LASTEXITCODE + # A Windows image archive takes gigabytes, which a runner keeping its disk between jobs would pile up. + # The copy goes too, so the scan of another image never reads it. + Remove-Item -Path $copy -Recurse -Force + exit $code diff --git a/actions/helm/setup/action.yml b/actions/helm/setup/action.yml index f128769..c76be24 100644 --- a/actions/helm/setup/action.yml +++ b/actions/helm/setup/action.yml @@ -8,7 +8,7 @@ inputs: helm-version: description: Version of Helm to install (check latest from https://github.com/helm/helm/releases) required: false - default: "v4.3.1" + default: "v4.3.2" runs: using: "composite" diff --git a/actions/mongodb/start/action.yml b/actions/mongodb/start/action.yml index dfd9439..8eaba24 100644 --- a/actions/mongodb/start/action.yml +++ b/actions/mongodb/start/action.yml @@ -7,21 +7,21 @@ description: | inputs: mongodb-version: - description: Version of the MongoDB server, an 8.0 one for instance, the latest release (9.0.4) when empty (check latest from https://www.mongodb.com/try/download/community) + description: Version of the MongoDB server, an 8.0 one for instance, the latest release (9.0.8) when empty (check latest from https://www.mongodb.com/try/download/community) required: false default: "" mongosh-version: description: Version of mongosh (check latest from https://github.com/mongodb-js/mongosh/releases) required: false - default: "2.14.1" + default: "2.14.2" mongosh-sha256: description: SHA256 of the mongosh archive for x64, given with any other mongosh-version, since its release publishes no checksum file required: false - default: "8d24940ebe3675959b518fd41ea16b4e2182d6a75c09777db09cfa64e18834a1" # 2.14.1 + default: "1523e16da7c6902333b681bf65d83bbef59bff558c46ac5636371d13beb4de53" # 2.14.2 mongosh-sha256-arm64: description: SHA256 of the mongosh archive for arm64, given with any other mongosh-version required: false - default: "cd7f1ae986baa400b021a2c0688aa3b64d6afcc3f7ab07833417a049e0cbf98b" # 2.14.1 + default: "20f89386f74c14cb63a163eea5491dc14759bcd64229b1c099c2390585a01fd3" # 2.14.2 port: description: Port the server listens on required: false @@ -38,7 +38,7 @@ runs: shell: bash env: # The one place naming the default version, which the workflows calling this action leave empty. - MONGODB_ARCHIVE: mongodb-linux-${{ runner.arch == 'ARM64' && 'aarch64' || 'x86_64' }}-ubuntu2404-${{ inputs.mongodb-version || '9.0.4' }}.tgz + MONGODB_ARCHIVE: mongodb-linux-${{ runner.arch == 'ARM64' && 'aarch64' || 'x86_64' }}-ubuntu2404-${{ inputs.mongodb-version || '9.0.8' }}.tgz MONGOSH_VERSION: ${{ inputs.mongosh-version }} MONGOSH_ARCHIVE: mongosh-${{ inputs.mongosh-version }}-linux-${{ runner.arch == 'ARM64' && 'arm64' || 'x64' }}.tgz MONGOSH_SHA256: ${{ runner.arch == 'ARM64' && inputs.mongosh-sha256-arm64 || inputs.mongosh-sha256 }} diff --git a/actions/sonar/scan/action.yml b/actions/sonar/scan/action.yml index 2631402..817ef1e 100644 --- a/actions/sonar/scan/action.yml +++ b/actions/sonar/scan/action.yml @@ -9,15 +9,15 @@ inputs: scanner-version: description: Version of the Sonar scanner CLI (check latest from https://github.com/SonarSource/sonar-scanner-cli/releases) required: false - default: "8.3.1.16491" + default: "8.4.0.16527" scanner-sha256: description: SHA256 of the scanner archive for x64, given with any other scanner-version required: false - default: "0f304e4c5982f0cfbd06762306d6e60e6ed9c8e3853629ae3b8ec2f4dc9bdc04" # 8.3.1.16491 + default: "2a28f118e2e9375dfd36eb27b803e1d37f93daba4db068aca6eef9853041bb24" # 8.4.0.16527 scanner-sha256-arm64: description: SHA256 of the scanner archive for arm64, given with any other scanner-version required: false - default: "aca51f414a581b8f088207e089f281b1b2985fb202160e8ca2e135a305639d26" # 8.3.1.16491 + default: "9a64ae895ea0a9d5fc1a7e4df148e60f174a4368a7f502fe709a50537f65b11c" # 8.4.0.16527 coverage-paths: description: lcov reports of the coverage, relative to the working directory, separated by commas, coverage/lcov.info when empty and the project has no sonar-project.properties required: false diff --git a/actions/syft/generate-sbom/action.yml b/actions/syft/generate-sbom/action.yml index 7715bec..a836d38 100644 --- a/actions/syft/generate-sbom/action.yml +++ b/actions/syft/generate-sbom/action.yml @@ -3,13 +3,13 @@ description: | Installs Syft by downloading the official binary from its GitHub release, verifying its SHA256 checksum, and uses it to generate a Software Bill of Materials for a container image or a source directory (replacement for anchore/sbom-action, to reduce third-party GitHub Action supply-chain risk). - Linux x64 or arm64 runners only (for example ubuntu-latest or ubuntu-24.04-arm). + Linux x64 or arm64 runners (for example ubuntu-latest or ubuntu-24.04-arm), or Windows x64 runners (for example windows-2025). inputs: syft-version: description: Version of Syft to install (check latest from https://github.com/anchore/syft/releases) required: false - default: "1.56.0" + default: "1.57.1" target-image: description: Container image reference to scan (mutually exclusive with target-path) required: false @@ -46,7 +46,7 @@ runs: shell: bash env: SYFT_VERSION: ${{ inputs.syft-version }} - SYFT_TARBALL: syft_${{ inputs.syft-version }}_linux_${{ runner.arch == 'ARM64' && 'arm64' || 'amd64' }}.tar.gz + SYFT_ARCHIVE: syft_${{ inputs.syft-version }}_${{ runner.os == 'Windows' && 'windows_amd64.zip' || format('linux_{0}.tar.gz', runner.arch == 'ARM64' && 'arm64' || 'amd64') }} SYFT_CHECKSUMS: syft_${{ inputs.syft-version }}_checksums.txt run: | # Downloaded into a directory of its own, since the repository may hold a file or a directory named like the binary. @@ -54,20 +54,28 @@ runs: BASE_URL="https://github.com/anchore/syft/releases/download/v${SYFT_VERSION}" echo "Downloading Syft binary and checksums..." - curl -fsSL -O "${BASE_URL}/${SYFT_TARBALL}" + curl -fsSL -O "${BASE_URL}/${SYFT_ARCHIVE}" curl -fsSL -O "${BASE_URL}/${SYFT_CHECKSUMS}" echo "Verifying checksum..." - if grep " ${SYFT_TARBALL}$" "${SYFT_CHECKSUMS}" | sha256sum --check --status; then + if grep " ${SYFT_ARCHIVE}$" "${SYFT_CHECKSUMS}" | sha256sum --check --status; then echo "Verification successful!" - tar -xzf "${SYFT_TARBALL}" syft - chmod +x syft # Installed where the job owns the directory, so neither root nor sudo is needed, on a hosted runner or in a container. mkdir -p "${RUNNER_TEMP}/bin" - mv syft "${RUNNER_TEMP}/bin/syft" + if [ "$RUNNER_OS" = Windows ]; then + unzip -q "${SYFT_ARCHIVE}" syft.exe + mv syft.exe "${RUNNER_TEMP}/bin/syft.exe" + # The drive colon of a Windows path would split the PATH of bash. + PATH="$(cygpath -u "${RUNNER_TEMP}/bin"):$PATH" + export PATH + else + tar -xzf "${SYFT_ARCHIVE}" syft + chmod +x syft + mv syft "${RUNNER_TEMP}/bin/syft" + export PATH="${RUNNER_TEMP}/bin:$PATH" + fi echo "${RUNNER_TEMP}/bin" >> "$GITHUB_PATH" - export PATH="${RUNNER_TEMP}/bin:$PATH" - rm -f "${SYFT_TARBALL}" "${SYFT_CHECKSUMS}" + rm -f "${SYFT_ARCHIVE}" "${SYFT_CHECKSUMS}" syft version else echo "ERROR: Checksum verification failed!" >&2 diff --git a/actions/terraform/setup/action.yml b/actions/terraform/setup/action.yml index 1a0a5b0..3fb6f56 100644 --- a/actions/terraform/setup/action.yml +++ b/actions/terraform/setup/action.yml @@ -8,7 +8,7 @@ inputs: terraform-version: description: Version of Terraform to install (check latest from https://releases.hashicorp.com/terraform/) required: false - default: "1.17.1" + default: "1.17.2" runs: using: "composite" diff --git a/actions/tflint/setup/action.yml b/actions/tflint/setup/action.yml index bf2d218..f4c2784 100644 --- a/actions/tflint/setup/action.yml +++ b/actions/tflint/setup/action.yml @@ -8,7 +8,7 @@ inputs: tflint-version: description: Version of TFLint to install (check latest from https://github.com/terraform-linters/tflint/releases) required: false - default: "v0.65.0" + default: "v0.66.0" runs: using: "composite" diff --git a/actions/trivy/scan/action.yml b/actions/trivy/scan/action.yml index 5a36c52..72dcc12 100644 --- a/actions/trivy/scan/action.yml +++ b/actions/trivy/scan/action.yml @@ -9,13 +9,13 @@ inputs: trivy-version: description: Version of Trivy to install (check latest from https://github.com/aquasecurity/trivy/releases) required: false - default: "0.76.1" + default: "0.76.2" scan-type: - description: What to scan, "image" (container image reference) or "config" (misconfiguration/IaC scan of a directory) + description: What to scan, "image" (container image reference), "rootfs" (vulnerabilities of the binaries and packages of a directory) or "config" (misconfiguration/IaC scan of a directory) required: false default: "image" target: - description: Container image reference (scan-type "image") or directory path (scan-type "config") to scan + description: Container image reference (scan-type "image") or directory path (scan-type "rootfs" or "config") to scan required: true format: description: Trivy report format (table, json, sarif, cyclonedx, spdx-json...) @@ -34,13 +34,17 @@ inputs: required: false default: "0" ignore-unfixed: - description: Only report vulnerabilities with a fix available (scan-type "image" only) + description: Only report vulnerabilities with a fix available (scan-type "image" or "rootfs" only) required: false default: "false" pkg-types: - description: Comma-separated package types to scan, os and/or library (scan-type "image" only) + description: Comma-separated package types to scan, os and/or library (scan-type "image" or "rootfs" only) required: false default: "os,library" + skip-dirs: + description: Comma-separated directories or glob patterns left out, relative to the target, none when empty + required: false + default: "" ignore-file: description: Trivy ignore file (.trivyignore.yaml) naming the findings left out, each with the reason and the day it counts again (expired_at), none when empty required: false @@ -92,6 +96,7 @@ runs: IGNORE_UNFIXED: ${{ inputs.ignore-unfixed }} PKG_TYPES: ${{ inputs.pkg-types }} IGNORE_FILE: ${{ inputs.ignore-file }} + SKIP_DIRS: ${{ inputs.skip-dirs }} run: | args=("$SCAN_TYPE" --format "$FORMAT" --severity "$SEVERITY" --exit-code "$EXIT_CODE") @@ -104,12 +109,21 @@ runs: args+=(--ignorefile "$IGNORE_FILE") fi + if [ -n "$SKIP_DIRS" ]; then + args+=(--skip-dirs "$SKIP_DIRS") + fi + if [ -n "$OUTPUT_FILE" ]; then args+=(--output "$OUTPUT_FILE") fi - # no-progress, ignore-unfixed and pkg-types only exist for vulnerability (image) scans - if [ "$SCAN_TYPE" = "image" ]; then + # A directory is scanned for vulnerabilities only, as secrets are matched in the bytes of every binary it holds. + if [ "$SCAN_TYPE" = "rootfs" ]; then + args+=(--scanners vuln) + fi + + # no-progress, ignore-unfixed and pkg-types only exist for vulnerability scans + if [ "$SCAN_TYPE" = "image" ] || [ "$SCAN_TYPE" = "rootfs" ]; then # A CI log is not a terminal, and every redraw of the database download bar becomes log text. args+=(--no-progress) if [ "$IGNORE_UNFIXED" = "true" ]; then diff --git a/actions/trivy/setup/action.yml b/actions/trivy/setup/action.yml index 64fac75..d0ba754 100644 --- a/actions/trivy/setup/action.yml +++ b/actions/trivy/setup/action.yml @@ -8,7 +8,7 @@ inputs: trivy-version: description: Version of Trivy to install (check latest from https://github.com/aquasecurity/trivy/releases) required: false - default: "0.76.1" + default: "0.76.2" runs: using: "composite" diff --git a/scripts/check_updates.sh b/scripts/check_updates.sh new file mode 100755 index 0000000..6e94264 --- /dev/null +++ b/scripts/check_updates.sh @@ -0,0 +1,149 @@ +#!/usr/bin/env bash +# Lists the pinned versions of the catalog that have a newer upstream release. +# The current versions are read from the repository, so the script stays right after every bump, +# and only where to look for a release is kept here. +# Exits with 1 when an update is available or a source is unknown. +set -euo pipefail + +cd "$(dirname "$0")/.." + +# Where each version input finds its latest release. +# A GitHub source is owner/repo, followed by the prefix of its tags when they have one. +# "skip" marks a channel chosen on purpose, such as an LTS major version. +declare -A SOURCES=( + [chart-releaser-version]="github helm/chart-releaser" + [chart-testing-version]="github helm/chart-testing" + [codeql-version]="github github/codeql-action codeql-bundle-" + [cosign-version]="github sigstore/cosign" + [dotnet-version]="skip" + [fossa-version]="github fossas/fossa-cli" + [goreleaser-version]="github goreleaser/goreleaser" + [govulncheck-version]="github golang/vuln" + [grype-version]="github anchore/grype" + [helm-repo-html-version]="github halkeye/helm-repo-html" + [helm-unittest-version]="github helm-unittest/helm-unittest" + [helm-version]="github helm/helm" + [java-version]="skip" + [kind-version]="github kubernetes-sigs/kind" + [kube-linter-version]="github stackrox/kube-linter" + [kubeconform-version]="github yannh/kubeconform" + [kubectl-version]="kubectl" + [mongodb-server-version]="mongodb" + [mongosh-version]="github mongodb-js/mongosh" + [opengrep-version]="github opengrep/opengrep" + [reportgenerator-version]="nuget dotnet-reportgenerator-globaltool" + [scanner-version]="github SonarSource/sonar-scanner-cli" + [shellcheck-version]="github koalaman/shellcheck" + [sonarscanner-version]="nuget dotnet-sonarscanner" + [syft-version]="github anchore/syft" + [task-version]="github go-task/task" + [terraform-version]="github hashicorp/terraform" + [tflint-version]="github terraform-linters/tflint" + [trivy-version]="github aquasecurity/trivy" + [yamale-version]="pypi yamale" + [yamllint-version]="pypi yamllint" + [actionlint-version]="github rhysd/actionlint" +) + +# Pre-releases are left out, since a default is only ever moved to a stable release. +latest_github() { + local repo=$1 prefix=${2:-} + git ls-remote --tags --refs "https://github.com/${repo}" | sed 's#.*refs/tags/##' \ + | grep -E "^${prefix}v?[0-9]+(\.[0-9]+)*$" | sed "s#^${prefix}##" | sort -V | tail -1 +} + +latest() { + local kind=$1; shift + case "$kind" in + github) latest_github "$@" ;; + nuget) curl -fsSL "https://api.nuget.org/v3-flatcontainer/$1/index.json" | jq -r '[.versions[] | select(test("-") | not)] | last' ;; + npm) curl -fsSL "https://registry.npmjs.org/$1/latest" | jq -r .version ;; + pypi) curl -fsSL "https://pypi.org/pypi/$1/json" | jq -r .info.version ;; + kubectl) curl -fsSL https://dl.k8s.io/release/stable.txt ;; + terraform) curl -fsSL "https://registry.terraform.io/v1/providers/$1/versions" | jq -r '[.versions[].version | select(test("^[0-9]+\\.[0-9]+\\.[0-9]+$"))] | sort_by(split(".") | map(tonumber)) | last' ;; + mongodb) curl -fsSL https://downloads.mongodb.org/full.json | jq -r '[.versions[] | select(.production_release) | .version] | first' ;; + esac +} + +status=0 + +# Compares without the leading v, which some pins keep and some tags lack. +report() { + local name=$1 current=$2 found=$3 where=$4 + if [[ -z "$found" ]]; then + printf '%-28s %-16s %-16s %s\n' "$name" "$current" "NOT FOUND" "$where" + status=1 + elif [[ "${current#v}" != "${found#v}" && "$(printf '%s\n%s\n' "${current#v}" "${found#v}" | sort -V | tail -1)" == "${found#v}" ]]; then + printf '%-28s %-16s %-16s %s\n' "$name" "$current" "$found" "$where" + status=1 + fi +} + +# Each row: name, current version, file. +pins() { + # Version inputs of the composite actions, with a non-empty default. + for file in actions/*/*/action.yml actions/*/*/*/action.yml; do + [[ -f "$file" ]] || continue + awk -v f="$file" ' + /^ [a-z0-9-]+-version:$/ { name = substr($1, 1, length($1) - 1); next } + /^ [a-z0-9-]+:/ { name = "" } + name && /^ default:/ { gsub(/["'\'']/, "", $2); if ($2 != "") print name, $2, f; name = "" } + ' "$file" + done + # The MongoDB server version sits in an expression, so that workflows can pass an empty input. + sed -nE "s/.*inputs\.mongodb-version \|\| '([0-9.]+)'.*/mongodb-server-version \1 actions\/mongodb\/start\/action.yml/p" actions/mongodb/start/action.yml + # Literal versions in the reusable workflows, ci.yml being left out since its older versions test the inputs. + grep -HnoE '^\s+[a-z0-9-]+-version: v?[0-9][0-9.]*$' .github/workflows/reusable-*.yml \ + | awk -F: '{ gsub(/ /, "", $3); print $3, $4 ? $4 : "", $1 }' | sed 's/ */ /g' + # Tools that the reusable workflows run inline, pinned by pipx, npx or a variable. + grep -HoE 'pipx run --spec [A-Za-z0-9_.-]+==[^ ]+' .github/workflows/reusable-*.yml \ + | sed -E 's/^([^:]+):pipx run --spec ([^=]+)==(.*)/pypi:\2 \3 \1/' + grep -HoE 'npx --yes [@A-Za-z0-9_./-]+@[0-9][^ ]*' .github/workflows/reusable-*.yml \ + | sed -E 's/^([^:]+):npx --yes (.+)@([^@]+)$/npm:\2 \3 \1/' + grep -HoE 'shellcheck_version="[^"]+"' .github/workflows/reusable-*.yml \ + | sed -E 's/^([^:]+):shellcheck_version="([^"]+)"/shellcheck-version \2 \1/' + sed -nE 's/^ACTIONLINT_VERSION=(.*)/actionlint-version \1 test\/run_static_checks.sh/p' test/run_static_checks.sh + sed -nE 's/^([A-Za-z0-9_.-]+)==([^ ]+).*/pypi:\1 \2 test\/requirements.txt/p' test/requirements.txt + # Providers locked by the Terraform fixtures, since the provider scan warns about the vulnerabilities of an old one. + git ls-files '*.terraform.lock.hcl' | while read -r lock; do + awk -v f="$lock" ' + /^provider "/ { split($2, parts, "/"); provider = parts[2] "/" parts[3]; gsub(/"/, "", provider) } + provider && /^ version *=/ { gsub(/"/, "", $3); print "terraform:" provider, $3, f; provider = "" } + ' "$lock" + done +} + +printf '%-28s %-16s %-16s %s\n' NAME CURRENT LATEST FILE + +declare -A seen=() +while read -r name current file; do + key="${name} ${current}" + [[ -n "${seen[$key]:-}" ]] && continue + seen[$key]=1 + if [[ "$name" == pypi:* ]]; then + source="pypi ${name#pypi:}" + elif [[ "$name" == npm:* ]]; then + source="npm ${name#npm:}" + elif [[ "$name" == terraform:* ]]; then + source="terraform ${name#terraform:}" + else + source="${SOURCES[$name]:-}" + fi + if [[ -z "$source" ]]; then + printf '%-28s %-16s %-16s %s\n' "$name" "$current" "UNKNOWN SOURCE" "$file" + status=1 + continue + fi + [[ "$source" == skip ]] && continue + # shellcheck disable=SC2086 # The source is split into its kind and arguments on purpose. + report "$name" "$current" "$(latest $source || true)" "$file" +done < <(pins) + +# GitHub Actions pinned by SHA, with their version in the trailing comment. +while read -r action version; do + repo=$(cut -d/ -f1-2 <<< "$action") + report "$action" "$version" "$(latest_github "$repo" || true)" "uses" +done < <(grep -rhoE 'uses: [A-Za-z0-9_.-]+/[A-Za-z0-9_./-]+@[0-9a-f]{40} +# v?[0-9.]+' .github actions \ + | sed -E 's/uses: ([^@]+)@[0-9a-f]+ +# (.*)/\1 \2/' | sort -u) + +exit "$status" diff --git a/test/check_workflow_parts.py b/test/check_workflow_parts.py index efda25c..25324a7 100755 --- a/test/check_workflow_parts.py +++ b/test/check_workflow_parts.py @@ -22,7 +22,6 @@ UNTESTED_PARTS = { "actions/fossa/analyze": "needs a FOSSA API key", "actions/mongodb-atlas/add-runner-ip": "needs MongoDB Atlas credentials", - ".github/workflows/reusable-container-publication.yml": "needs registry credentials and an OIDC token to sign", ".github/workflows/reusable-helm-publication.yml": "creates GitHub releases and pushes to the Pages branch of the repository", ".github/workflows/reusable-terraform-deployment.yml": "needs MongoDB Atlas credentials and a Terraform backend", } @@ -156,8 +155,9 @@ def check_action(directory): for index, step in enumerate(runs.get("steps", []), 1): if not step.get("name"): fail(name, f"step {index} has no name") - if "run" in step and step.get("shell") != "bash": - fail(name, f"step '{step.get('name', index)}' runs a script without 'shell: bash', which a composite action requires and the actions assume") + # A Windows runner has no bash of its own, so an action made for one runs PowerShell. + if "run" in step and step.get("shell") not in ("bash", "pwsh"): + fail(name, f"step '{step.get('name', index)}' runs a script without 'shell: bash' or 'shell: pwsh', which a composite action requires") def check_reusable_workflow(path): @@ -217,7 +217,7 @@ def shellcheck_actions(): for action in action_paths(): document = load(action / "action.yml") for index, step in enumerate(document["runs"].get("steps", []), 1): - if "run" not in step: + if "run" not in step or step.get("shell") != "bash": continue script = pathlib.Path(directory) / f"{action.relative_to(ROOT).as_posix().replace('/', '_')}_{index}.sh" # An expression becomes a word shellcheck reads as a plain value, as the runner writes it before bash runs. diff --git a/test/fixtures/container/windows/Dockerfile b/test/fixtures/container/windows/Dockerfile new file mode 100644 index 0000000..f7782ef --- /dev/null +++ b/test/fixtures/container/windows/Dockerfile @@ -0,0 +1,4 @@ +# A command run in the build proves the engine starts a Windows container, which only a matching Windows version does. +FROM mcr.microsoft.com/windows/nanoserver:ltsc2025 +RUN cmd /c ver +CMD ["cmd", "/c", "echo", "ok"] diff --git a/test/fixtures/dotnet-framework/.gitignore b/test/fixtures/dotnet-framework/.gitignore new file mode 100644 index 0000000..227e9f2 --- /dev/null +++ b/test/fixtures/dotnet-framework/.gitignore @@ -0,0 +1,4 @@ +bin/ +obj/ +packages/ +report/ diff --git a/test/fixtures/dotnet-framework/Fixture.Framework.Library/Fixture.Framework.Library.csproj b/test/fixtures/dotnet-framework/Fixture.Framework.Library/Fixture.Framework.Library.csproj new file mode 100644 index 0000000..33cf763 --- /dev/null +++ b/test/fixtures/dotnet-framework/Fixture.Framework.Library/Fixture.Framework.Library.csproj @@ -0,0 +1,28 @@ + + + + + + Debug + AnyCPU + {6E1F3C2A-8B4D-4F5E-9A7C-1D2E3F4A5B6C} + Library + Fixture.Framework.Library + Fixture.Framework.Library + v4.8 + bin\$(Configuration)\ + + + + + ..\packages\Newtonsoft.Json.13.0.4\lib\net45\Newtonsoft.Json.dll + + + + + + + + + + diff --git a/test/fixtures/dotnet-framework/Fixture.Framework.Library/Greeting.cs b/test/fixtures/dotnet-framework/Fixture.Framework.Library/Greeting.cs new file mode 100644 index 0000000..838695c --- /dev/null +++ b/test/fixtures/dotnet-framework/Fixture.Framework.Library/Greeting.cs @@ -0,0 +1,13 @@ +using Newtonsoft.Json; + +namespace Fixture.Framework.Library +{ + public static class Greeting + { + // A package restored from packages.config is used, so a restore that skips it fails the build. + public static string ToJson(string name) + { + return JsonConvert.SerializeObject(new { message = "Hello " + name }); + } + } +} diff --git a/test/fixtures/dotnet-framework/Fixture.Framework.Library/packages.config b/test/fixtures/dotnet-framework/Fixture.Framework.Library/packages.config new file mode 100644 index 0000000..57a5b0a --- /dev/null +++ b/test/fixtures/dotnet-framework/Fixture.Framework.Library/packages.config @@ -0,0 +1,4 @@ + + + + diff --git a/test/fixtures/dotnet-framework/Fixture.Framework.Tests/Fixture.Framework.Tests.csproj b/test/fixtures/dotnet-framework/Fixture.Framework.Tests/Fixture.Framework.Tests.csproj new file mode 100644 index 0000000..379ac79 --- /dev/null +++ b/test/fixtures/dotnet-framework/Fixture.Framework.Tests/Fixture.Framework.Tests.csproj @@ -0,0 +1,18 @@ + + + + net48 + false + + + + + + + + + + + + + diff --git a/test/fixtures/dotnet-framework/Fixture.Framework.Tests/GreetingTests.cs b/test/fixtures/dotnet-framework/Fixture.Framework.Tests/GreetingTests.cs new file mode 100644 index 0000000..67f68f3 --- /dev/null +++ b/test/fixtures/dotnet-framework/Fixture.Framework.Tests/GreetingTests.cs @@ -0,0 +1,15 @@ +using Fixture.Framework.Library; +using Microsoft.VisualStudio.TestTools.UnitTesting; + +namespace Fixture.Framework.Tests +{ + [TestClass] + public class GreetingTests + { + [TestMethod] + public void ToJson_WritesTheMessage() + { + Assert.AreEqual("{\"message\":\"Hello world\"}", Greeting.ToJson("world")); + } + } +} diff --git a/test/fixtures/dotnet-framework/Fixture.Framework.sln b/test/fixtures/dotnet-framework/Fixture.Framework.sln new file mode 100644 index 0000000..ee4b3dc --- /dev/null +++ b/test/fixtures/dotnet-framework/Fixture.Framework.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.0.31903.59 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Fixture.Framework.Library", "Fixture.Framework.Library\Fixture.Framework.Library.csproj", "{6E1F3C2A-8B4D-4F5E-9A7C-1D2E3F4A5B6C}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Fixture.Framework.Tests", "Fixture.Framework.Tests\Fixture.Framework.Tests.csproj", "{2B7C4D1E-5F6A-4B8C-9D0E-3F1A2B4C5D6E}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {6E1F3C2A-8B4D-4F5E-9A7C-1D2E3F4A5B6C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {6E1F3C2A-8B4D-4F5E-9A7C-1D2E3F4A5B6C}.Debug|Any CPU.Build.0 = Debug|Any CPU + {6E1F3C2A-8B4D-4F5E-9A7C-1D2E3F4A5B6C}.Release|Any CPU.ActiveCfg = Release|Any CPU + {6E1F3C2A-8B4D-4F5E-9A7C-1D2E3F4A5B6C}.Release|Any CPU.Build.0 = Release|Any CPU + {2B7C4D1E-5F6A-4B8C-9D0E-3F1A2B4C5D6E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {2B7C4D1E-5F6A-4B8C-9D0E-3F1A2B4C5D6E}.Debug|Any CPU.Build.0 = Debug|Any CPU + {2B7C4D1E-5F6A-4B8C-9D0E-3F1A2B4C5D6E}.Release|Any CPU.ActiveCfg = Release|Any CPU + {2B7C4D1E-5F6A-4B8C-9D0E-3F1A2B4C5D6E}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection +EndGlobal diff --git a/test/fixtures/terraform/.tflint.hcl b/test/fixtures/terraform/.tflint.hcl index 427121c..34cf3ef 100644 --- a/test/fixtures/terraform/.tflint.hcl +++ b/test/fixtures/terraform/.tflint.hcl @@ -2,3 +2,10 @@ plugin "terraform" { enabled = true preset = "recommended" } + +# A plugin pinned to an exact version, for the check of TFLint plugin versions. +plugin "azurerm" { + enabled = true + version = "0.33.0" + source = "github.com/terraform-linters/tflint-ruleset-azurerm" +} diff --git a/test/fixtures/terraform/examples/greeting/.terraform.lock.hcl b/test/fixtures/terraform/examples/greeting/.terraform.lock.hcl new file mode 100644 index 0000000..4f0ac51 --- /dev/null +++ b/test/fixtures/terraform/examples/greeting/.terraform.lock.hcl @@ -0,0 +1,26 @@ +# This file is maintained automatically by "terraform init". +# Manual edits may be lost in future updates. + +provider "registry.terraform.io/hashicorp/local" { + version = "2.9.1" + constraints = "~> 2.5" + hashes = [ + "h1:OZGJN0LSSat5QIxZPxDXtVr4XpHb2oG7cVKJhSqBFIE=", + "h1:bek0XHcE8X713/1PR+sMKZFwLnamznJdYbORghbFRn0=", + "h1:qGLHCuYSus+uHNnoEL4SuJqOs5yrNOcB7gnuHoVqizo=", + "h1:tX/GU6iR6pP5XMj3zo22mIsZEIW2GUZ9GxfVdo2KjoI=", + "zh:25606c7a5e308144fb627f6e31611bb52ff72bb9ae2d27af39673ab1a6b3c1bf", + "zh:2568c4ef4dab31821f6f7040af0d1a2aa2b9455b8d9cc546598b791b8ada34cd", + "zh:25ac210f136042047975896e5e11fe6012425301c826d6b7ce22a49f96a1e0e8", + "zh:55d3a7bf01eced8e1f259b548020ef1221c5687e0fe6b5b30f81ad0b4121ff12", + "zh:6168d6934777b853c57815baa18a54101c604a6f1124ca47cd23d016c6f2f1e5", + "zh:63c0aa17c8373f761123376226debffd1f2259901ff259d4547c520def9a6787", + "zh:6d1f1572db6c85bd6d6b1b1deef247084e189816875f67e6bcc5d4736794e0a9", + "zh:78d5eefdd9e494defcb3c68d282b8f96630502cac21d1ea161f53cfe9bb483b3", + "zh:a8ea1c155bd5e0d695a28d3c0e2f542de8844e1791ea021f015a3f08e1c059e1", + "zh:ccd790f97269509ade0574ef63c955d3943cb1d812c59177bd85ce4c1d17ca0f", + "zh:dcfc17bb666e659a9daa9ff52fd8f6ec9ea519868726015e645955c372296332", + "zh:eb83abbfa7f52cba609b48cbb9a6a5cab07780a672b2020fc2ba190e699a2516", + "zh:eedffca70074ae153790fb23c4ace8d1637a60ceba4e3c42c8eaeda7c1f9d10f", + ] +} diff --git a/test/fixtures/terraform/examples/greeting/main.tf b/test/fixtures/terraform/examples/greeting/main.tf new file mode 100644 index 0000000..b0b5c68 --- /dev/null +++ b/test/fixtures/terraform/examples/greeting/main.tf @@ -0,0 +1,16 @@ +# Root configuration of the Terraform fixture calling its module, with a committed lock file. + +terraform { + required_version = ">= 1.9.0" +} + +module "greeting" { + source = "../../modules/greeting" + + name = "github-workflow-parts" +} + +output "filename" { + description = "Path of the greeting file" + value = module.greeting.filename +} diff --git a/test/fixtures/terraform/modules/greeting/main.tf b/test/fixtures/terraform/modules/greeting/main.tf new file mode 100644 index 0000000..5fa2a71 --- /dev/null +++ b/test/fixtures/terraform/modules/greeting/main.tf @@ -0,0 +1,27 @@ +# Module of the Terraform fixture, validated on its own and through the example calling it. + +terraform { + required_version = ">= 1.9.0" + + required_providers { + local = { + source = "hashicorp/local" + version = "~> 2.5" + } + } +} + +variable "name" { + description = "Name the greeting is addressed to" + type = string +} + +resource "local_file" "greeting" { + filename = "${path.root}/greeting.txt" + content = "Hello ${var.name}.\n" +} + +output "filename" { + description = "Path of the greeting file" + value = local_file.greeting.filename +} diff --git a/test/fixtures/trivy/rootfs/usr/lib/python3/site-packages/urllib3-1.24.1.dist-info/METADATA b/test/fixtures/trivy/rootfs/usr/lib/python3/site-packages/urllib3-1.24.1.dist-info/METADATA new file mode 100644 index 0000000..4aa485b --- /dev/null +++ b/test/fixtures/trivy/rootfs/usr/lib/python3/site-packages/urllib3-1.24.1.dist-info/METADATA @@ -0,0 +1,5 @@ +Metadata-Version: 2.1 +Name: urllib3 +Version: 1.24.1 +Summary: Fixture of an installed package with known vulnerabilities, for the rootfs scan of the Trivy action. +License: MIT