Skip to content

fix: add GH_TOKEN preflight check to compliance-audit.sh#60

Merged
don-petry merged 1 commit intomainfrom
claude/issue-30-20260406-0341
Apr 6, 2026
Merged

fix: add GH_TOKEN preflight check to compliance-audit.sh#60
don-petry merged 1 commit intomainfrom
claude/issue-30-20260406-0341

Conversation

@claude
Copy link
Copy Markdown
Contributor

@claude claude Bot commented Apr 6, 2026

Summary

Adds an early-exit preflight check at the top of main() in scripts/compliance-audit.sh that fails fast with clear, actionable error messages when authentication isn't configured correctly.

Changes

scripts/compliance-audit.sh — added at the top of main():

# Preflight: verify GH_TOKEN is set and gh CLI is authenticated
if [ -z "${GH_TOKEN:-}" ]; then
  echo "::error::GH_TOKEN is not set. Ensure ORG_SCORECARD_TOKEN secret is configured and passed as an env var to this step." >&2
  exit 1
fi
if ! gh auth status >/dev/null 2>&1; then
  echo "::error::gh auth failed — GH_TOKEN is set but authentication did not succeed. Check that ORG_SCORECARD_TOKEN is valid and has repo + read:org scopes." >&2
  exit 1
fi

Previously, auth failures manifested deep in the script as cryptic gh CLI errors rather than a clear authentication failure message.

Required manual change (workflow file)

The Claude GitHub App lacks the workflows permission and cannot modify .github/workflows/. To fully resolve the root cause, apply this one-line change manually to .github/workflows/compliance-audit-and-improvement.yml:

In the Run compliance audit step (job audit), add GH_TOKEN explicitly at the step level:

      - name: Run compliance audit
        id: audit
        env:
          GH_TOKEN: ${{ secrets.ORG_SCORECARD_TOKEN }}   # ← add this line
          REPORT_DIR: ${{ runner.temp }}/compliance-report
          DRY_RUN: ${{ inputs.dry_run || 'false' }}
          CREATE_ISSUES: 'true'

Also verify ORG_SCORECARD_TOKEN is set in Settings → Secrets with repo + read:org scopes.

Closes #30

Generated with Claude Code

Adds an early-exit preflight check at the top of main() that:
1. Fails fast with a clear error if GH_TOKEN is unset
2. Runs gh auth status to verify the token is valid before proceeding

Previously, auth failures manifested deep in the script as cryptic
gh CLI errors rather than a clear authentication failure.

Note: the step-level GH_TOKEN env var in the workflow also needs
to be added manually (cannot be done here due to workflow permissions).
See issue #30 for the required one-line workflow change.

Co-authored-by: don-petry <don-petry@users.noreply.github.com>
@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud Bot commented Apr 6, 2026

@don-petry don-petry merged commit eba7ea0 into main Apr 6, 2026
17 checks passed
@don-petry don-petry deleted the claude/issue-30-20260406-0341 branch April 6, 2026 11:47
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.

fix: Weekly Compliance Audit workflow broken — GH_TOKEN not passed to script

1 participant