Skip to content

feat: consolidate PR gates and harden security scans#2669

Open
DerekRoberts wants to merge 1 commit intomainfrom
feat/harden-ci-gates-v2
Open

feat: consolidate PR gates and harden security scans#2669
DerekRoberts wants to merge 1 commit intomainfrom
feat/harden-ci-gates-v2

Conversation

@DerekRoberts
Copy link
Copy Markdown
Member

@DerekRoberts DerekRoberts commented Apr 9, 2026

Summary

This PR hardens the CI configuration to prevent merges when tests or security scans fail, addressing the issue where PRs (like #2667) were able to merge despite failing checks.

The Problem

The repository had fragmented workflows (pr-open.yml and analysis.yml), each with their own Results job. If only one Results job was marked as required, the other workflow's failures would not block a merge. Additionally, Trivy scans were configured with continue-on-error: true, hiding security failures.

The Fix

  1. Consolidated PR Gate: Ported Backend/Frontend tests and Trivy scans from analysis.yml directly into pr-open.yml.
  2. Unified Results: The PR Results job now depends on ALL checks, including security.
  3. Hard Security Failures: Set exit-code: 1 and removed continue-on-error from Trivy to ensure vulnerabilities block merges.

Action Required

The repository administrator should ensure that the status check named PR Results (from pr-open.yml) is set as the primary Required Status Check in Branch Protection settings.


Thanks for the PR!

Deployments, as required, will be available below:

Please create PRs in draft mode. Mark as ready to enable:

After merge, new images are deployed in:

Copilot AI review requested due to automatic review settings April 9, 2026 20:14
@DerekRoberts DerekRoberts force-pushed the feat/harden-ci-gates-v2 branch from 17273b9 to f9c1213 Compare April 9, 2026 20:18
Comment on lines +13 to +52
name: Backend
runs-on: ubuntu-24.04
timeout-minutes: 5
services:
postgres:
image: postgres
env:
POSTGRES_PASSWORD: default
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 5432:5432
steps:
- uses: actions/checkout@v6
- uses: bcgov/action-test-and-analyse@v2
env:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN_BACKEND }}
with:
commands: |
npm ci
npm run lint
npm run test:cov
dir: backend
node_version: "22"
sonar_args: >
-Dsonar.exclusions=**/coverage/**,**/node_modules/**,**/*spec.ts
-Dsonar.organization=bcgov-sonarcloud
-Dsonar.projectKey=quickstart-openshift_backend
-Dsonar.sources=src
-Dsonar.test.inclusions=**/*spec.ts
-Dsonar.javascript.lcov.reportPaths=./coverage/lcov.info
sonar_token: ${{ env.SONAR_TOKEN }}
dep_scan: warning
supply_scan: true
triggers: ('backend/')

frontend-tests:
Comment on lines +53 to +80
name: Frontend
runs-on: ubuntu-24.04
timeout-minutes: 5
steps:
- uses: actions/checkout@v6
- uses: bcgov/action-test-and-analyse@v2
env:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN_FRONTEND }}
with:
commands: |
npm ci
npm run lint
npm run test:cov
dir: frontend
node_version: "22"
sonar_args: >-
-Dsonar.exclusions=**/coverage/**,**/node_modules/**,**/*spec.ts
-Dsonar.organization=bcgov-sonarcloud
-Dsonar.projectKey=quickstart-openshift_frontend
-Dsonar.sources=src
-Dsonar.test.inclusions=**/*spec.ts
-Dsonar.javascript.lcov.reportPaths=./coverage/lcov.info
sonar_token: ${{ env.SONAR_TOKEN }}
dep_scan: warning
supply_scan: true
triggers: ('frontend/')

trivy:
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR tightens merge gating by centralizing CI checks into the pr-open.yml workflow and making security scan failures (Trivy) block merges, addressing cases where PRs could merge despite failures in non-required workflows.

Changes:

  • Added Backend/Frontend test jobs and a Trivy scan job to pr-open.yml and included them in the unified PR Results gate.
  • Hardened Trivy scanning in analysis.yml by removing continue-on-error and forcing non-zero exit on HIGH/CRITICAL findings.
  • Updated Analysis Results to depend on Trivy and run with if: always().

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
.github/workflows/pr-open.yml Adds backend/frontend unit+lint+coverage jobs and Trivy scan; makes PR Results depend on all PR checks.
.github/workflows/analysis.yml Makes Trivy fail the workflow on findings and ensures Analysis Results reflects Trivy outcome.
Comments suppressed due to low confidence (1)

.github/workflows/analysis.yml:119

  • analysis.yml still runs on pull_request events and includes backend/frontend tests + Trivy, but those same checks have now been added to pr-open.yml and are included in the required PR Results gate. This will cause duplicate CI runs on every PR (extra time/cost) and can create confusion about which workflow is authoritative for merge gating. Consider removing the pull_request trigger from analysis.yml (keep it for push/schedule), or gating these jobs to skip when github.event_name == 'pull_request'.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +59 to +63
SONAR_TOKEN_FRONTEND: ${{ secrets.SONAR_TOKEN_FRONTEND }}

results:
name: PR Results
needs: [builds, deploys, tests]
needs: [builds, deploys, tests, unit-tests]
Copy link

Copilot AI Apr 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Postgres service uses the floating postgres image tag, which can change over time (including major-version upgrades) and make CI behavior non-deterministic. Pin the image to a specific major/minor (e.g., postgres:16 or similar) to keep PR test runs reproducible.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: New

Development

Successfully merging this pull request may close these issues.

3 participants