Skip to content

Commit 33bddd3

Browse files
author
kadraman
committed
chore: updating workflows
1 parent 33592c6 commit 33bddd3

5 files changed

Lines changed: 120 additions & 111 deletions

File tree

.github/workflows/ci.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,3 +67,18 @@ jobs:
6767
tags: |
6868
ghcr.io/${{ github.repository_owner }}/insecurewebapp:${{ github.sha }}
6969
ghcr.io/${{ github.repository_owner }}/insecurewebapp:latest
70+
71+
cleanup-images:
72+
name: Cleanup old GHCR images
73+
needs: build-and-push
74+
runs-on: ubuntu-latest
75+
steps:
76+
- name: Delete old GHCR package versions (keep last 5)
77+
uses: actions/delete-package-versions@v5
78+
with:
79+
package-name: insecurewebapp
80+
owner: ${{ github.repository_owner }}
81+
min-versions-to-keep: 5
82+
package-type: container
83+
env:
84+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/codeql.yml

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ jobs:
8585

8686
# Initializes the CodeQL tools for scanning.
8787
- name: Initialize CodeQL
88-
uses: github/codeql-action/init@v3
88+
uses: github/codeql-action/init@v4
8989
with:
9090
languages: ${{ matrix.language }}
9191
build-mode: ${{ matrix.build-mode }}
@@ -114,7 +114,7 @@ jobs:
114114
115115
- name: Perform CodeQL Analysis
116116
id: analyze
117-
uses: github/codeql-action/analyze@v3
117+
uses: github/codeql-action/analyze@v4
118118
with:
119119
category: "/language:${{matrix.language}}"
120120
output: sarif-out/${{ matrix.language }}
@@ -139,3 +139,37 @@ jobs:
139139
path: export/*.sarif
140140
if-no-files-found: error
141141
retention-days: 30
142+
143+
merge-sarif:
144+
name: Merge SARIF files
145+
needs: analyze
146+
runs-on: ubuntu-latest
147+
permissions:
148+
security-events: write
149+
contents: read
150+
steps:
151+
- name: Download all SARIF artifacts
152+
uses: actions/download-artifact@v4
153+
with:
154+
path: artifacts
155+
156+
- name: Install jq
157+
run: sudo apt-get update && sudo apt-get install -y jq
158+
159+
- name: Merge SARIF files
160+
run: |
161+
set -euo pipefail
162+
mkdir -p export
163+
# Find all SARIF files downloaded from matrix jobs and merge their `runs` arrays.
164+
find artifacts -type f -name '*.sarif' -print0 | xargs -0 jq -s '{version: (.[0].version), "$schema": (.[0]."$schema"), runs: map(.runs) | add}' > export/combined_${{ github.run_id }}.sarif
165+
# Also copy individual SARIF files into export/ for convenience
166+
find artifacts -type f -name '*.sarif' -exec cp {} export/ \;
167+
echo "Prepared $(ls -1 export | wc -l) SARIF files in export/"
168+
169+
- name: Upload merged SARIF artifact
170+
uses: actions/upload-artifact@v4
171+
with:
172+
name: sarif-combined-${{ github.run_id }}
173+
path: export/*.sarif
174+
if-no-files-found: error
175+
retention-days: 30

.github/workflows/fod.yml

Lines changed: 9 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,11 @@ on:
3838
- 'tests/**'
3939
- '*.md'
4040
- 'LICENSE'
41-
#branches-ignore:
42-
# - main
43-
# - develop
4441
branches:
45-
- '**' # matches every branch
42+
- main
43+
- develop
44+
- feature/**
45+
- bugfix/**
4646
pull_request:
4747
branches: [ main, develop ]
4848

@@ -56,11 +56,7 @@ on:
5656
runFoDOSSScan:
5757
description: 'Carry out OSS scan using OpenText Core Application Security'
5858
required: false
59-
default: 'true'
60-
deployApp:
61-
description: 'Deploy App to Azure'
62-
required: false
63-
default: 'true'
59+
default: 'true'
6460
runFoDDASTScan:
6561
description: 'Carry out DAST scan using OpenText Core Application Security'
6662
required: false
@@ -94,48 +90,7 @@ jobs:
9490
echo "Running in a branch pipeline ..."
9591
echo "FOD_RELEASE=${{ env.DEFAULT_APP_NAME }}${{ vars.FORTIFY_APP_NAME_POSTFIX }}:${{ github.ref_name }}" >> $GITHUB_OUTPUT
9692
echo "FOD_PARENT_RELEASE=${{ env.DEFAULT_APP_NAME }}${{ vars.FORTIFY_APP_NAME_POSTFIX }}:${{ env.DEFAULT_PARENT_RELEASE_NAME }}" >> $GITHUB_OUTPUT
97-
fi
98-
99-
Build-And-Unit-Test:
100-
runs-on: ubuntu-latest
101-
needs: [ Env-Prepare ]
102-
steps:
103-
- name: Checkout
104-
uses: actions/checkout@v4
105-
- name: Set up Python
106-
uses: actions/setup-python@v5
107-
with:
108-
python-version: ${{ env.PYTHON_VERSION }}
109-
cache: 'pip'
110-
- name: Create and start virtual environment
111-
run: |
112-
python -m venv venv
113-
source venv/bin/activate
114-
- name: Install dependencies
115-
run: |
116-
pip install -r requirements.txt
117-
pip install pytest pytest-md pytest-emoji
118-
- uses: pavelzw/pytest-action@v2
119-
with:
120-
emoji: false
121-
verbose: false
122-
job-summary: true
123-
# Publish test results
124-
#- name: Publish Test Results
125-
# uses: EnricoMi/publish-unit-test-result-action@v2
126-
# if: always()
127-
# with:
128-
# files: |
129-
# build/test-results/**/*.xml
130-
# build/test-results/**/*.trx
131-
# build/test-results/**/*.json
132-
- name: Upload artifact for deployment jobs
133-
uses: actions/upload-artifact@v4
134-
with:
135-
name: python-app
136-
path: |
137-
.
138-
!venv/
93+
fi
13994
14095
FoD-SAST-Scan:
14196
runs-on: ubuntu-latest
@@ -194,7 +149,7 @@ jobs:
194149
FoD-OSS-Scan:
195150
runs-on: ubuntu-latest
196151
if: ${{ (github.event_name == 'push') || (github.event_name == 'pull_request') || (github.event.inputs.runFoDOSSScan == 'true') }}
197-
needs: [ Env-Prepare, FoD-SAST-Scan ] # for creating new FoD release (if required)
152+
needs: [ Env-Prepare ]
198153
env:
199154
FOD_RELEASE: ${{ needs.Env-Prepare.outputs.FOD_RELEASE }}
200155
FOD_PARENT_RELEASE: ${{ needs.Env-Prepare.outputs.FOD_PARENT_RELEASE }}
@@ -227,46 +182,11 @@ jobs:
227182
FOD_CLIENT_SECRET: ${{ secrets.FOD_CLIENT_SECRET }}
228183
PACKAGE_FILE: "fortifypackage.zip"
229184
FOD_RELEASE: ${{ env.FOD_RELEASE }}
230-
231-
Deploy-App:
232-
permissions:
233-
contents: none
234-
runs-on: ubuntu-latest
235-
needs: [ Build-And-Unit-Test, FoD-SAST-Scan, FoD-OSS-Scan ]
236-
environment:
237-
name: 'Development'
238-
#url: ${{ steps.deploy-to-webapp.outputs.webapp-url }}
239-
if: ${{ success() && github.ref_name == github.event.repository.default_branch }}
240-
steps:
241-
- name: Download artifact from build job
242-
uses: actions/download-artifact@v4
243-
with:
244-
name: python-app
245-
path: .
246-
# Example deployment to azure web app
247-
# This is commented out as it is done in workflows/azure_webapp..yml
248-
#- name: 'Deploy to Azure Web App'
249-
# id: deploy-to-webapp
250-
# uses: azure/webapps-deploy@v3
251-
# with:
252-
# app-name: ${{ env.AZURE_WEBAPP_NAME }}
253-
# publish-profile: ${{ secrets.AZUREAPPSERVICE_PUBLISHPROFILE_94429323A56E479BA44DAB94865DCF4A }}
254-
255-
Functional-Test:
256-
runs-on: ubuntu-latest
257-
if: ${{ always() }}
258-
needs: [ Env-Prepare, Deploy-App ]
259-
env:
260-
FOD_RELEASE: ${{ needs.Env-Prepare.outputs.FOD_RELEASE }}
261-
FOD_PARENT_RELEASE: ${{ needs.Env-Prepare.outputs.FOD_PARENT_RELEASE }}
262-
steps:
263-
- name: Checkout
264-
uses: actions/checkout@v4
265-
185+
266186
FoD-DAST-Scan:
267187
runs-on: ubuntu-latest
268188
if: ${{ (github.ref_name == github.event.repository.default_branch) && (github.event.inputs.runFoDDASTScan == 'true') }}
269-
needs: [ Env-Prepare, Deploy-App ]
189+
needs: [ Env-Prepare, FoD-SAST-Scan, FoD-OSS-Scan ]
270190
env:
271191
FOD_RELEASE: ${{ needs.Env-Prepare.outputs.FOD_RELEASE }}
272192
FOD_PARENT_RELEASE: ${{ needs.Env-Prepare.outputs.FOD_PARENT_RELEASE }}
@@ -323,13 +243,3 @@ jobs:
323243
FOD_CLIENT_ID: ${{ secrets.FOD_CLIENT_ID }}
324244
FOD_CLIENT_SECRET: ${{ secrets.FOD_CLIENT_SECRET }}
325245
FOD_RELEASE: ${{ env.FOD_RELEASE }}
326-
327-
#Release-To-Prod:
328-
# runs-on: ubuntu-latest
329-
# needs: [ Env-Prepare, Verify-Security-Policy ]
330-
# env:
331-
# FOD_RELEASE: ${{ needs.Env-Prepare.outputs.FOD_RELEASE }}
332-
# FOD_PARENT_RELEASE: ${{ needs.Env-Prepare.outputs.FOD_PARENT_RELEASE }}
333-
# steps:
334-
# - name: Checkout
335-
# uses: actions/checkout@v4

.github/workflows/semgrep.yml

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
name: Semgrep (SARIF export)
22

33
on:
4-
push:
5-
branches: [ "main" ]
6-
pull_request:
7-
branches: [ "main" ]
84
workflow_dispatch:
95
inputs:
106
upload_sarif:
11-
description: 'Set to "true" to upload SARIF to GitHub Code Scanning'
7+
description: 'Set to "true" to upload SARIF artifact to GitHub'
8+
required: false
9+
default: 'true'
10+
import_sarif:
11+
description: 'Set to "true" to import SARIF results to GitHub Code Scanning'
1212
required: false
1313
default: 'false'
1414

@@ -19,8 +19,6 @@ permissions:
1919

2020
jobs:
2121
semgrep:
22-
# only run this job if the repository is origin 'kadraman/InsecureWeb not forked repositories
23-
if: ${{ github.repository == 'kadraman/InsecureWebApp' }}
2422
runs-on: ubuntu-latest
2523

2624
steps:
@@ -49,9 +47,9 @@ jobs:
4947
# Optional Semgrep App token if you use Semgrep Cloud Platform features
5048
# SEMGREP_APP_TOKEN: ${{ secrets.SEMGREP_APP_TOKEN }}
5149

52-
- name: Upload SARIF to GitHub Code Scanning
53-
if: ${{ github.event.inputs.upload_sarif == 'true' }}
54-
uses: github/codeql-action/upload-sarif@v3
50+
- name: Import SARIF results to GitHub Code Scanning
51+
if: ${{ github.event.inputs.import_sarif == 'true' }}
52+
uses: github/codeql-action/upload-sarif@v4
5553
with:
5654
sarif_file: sarif-out/semgrep.sarif
5755
category: "semgrep"
@@ -64,6 +62,7 @@ jobs:
6462
cp sarif-out/semgrep.sarif "export/semgrep_${ts}.sarif"
6563
6664
- name: Upload SARIF artifact
65+
if: ${{ github.event.inputs.upload_sarif == 'true' }}
6766
uses: actions/upload-artifact@v4
6867
with:
6968
name: sarif-semgrep-${{ github.run_id }}

.github/workflows/trivy.yml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
name: Trivy container SARIF scan
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
upload_sarif:
7+
description: 'Set to "true" to upload SARIF artifact to GitHub'
8+
required: false
9+
default: 'true'
10+
import_sarif:
11+
description: 'Set to "true" to import SARIF results to GitHub Code Scanning'
12+
required: false
13+
default: 'false'
14+
15+
permissions:
16+
contents: read
17+
security-events: write # required to upload SARIF to Code Scanning
18+
actions: read
19+
20+
jobs:
21+
scan:
22+
name: Scan GHCR image with Trivy
23+
runs-on: ubuntu-latest
24+
steps:
25+
- name: Set image
26+
run: echo "IMAGE=ghcr.io/${{ github.repository_owner }}/insecurewebapp:latest" >> $GITHUB_ENV
27+
28+
- name: Pull image
29+
run: docker pull $IMAGE
30+
31+
- name: Run Trivy (SARIF)
32+
run: |
33+
set -euo pipefail
34+
# Run Trivy in a container and output SARIF to a file
35+
docker run --rm -v /var/run/docker.sock:/var/run/docker.sock -v "$PWD:/work" aquasecurity/trivy:latest image --format sarif -o /work/trivy.sarif "$IMAGE"
36+
37+
- name: Import SARIF results to GitHub Code Scanning
38+
if: ${{ github.event.inputs.import_sarif == 'true' }}
39+
uses: github/codeql-action/upload-sarif@v4
40+
with:
41+
sarif_file: trivy.sarif
42+
category: "trivy"
43+
44+
- name: Upload SARIF artifact
45+
if: ${{ github.event.inputs.upload_sarif == 'true' }}
46+
uses: actions/upload-artifact@v4
47+
with:
48+
name: trivy-sarif-${{ github.run_id }}
49+
path: trivy.sarif
50+
if-no-files-found: error
51+
retention-days: 30

0 commit comments

Comments
 (0)