Skip to content

Commit 5ea8a69

Browse files
author
chendelin1982
committed
refactor(ci): optimize CI pipeline structure
Changes: 1. Add independent 'security' job - Move govulncheck from test to security - Move Trivy scan from docker-build to security - Depends on lint + test, non-blocking for main pipeline 2. Test coverage as warning only - Add 'continue-on-error: true' - Use ::warning:: annotation for GitHub UI - No longer fails CI if below threshold 3. Update summary job dependencies - Add security to needs list - Security failures show warning but don't block CI Benefits: - Security checks run independently - Coverage warnings don't block deployments - Better separation of concerns (lint/test/security/build) Related: Story 5 CI/CD Pipeline, Story 17 Go Version Upgrade
1 parent 84a94c2 commit 5ea8a69

File tree

1 file changed

+66
-20
lines changed

1 file changed

+66
-20
lines changed

.github/workflows/ci.yml

Lines changed: 66 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -50,27 +50,23 @@ jobs:
5050
working-directory: core
5151
run: go mod download
5252

53-
- name: Run govulncheck (dependency vulnerability scan)
54-
uses: golang/govulncheck-action@v1
55-
with:
56-
go-version-input: ${{ env.GO_VERSION }}
57-
go-package: ./...
58-
work-dir: core
59-
6053
- name: Run tests with coverage
6154
working-directory: core
6255
run: |
6356
go test -v -race -coverprofile=coverage.out -covermode=atomic ./...
6457
go tool cover -func=coverage.out
6558
66-
- name: Check coverage threshold
59+
- name: Check coverage threshold (warning only)
6760
working-directory: core
61+
continue-on-error: true
6862
run: |
6963
COVERAGE=$(go tool cover -func=coverage.out | grep total | awk '{print $3}' | sed 's/%//')
70-
echo "Current coverage: ${COVERAGE}%"
64+
echo "📊 Current coverage: ${COVERAGE}%"
7165
if (( $(echo "$COVERAGE < ${{ env.COVERAGE_THRESHOLD }}" | bc -l) )); then
72-
echo "Coverage ${COVERAGE}% is below threshold ${{ env.COVERAGE_THRESHOLD }}%"
73-
exit 1
66+
echo "⚠️ Warning: Coverage ${COVERAGE}% is below threshold ${{ env.COVERAGE_THRESHOLD }}%"
67+
echo "::warning::Code coverage (${COVERAGE}%) is below the recommended threshold (${{ env.COVERAGE_THRESHOLD }}%)"
68+
else
69+
echo "✅ Coverage meets threshold"
7470
fi
7571
7672
- name: Upload coverage to Codecov
@@ -106,48 +102,87 @@ jobs:
106102
run: |
107103
./bin/apprun-core --version || echo "Version command not implemented yet"
108104
109-
docker-build:
110-
name: Build Docker Image
105+
security:
106+
name: Security Checks
111107
runs-on: ubuntu-latest
112108
needs: [lint, test]
113109
steps:
114110
- name: Checkout code
115111
uses: actions/checkout@v4
116112

113+
- name: Set up Go
114+
uses: actions/setup-go@v5
115+
with:
116+
go-version: ${{ env.GO_VERSION }}
117+
cache: true
118+
cache-dependency-path: core/go.sum
119+
120+
- name: Run govulncheck (dependency vulnerabilities)
121+
uses: golang/govulncheck-action@v1
122+
with:
123+
go-version-input: ${{ env.GO_VERSION }}
124+
go-package: ./...
125+
work-dir: core
126+
117127
- name: Set up QEMU
118128
uses: docker/setup-qemu-action@v3
119129

120130
- name: Set up Docker Buildx
121131
uses: docker/setup-buildx-action@v3
122132

123-
- name: Build Docker image (test only)
124-
id: build
133+
- name: Build Docker image for security scan
125134
uses: docker/build-push-action@v5
126135
with:
127136
context: .
128137
file: ./docker/Dockerfile
129138
push: false
130-
tags: apprun:ci-test
139+
tags: apprun:security-scan
131140
cache-from: type=gha
132141
cache-to: type=gha,mode=max
133-
platforms: linux/amd64,linux/arm64
142+
load: true
134143

135144
- name: Run Trivy vulnerability scanner
136145
uses: aquasecurity/trivy-action@master
137146
with:
138147
scan-type: 'image'
139-
image-ref: 'apprun:ci-test'
148+
image-ref: 'apprun:security-scan'
140149
format: 'sarif'
141150
output: 'trivy-results.sarif'
142151
exit-code: '1'
143152
severity: 'CRITICAL,HIGH'
144153

145-
- name: Upload Trivy scan results to GitHub Security tab
154+
- name: Upload Trivy results to GitHub Security tab
146155
uses: github/codeql-action/upload-sarif@v3
147156
if: always()
148157
with:
149158
sarif_file: 'trivy-results.sarif'
150159

160+
docker-build:
161+
name: Build Docker Image
162+
runs-on: ubuntu-latest
163+
needs: [lint, test]
164+
steps:
165+
- name: Checkout code
166+
uses: actions/checkout@v4
167+
168+
- name: Set up QEMU
169+
uses: docker/setup-qemu-action@v3
170+
171+
- name: Set up Docker Buildx
172+
uses: docker/setup-buildx-action@v3
173+
174+
- name: Build Docker image (test only)
175+
id: build
176+
uses: docker/build-push-action@v5
177+
with:
178+
context: .
179+
file: ./docker/Dockerfile
180+
push: false
181+
tags: apprun:ci-test
182+
cache-from: type=gha
183+
cache-to: type=gha,mode=max
184+
platforms: linux/amd64,linux/arm64
185+
151186
integration-test:
152187
name: Integration Tests
153188
runs-on: ubuntu-latest
@@ -174,25 +209,36 @@ jobs:
174209
summary:
175210
name: CI Summary
176211
runs-on: ubuntu-latest
177-
needs: [lint, test, build, docker-build, integration-test]
212+
needs: [lint, test, build, security, docker-build, integration-test]
178213
if: always()
214+
permissions:
215+
actions: write
179216
steps:
180217
- name: Check job status
181218
run: |
182219
echo "=== CI Pipeline Summary ==="
183220
echo "Lint: ${{ needs.lint.result }}"
184221
echo "Test: ${{ needs.test.result }}"
185222
echo "Build: ${{ needs.build.result }}"
223+
echo "Security: ${{ needs.security.result }}"
186224
echo "Docker Build: ${{ needs.docker-build.result }}"
187225
echo "Integration Test: ${{ needs.integration-test.result }}"
188226
227+
# Core jobs must pass (security is independent)
189228
if [[ "${{ needs.lint.result }}" != "success" ]] || \
190229
[[ "${{ needs.test.result }}" != "success" ]] || \
191230
[[ "${{ needs.build.result }}" != "success" ]] || \
192231
[[ "${{ needs.docker-build.result }}" != "success" ]]; then
193232
echo "❌ CI Pipeline failed"
194233
exit 1
195234
fi
235+
236+
# Security check warning (non-blocking)
237+
if [[ "${{ needs.security.result }}" != "success" ]]; then
238+
echo "⚠️ Security checks failed - please review vulnerabilities"
239+
echo "::warning::Security scan detected vulnerabilities. Check the Security tab for details."
240+
fi
241+
196242
echo "✅ CI Pipeline passed"
197243
echo ""
198244
echo "Note: Docker Build workflow will be triggered automatically via workflow_run on main/develop branches"

0 commit comments

Comments
 (0)