Skip to content

Fix TruffleHog workflow failing on push events with "BASE and HEAD commits are the same" - #16

Merged
No-Github merged 2 commits into
masterfrom
copilot/fix-secret-scan-workflow
Jan 23, 2026
Merged

Fix TruffleHog workflow failing on push events with "BASE and HEAD commits are the same"#16
No-Github merged 2 commits into
masterfrom
copilot/fix-secret-scan-workflow

Conversation

Copilot AI commented Jan 23, 2026

Copy link
Copy Markdown
Contributor

TruffleHog was failing on push events because base: ${{ github.event.repository.default_branch }} and head: HEAD resolve to the same commit when pushing directly to master.

Changes

Split the TruffleHog step into two conditional executions:

  • Push/workflow_dispatch: Omit base and head parameters, allowing TruffleHog to scan commits in the push using its default behavior
  • Pull requests: Use github.event.pull_request.base.sha and github.event.pull_request.head.sha to explicitly scan the diff
- name: TruffleHog Secret Scanning (Push/Workflow Dispatch)
  if: github.event_name != 'pull_request'
  uses: trufflesecurity/trufflehog@v3.82.13
  with:
    path: ./
    extra_args: --exclude-paths=.trufflehogignore --json

- name: TruffleHog Secret Scanning (Pull Request)
  if: github.event_name == 'pull_request'
  uses: trufflesecurity/trufflehog@v3.82.13
  with:
    path: ./
    base: ${{ github.event.pull_request.base.sha }}
    head: ${{ github.event.pull_request.head.sha }}
    extra_args: --exclude-paths=.trufflehogignore --json
Original prompt

Problem

The secret scanning workflow is failing with the error:

BASE and HEAD commits are the same. TruffleHog won't scan anything.

This occurs when pushing directly to the master branch because both base and head resolve to the same commit.

Solution Required

Fix the .github/workflows/secret-scan.yml workflow file to properly handle different event types:

  1. For push events: Remove the base and head parameters to let TruffleHog use its default behavior (scanning the commits in the push)
  2. For pull_request events: Use the proper base and head references for PR scanning
  3. For workflow_dispatch: Use default scanning behavior

Current Configuration (Lines 23-33 in .github/workflows/secret-scan.yml)

- name: TruffleHog Secret Scanning
  uses: trufflesecurity/trufflehog@v3.82.13
  with:
    path: ./
    base: ${{ github.event.repository.default_branch }}
    head: HEAD
    extra_args: --exclude-paths=.trufflehogignore --json

Recommended Fix

Replace the TruffleHog step with conditional logic:

- name: TruffleHog Secret Scanning (Push/Workflow Dispatch)
  if: github.event_name != 'pull_request'
  uses: trufflesecurity/trufflehog@v3.82.13
  with:
    path: ./
    extra_args: --exclude-paths=.trufflehogignore --json

- name: TruffleHog Secret Scanning (Pull Request)
  if: github.event_name == 'pull_request'
  uses: trufflesecurity/trufflehog@v3.82.13
  with:
    path: ./
    base: ${{ github.event.pull_request.base.sha }}
    head: ${{ github.event.pull_request.head.sha }}
    extra_args: --exclude-paths=.trufflehogignore --json

This approach:

  • For push events and manual triggers: Scans using TruffleHog's default behavior
  • For pull requests: Explicitly scans the diff between base and head commits
  • Prevents the "BASE and HEAD commits are the same" error

Reference

This pull request was created from Copilot chat.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

- Split TruffleHog step into two conditional steps
- Push/workflow_dispatch: Use default behavior without base/head
- Pull requests: Use proper base and head SHA references
- Prevents "BASE and HEAD commits are the same" error

Co-authored-by: No-Github <18167071+No-Github@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix secret scanning workflow for different event types Fix TruffleHog workflow failing on push events with "BASE and HEAD commits are the same" Jan 23, 2026
Copilot AI requested a review from No-Github January 23, 2026 09:46
@No-Github
No-Github marked this pull request as ready for review January 23, 2026 09:46
@No-Github
No-Github merged commit 90ba176 into master Jan 23, 2026
2 checks passed
github-actions Bot pushed a commit that referenced this pull request Jan 23, 2026
…rkflow

Fix TruffleHog workflow failing on push events with "BASE and HEAD commits are the same" 90ba176
@No-Github
No-Github deleted the copilot/fix-secret-scan-workflow branch January 23, 2026 10:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants