Fix CI breakage from PR #181 - SyntaxWarning and authentication issues#186
Fix CI breakage from PR #181 - SyntaxWarning and authentication issues#186
Conversation
Co-authored-by: felickz <1760475+felickz@users.noreply.github.com>
Dependency Review✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.Scanned FilesNone |
The e2e-tests and action-test jobs require a PAT with permissions beyond what the default GITHUB_TOKEN provides. These jobs are now skipped when the POLICY_AS_CODE_TESTING_TOKEN secret is not available, preventing CI failures due to authentication errors. Co-authored-by: felickz <1760475+felickz@users.noreply.github.com>
Fixed in commit 42728bd. The CI failures were caused by:
Solution: Made both jobs conditional with The jobs will now only run when the secret is available with proper permissions. |
There was a problem hiding this comment.
Pull request overview
This PR fixes CI failures introduced by PR #181's Python 3.12+ upgrade by addressing a SyntaxWarning in the version file and making integration tests conditional on secret availability.
Changes:
- Converted ASCII art banner to raw f-string to eliminate Python 3.12+ SyntaxWarning
- Made e2e-tests and action-test jobs conditional to prevent failures when
POLICY_AS_CODE_TESTING_TOKENis unavailable
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| ghascompliance/version.py | Fixed SyntaxWarning by converting banner to raw f-string and adjusting backslash escaping |
| .github/workflows/main.yml | Added conditional checks to skip integration test jobs when authentication secret is missing |
.github/workflows/main.yml
Outdated
| runs-on: ubuntu-latest | ||
| needs: run | ||
| needs: run | ||
| if: ${{ secrets.POLICY_AS_CODE_TESTING_TOKEN != '' }} |
There was a problem hiding this comment.
The condition uses secrets.POLICY_AS_CODE_TESTING_TOKEN which is not accessible in the if context. GitHub Actions does not allow direct access to secrets in conditional expressions for security reasons. Use a different approach such as checking for the secret's existence in a prior step and setting an output, or consider using repository variables instead of secrets for this check.
There was a problem hiding this comment.
Fixed in commit 138a9d7. Implemented a check-secret job that safely checks for the secret and outputs a boolean. The e2e-tests job now uses needs.check-secret.outputs.has-testing-token == 'true' for its conditional.
.github/workflows/main.yml
Outdated
| runs-on: ubuntu-latest | ||
| needs: run | ||
| needs: run | ||
| if: ${{ secrets.POLICY_AS_CODE_TESTING_TOKEN != '' }} |
There was a problem hiding this comment.
The condition uses secrets.POLICY_AS_CODE_TESTING_TOKEN which is not accessible in the if context. GitHub Actions does not allow direct access to secrets in conditional expressions for security reasons. Use a different approach such as checking for the secret's existence in a prior step and setting an output, or consider using repository variables instead of secrets for this check.
There was a problem hiding this comment.
Fixed in commit 138a9d7. Implemented a check-secret job that safely checks for the secret and outputs a boolean. The action-test job now uses needs.check-secret.outputs.has-testing-token == 'true' for its conditional.
|
@copilot apply changes based on the comments in this thread |
GitHub Actions doesn't allow direct access to secrets in job-level if conditions. Changed to use a pre-check job that safely checks for secret existence and outputs a boolean, which the e2e-tests and action-test jobs can then use in their conditional expressions. Co-authored-by: felickz <1760475+felickz@users.noreply.github.com>
Fixed in commit 138a9d7. Changed from directly checking secrets in job-level conditionals (which GitHub Actions doesn't allow) to using a pre-check job that safely verifies secret existence and outputs a boolean that the integration test jobs can use. |
Use environment variable for secret check instead of directly referencing the secret in the shell condition. This prevents potential exposure in debug logs while still safely checking for secret existence. Co-authored-by: felickz <1760475+felickz@users.noreply.github.com>
PR #181 upgraded
actions/setup-pythonto v6, enabling Python 3.12+ testing. This exposed two issues that caused CI failures:Issues Fixed
1. SyntaxWarning in Python 3.12+
The ASCII art banner in
ghascompliance/__version__.pyused a regular f-string with backslashes, causing warnings:Fix: Converted
__banner__to raw f-string (rf""") to treat backslashes literally and removed trailing backslash after opening delimiter.2. Integration Test Authentication Failures
The
e2e-testsandaction-testjobs were failing with 401 authentication errors. These jobs require thePOLICY_AS_CODE_TESTING_TOKENsecret with broader permissions than the defaultGITHUB_TOKENprovides (which cannot access Dependabot alerts API and has limited security-events permissions).Fix: Implemented a secure pre-check job pattern to verify secret existence:
check-secretjob that safely checks for the token and outputs a booleancheck-secretand use its output (needs.check-secret.outputs.has-testing-token == 'true') in their conditionalsTesting
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.