-
-
Notifications
You must be signed in to change notification settings - Fork 716
55 lines (53 loc) · 2.1 KB
/
generate_policies.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
name: Generate Scan Policies from Policy Tags
on:
schedule: # The start of every Friday
- cron: '0 0 * * 5'
workflow_dispatch:
permissions:
contents: write
pull-requests: write
jobs:
update-policies:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
persist-credentials: false
path: zap-extensions
fetch-depth: 0
- name: Create Policies
run: |
# Run the ZAP script
docker run -v $(pwd):/zap/wrk/:rw --user root -t ghcr.io/zaproxy/zaproxy:nightly ./zap.sh -addoninstall ascanrulesAlpha -silent -script /zap/wrk/zap-extensions/.github/scripts/generateScanPolicies.js -cmd
- name: Attach Policies
uses: actions/upload-artifact@v4
with:
name: Policies
path: 'zap-extensions/addOns/scanpolicies/src/main/zapHomeFiles/policies/*.policy'
- name: Update Scan Policies
run: |
export BASE=$(pwd)
# Setup git details
export GITHUB_USER=zapbot
git config --global user.email "[email protected]"
git config --global user.name $GITHUB_USER
export GITHUB_TOKEN=${{ secrets.ZAPBOT_TOKEN }}
BRANCH=scan-policies-updt
cd zap-extensions
SRC_BASE="zaproxy/zap-extensions@"$(git log -1 --format=format:%h)
git checkout -b $BRANCH
git remote add upstream https://github.com/zaproxy/zap-extensions.git
git fetch upstream
# Update the index to be sure git is aware of changes
git update-index -q --refresh
git add .
## If there are changes: comment, commit, PR
if ! git diff-index --quiet HEAD --; then
./gradlew :addOns:scanpolicies:updateChangelog --change="- Updated based on Rules' Policy Tag assignments."
git remote set-url origin https://$GITHUB_USER:[email protected]/$GITHUB_USER/zap-extensions.git
git add .
git commit -m "Update scan policies based on Tags" -m "Updates based on $SRC_BASE" --signoff
git push --set-upstream origin $BRANCH --force
gh pr create --fill
fi