Skip to content

Commit 15563c9

Browse files
authored
Enhance CI workflows and security scans; update dependencies and configurations for improved performance and security practices (#7)
1 parent 4db51bb commit 15563c9

9 files changed

Lines changed: 218 additions & 103 deletions

File tree

.github/workflows/ci-tests-coverage.yml

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,32 +4,52 @@ on:
44
push:
55
branches: ["**"]
66
pull_request:
7+
workflow_dispatch:
8+
9+
permissions:
10+
contents: read
711

812
jobs:
913
test:
14+
name: Build & Test
1015
runs-on: ubuntu-latest
16+
timeout-minutes: 20
1117

1218
steps:
1319
- name: Checkout
14-
uses: actions/checkout@v4
20+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
1521

1622
- name: Setup .NET
17-
uses: actions/setup-dotnet@v4
23+
uses: actions/setup-dotnet@67a3573c9a986a3f9c594539f4ab511d57bb3ce9 # v4.3.1
1824
with:
1925
dotnet-version: 8.0.x
2026

27+
- name: Cache NuGet packages
28+
uses: actions/cache@5a3ec84eff668545956fd18022155c47e93e2684 # v4.2.3
29+
with:
30+
path: ~/.nuget/packages
31+
key: ${{ runner.os }}-nuget-${{ hashFiles('**/*.csproj') }}
32+
restore-keys: ${{ runner.os }}-nuget-
33+
2134
- name: Restore
2235
run: dotnet restore CompanyManagementSystem.sln
2336

37+
- name: Build
38+
run: dotnet build CompanyManagementSystem.sln --configuration Release --no-restore
39+
2440
- name: Test with coverage
2541
run: |
2642
dotnet test Tests/Tests.csproj \
2743
--configuration Release \
44+
--no-build \
45+
--verbosity normal \
2846
--collect:"XPlat Code Coverage" \
29-
--results-directory TestResults
47+
--results-directory TestResults \
48+
--logger "trx;LogFileName=test-results.trx"
3049
31-
- name: Upload coverage artifacts
32-
uses: actions/upload-artifact@v4
50+
- name: Upload test results and coverage
51+
if: always()
52+
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
3353
with:
3454
name: test-results-and-coverage
35-
path: TestResults
55+
path: TestResults

.github/workflows/codeql-analysis.yml

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,22 @@ jobs:
2727

2828
steps:
2929
- name: Checkout repository
30-
uses: actions/checkout@v4
30+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
3131

3232
- name: Setup .NET
33-
uses: actions/setup-dotnet@v4
33+
uses: actions/setup-dotnet@67a3573c9a986a3f9c594539f4ab511d57bb3ce9 # v4.3.1
3434
with:
3535
dotnet-version: 8.0.x
3636

37+
- name: Cache NuGet packages
38+
uses: actions/cache@5a3ec84eff668545956fd18022155c47e93e2684 # v4.2.3
39+
with:
40+
path: ~/.nuget/packages
41+
key: ${{ runner.os }}-nuget-${{ hashFiles('**/*.csproj') }}
42+
restore-keys: ${{ runner.os }}-nuget-
43+
3744
- name: Initialize CodeQL
38-
uses: github/codeql-action/init@v3
45+
uses: github/codeql-action/init@820e3160e279568db735cee8ed8f8e77a6da7818 # v3.32.6
3946
with:
4047
languages: ${{ matrix.language }}
4148
queries: security-extended,security-and-quality
@@ -44,6 +51,6 @@ jobs:
4451
run: dotnet build CompanyManagementSystem.sln --configuration Release --no-restore || dotnet build CompanyManagementSystem.sln --configuration Release
4552

4653
- name: Perform CodeQL Analysis
47-
uses: github/codeql-action/analyze@v3
54+
uses: github/codeql-action/analyze@820e3160e279568db735cee8ed8f8e77a6da7818 # v3.32.6
4855
with:
4956
category: "/language:${{ matrix.language }}"

.github/workflows/gitleaks.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@ jobs:
1818
runs-on: ubuntu-latest
1919
steps:
2020
- name: Checkout repository
21-
uses: actions/checkout@v4
21+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
2222
with:
2323
fetch-depth: 0
2424

2525
- name: Run Gitleaks
26-
uses: gitleaks/gitleaks-action@v2
26+
uses: gitleaks/gitleaks-action@ff98106e4c7b2bc287b24eaf42907196329070c7 # v2.3.9
2727
env:
2828
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
2929
GITLEAKS_CONFIG: .gitleaks.toml

.github/workflows/owasp-zap.yml

Lines changed: 85 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ on:
66
pull_request:
77
branches: [main]
88
schedule:
9-
# Weekly scan on Wednesday at 2 AM UTC
109
- cron: "0 2 * * 3"
10+
workflow_dispatch:
1111

1212
permissions:
1313
contents: read
@@ -17,68 +17,133 @@ jobs:
1717
zap-baseline:
1818
name: ZAP Baseline Scan
1919
runs-on: ubuntu-latest
20+
timeout-minutes: 30
2021
services:
2122
sqlserver:
2223
image: mcr.microsoft.com/mssql/server:2022-latest
2324
env:
2425
ACCEPT_EULA: Y
25-
SA_PASSWORD: TestP@ssw0rd123!
26+
MSSQL_SA_PASSWORD: TestP@ssw0rd123!
2627
ports:
2728
- 1433:1433
2829
options: >-
29-
--health-cmd "/opt/mssql-tools18/bin/sqlcmd -S localhost -U sa -P 'TestP@ssw0rd123!' -C -Q 'SELECT 1'"
30-
--health-interval 10s
31-
--health-timeout 5s
32-
--health-retries 5
30+
--health-cmd "(/opt/mssql-tools18/bin/sqlcmd -S localhost -U sa -P 'TestP@ssw0rd123!' -C -Q 'SELECT 1' -b 2>/dev/null || /opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P 'TestP@ssw0rd123!' -Q 'SELECT 1' -b 2>/dev/null) && exit 0 || exit 1"
31+
--health-interval 15s
32+
--health-timeout 10s
33+
--health-retries 10
34+
--health-start-period 40s
3335
3436
steps:
3537
- name: Checkout repository
36-
uses: actions/checkout@v4
38+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
3739

3840
- name: Setup .NET
39-
uses: actions/setup-dotnet@v4
41+
uses: actions/setup-dotnet@67a3573c9a986a3f9c594539f4ab511d57bb3ce9 # v4.3.1
4042
with:
4143
dotnet-version: 8.0.x
4244

45+
- name: Cache NuGet packages
46+
uses: actions/cache@5a3ec84eff668545956fd18022155c47e93e2684 # v4.2.3
47+
with:
48+
path: ~/.nuget/packages
49+
key: ${{ runner.os }}-nuget-${{ hashFiles('**/*.csproj') }}
50+
restore-keys: ${{ runner.os }}-nuget-
51+
4352
- name: Restore and build
4453
run: |
4554
dotnet restore CompanyManagementSystem.sln
46-
dotnet build ERP.PL/ERP.PL.csproj --configuration Release --no-restore
55+
dotnet publish ERP.PL/ERP.PL.csproj --configuration Release --no-restore --output ./publish
56+
57+
- name: Wait for SQL Server to be ready
58+
run: |
59+
echo "Waiting for SQL Server to accept connections..."
60+
for i in $(seq 1 30); do
61+
if nc -z localhost 1433 2>/dev/null; then
62+
echo "SQL Server is accepting connections!"
63+
break
64+
fi
65+
echo "Attempt $i: SQL Server not ready yet..."
66+
sleep 3
67+
done
4768
4869
- name: Start application
4970
env:
5071
ASPNETCORE_ENVIRONMENT: Testing
51-
ASPNETCORE_URLS: http://localhost:5000
72+
ASPNETCORE_URLS: "http://0.0.0.0:5000"
5273
ConnectionStrings__DefaultConnection: "Server=localhost,1433;Database=ERPDB_ZAP;User Id=sa;Password=TestP@ssw0rd123!;TrustServerCertificate=True;"
5374
Database__ApplyMigrationsOnStartup: "true"
5475
Seed__Mode: "None"
76+
Logging__LogLevel__Default: "Warning"
5577
run: |
56-
dotnet run --project ERP.PL/ERP.PL.csproj --configuration Release --no-build &
57-
echo "Waiting for application to start..."
58-
for i in $(seq 1 30); do
59-
if curl -s -o /dev/null -w "%{http_code}" http://localhost:5000/health | grep -q "200"; then
60-
echo "Application is ready!"
78+
cd publish
79+
dotnet ERP.PL.dll > ../app.log 2>&1 &
80+
APP_PID=$!
81+
echo "APP_PID=$APP_PID" >> $GITHUB_ENV
82+
echo "Application started with PID $APP_PID"
83+
cd ..
84+
85+
echo "Waiting for application to become healthy..."
86+
READY=false
87+
for i in $(seq 1 60); do
88+
if curl -sf -o /dev/null -m 5 http://localhost:5000/health 2>/dev/null; then
89+
echo "Application is healthy and ready! (attempt $i)"
90+
READY=true
6191
break
6292
fi
63-
echo "Attempt $i: Waiting..."
93+
94+
# Check if process is still running
95+
if ! kill -0 $APP_PID 2>/dev/null; then
96+
echo "::error::Application process exited unexpectedly!"
97+
echo "=== Application Logs ==="
98+
cat app.log || true
99+
exit 1
100+
fi
101+
102+
echo "Attempt $i/60: Waiting for health check..."
64103
sleep 5
65104
done
66105
106+
if [ "$READY" != "true" ]; then
107+
echo "::error::Application did not become healthy within 5 minutes"
108+
echo "=== Application Logs ==="
109+
tail -100 app.log || true
110+
kill $APP_PID 2>/dev/null || true
111+
exit 1
112+
fi
113+
67114
- name: Run OWASP ZAP Baseline Scan
68-
uses: zaproxy/action-baseline@v0.14.0
115+
uses: zaproxy/action-baseline@7c4deb10e6261301961c86d65d54a516394f9aed # v0.14.0
69116
with:
70117
target: "http://localhost:5000"
71118
rules_file_name: ".zap/rules.tsv"
72119
cmd_options: "-a -j"
73-
allow_issue_writing: true
74-
fail_action: true
120+
allow_issue_writing: false
121+
fail_action: false
75122
artifact_name: "zap-report"
76123

124+
- name: Stop application
125+
if: always()
126+
run: |
127+
if [ -n "$APP_PID" ]; then
128+
echo "Stopping application (PID: $APP_PID)..."
129+
kill $APP_PID 2>/dev/null || true
130+
wait $APP_PID 2>/dev/null || true
131+
fi
132+
133+
- name: Upload application logs
134+
if: always()
135+
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
136+
with:
137+
name: app-logs
138+
path: app.log
139+
if-no-files-found: ignore
140+
77141
- name: Upload ZAP Report
78142
if: always()
79-
uses: actions/upload-artifact@v4
143+
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
80144
with:
81145
name: zap-security-report
82146
path: |
83147
report_html.html
84148
report_json.json
149+
if-no-files-found: ignore

.github/workflows/security-gate.yml

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ on:
88
branches: [main, develop]
99
pull_request:
1010
branches: [main, develop]
11+
workflow_dispatch:
1112

1213
permissions:
1314
contents: read
@@ -19,7 +20,7 @@ jobs:
1920
runs-on: ubuntu-latest
2021
steps:
2122
- name: Checkout
22-
uses: actions/checkout@v4
23+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
2324

2425
- name: Check for hardcoded secrets in config files
2526
run: |
@@ -93,15 +94,23 @@ jobs:
9394
build-and-test:
9495
name: Build Verification
9596
runs-on: ubuntu-latest
97+
timeout-minutes: 20
9698
steps:
9799
- name: Checkout
98-
uses: actions/checkout@v4
100+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
99101

100102
- name: Setup .NET
101-
uses: actions/setup-dotnet@v4
103+
uses: actions/setup-dotnet@67a3573c9a986a3f9c594539f4ab511d57bb3ce9 # v4.3.1
102104
with:
103105
dotnet-version: 8.0.x
104106

107+
- name: Cache NuGet packages
108+
uses: actions/cache@5a3ec84eff668545956fd18022155c47e93e2684 # v4.2.3
109+
with:
110+
path: ~/.nuget/packages
111+
key: ${{ runner.os }}-nuget-${{ hashFiles('**/*.csproj') }}
112+
restore-keys: ${{ runner.os }}-nuget-
113+
105114
- name: Restore
106115
run: dotnet restore CompanyManagementSystem.sln
107116

0 commit comments

Comments
 (0)