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
1212permissions :
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
0 commit comments