diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1bd7a89..c32da18 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -20,7 +20,11 @@ jobs: fail-fast: false matrix: os: [ubuntu-latest, macos-latest] - runs-on: ${{ matrix.os }} + # The Linux leg runs on the self-hosted runner; the matrix value stays + # "ubuntu-latest" so the required check names do not change. Fork PRs never + # reach the self-hosted runner (it has the host Docker socket); neither do + # Dependabot PRs, whose workflow changes are unreviewed until merged. + runs-on: ${{ matrix.os == 'macos-latest' && 'macos-latest' || ((github.event_name != 'pull_request' || (github.event.pull_request.head.repo.full_name == github.repository && github.event.pull_request.user.login != 'dependabot[bot]' && !startsWith(github.event.pull_request.head.ref, 'dependabot/'))) && fromJSON('["self-hosted","Linux","X64","docker"]') || 'ubuntu-latest') }} timeout-minutes: 10 steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 @@ -29,8 +33,11 @@ jobs: - name: Install zsh + shellcheck run: | if [ "$RUNNER_OS" = Linux ]; then - sudo apt-get update -qq - sudo apt-get install -y -qq zsh shellcheck + # The self-hosted runner image runs as root and ships no sudo. + SUDO="" + [ "$(id -u)" -eq 0 ] || SUDO="sudo" + $SUDO apt-get update -qq + $SUDO apt-get install -y -qq zsh shellcheck else brew install shellcheck fi @@ -80,15 +87,23 @@ jobs: secrets: name: secret scan (full history) - runs-on: ubuntu-latest + # Self-hosted runner for trusted runs only (see lint-test); other PRs stay on + # GitHub's runners. + runs-on: ${{ (github.event_name != 'pull_request' || (github.event.pull_request.head.repo.full_name == github.repository && github.event.pull_request.user.login != 'dependabot[bot]' && !startsWith(github.event.pull_request.head.ref, 'dependabot/'))) && fromJSON('["self-hosted","Linux","X64","docker"]') || 'ubuntu-latest' }} timeout-minutes: 5 steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: fetch-depth: 0 persist-credentials: false + # `docker run -v "$PWD:/repo"` resolves $PWD on the Docker host, which is + # not the runner's path when the runner itself is a container. Copy the + # checkout into the scan container instead; this works on both runner kinds. - name: gitleaks run: | - docker run --rm -v "$PWD:/repo" \ + cid="$(docker create \ zricethezav/gitleaks@sha256:c00b6bd0aeb3071cbcb79009cb16a60dd9e0a7c60e2be9ab65d25e6bc8abbb7f \ - git /repo --no-banner --redact -v + git /repo --no-banner --redact -v)" + trap 'docker rm -f "$cid" >/dev/null' EXIT + docker cp "$PWD/." "$cid:/repo" + docker start -a "$cid"