44 push :
55 branches : [dev, main]
66
7+ concurrency :
8+ group : tests-${{ github.ref }}
9+ cancel-in-progress : true
10+
711jobs :
812 codeql :
913 uses : ./.github/workflows/codeql.yml
@@ -12,40 +16,143 @@ jobs:
1216 contents : read
1317 security-events : write
1418
15- setup :
19+ tag :
20+ runs-on : ubuntu-latest
21+ outputs :
22+ bw_tag : ${{ steps.tag.outputs.bw_tag }}
23+ steps :
24+ - name : Resolve latest stable BunkerWeb tag
25+ id : tag
26+ env :
27+ GH_TOKEN : ${{ github.token }}
28+ run : |
29+ # Always test against the latest STABLE BunkerWeb release, resolved at
30+ # runtime so it never goes stale. GitHub's releases/latest endpoint
31+ # excludes drafts and pre-releases (rc/beta), giving us "stable".
32+ # Same tag on every branch (dev and main) — there is no pinned version.
33+ # `|| true`: a 404 (no stable release yet) or rate-limit makes gh exit
34+ # non-zero, which under `bash -e` would abort the step here with a raw
35+ # error. Swallow it so the empty tag falls through to the case below
36+ # and reports our own diagnostic.
37+ tag="$(gh api repos/bunkerity/bunkerweb/releases/latest --jq .tag_name || true)"
38+ tag="${tag#v}" # release tag may be "v1.6.1"; Docker tags have no "v"
39+ case "$tag" in
40+ "" | *-*)
41+ echo "::error::could not resolve a stable BunkerWeb tag (got '${tag:-<empty>}')"
42+ exit 1
43+ ;;
44+ esac
45+ echo "Resolved latest stable BunkerWeb tag: $tag"
46+ echo "bw_tag=$tag" >> "$GITHUB_OUTPUT"
47+
48+ lint :
1649 runs-on : ubuntu-latest
1750 steps :
1851 - name : Checkout source code
19- uses : actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
52+ uses : actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
53+ - name : Set up Python
54+ uses : actions/setup-python@ece7cb06caefa5fff74198d8649806c4678c61a1 # v6.3.0
55+ with :
56+ python-version : " 3.11"
57+ - name : Install pre-commit
58+ run : pip install pre-commit
59+ - name : Install Lua toolchain
60+ # The luacheck pre-commit hook is language:lua and needs luarocks on the
61+ # runner to bootstrap its environment.
62+ run : |
63+ sudo apt-get update
64+ sudo apt-get install -y lua5.4 liblua5.4-dev luarocks
65+ - name : Set up Node
66+ uses : actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0
67+ with :
68+ node-version : " 22"
69+ cache : " npm"
70+ - name : Install Prettier
71+ # The prettier hook is language:system and resolves prettier from the
72+ # repo's pinned package-lock.json via npx.
73+ run : npm ci
74+ - name : Run pre-commit
75+ run : pre-commit run --all-files
76+
77+ unit :
78+ runs-on : ubuntu-latest
79+ strategy :
80+ fail-fast : false
81+ matrix :
82+ lang : [go, python, lua]
83+ steps :
84+ - name : Checkout source code
85+ uses : actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
86+
87+ # --- Go : coraza API service ---
88+ - name : Set up Go
89+ if : matrix.lang == 'go'
90+ uses : actions/setup-go@924ae3a1cded613372ab5595356fb5720e22ba16 # v6.5.0
91+ with :
92+ go-version : " 1.25"
93+ - name : Run Go unit tests
94+ if : matrix.lang == 'go'
95+ working-directory : coraza/api
96+ run : |
97+ # No go.sum is committed (the Dockerfile resolves deps at build time),
98+ # so populate it before testing. Build tag must match the binary.
99+ go mod tidy
100+ go test -tags=coraza.rule.multiphase_evaluation ./...
101+
102+ # --- Python : ui/actions.py ---
103+ - name : Set up Python
104+ if : matrix.lang == 'python'
105+ uses : actions/setup-python@ece7cb06caefa5fff74198d8649806c4678c61a1 # v6.3.0
106+ with :
107+ python-version : " 3.11"
108+ - name : Run Python unit tests
109+ if : matrix.lang == 'python'
110+ run : |
111+ pip install pytest
112+ pytest tests/ -q
20113
21- - name : Get BW tag
114+ # --- Lua : busted specs ---
115+ - name : Run Lua unit tests
116+ if : matrix.lang == 'lua'
22117 run : |
23- if [ "$GITHUB_REF" = "refs/heads/main" ] ; then
24- echo "BW_TAG=1.6.1" >> $GITHUB_ENV
25- else
26- echo "BW_TAG=dev" >> $GITHUB_ENV
27- fi
118+ sudo apt-get update
119+ # liblua5.4-dev provides headers for busted's C deps; pin the luarocks
120+ # tree to 5.4 so the busted CLI runs against the lua5.4 we installed.
121+ sudo apt-get install -y lua5.4 liblua5.4-dev luarocks
122+ sudo luarocks --lua-version=5.4 install busted
123+ busted
28124
125+ integration :
126+ needs : [tag, lint, unit]
127+ runs-on : ubuntu-latest
128+ strategy :
129+ fail-fast : false
130+ matrix :
131+ plugin : [clamav, cloudflare, coraza, virustotal, authentik, notifier]
132+ steps :
133+ - name : Checkout source code
134+ uses : actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
29135 - name : Login to Docker Hub
30- uses : docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567 # v3.3 .0
136+ uses : docker/login-action@650006c6eb7dba73a995cc03b0b2d7f5ca915bee # v4.2 .0
31137 with :
32138 username : ${{ secrets.DOCKER_USERNAME }}
33139 password : ${{ secrets.DOCKER_TOKEN }}
34-
35140 - name : Pull and build BW
36- run : ./.tests/bw.sh "${{ env.BW_TAG }}"
37-
38- - name : Run ClamAV tests
39- run : ./.tests/clamav.sh
40-
41- - name : Run Coraza tests
42- run : ./.tests/coraza.sh
43-
44- - name : Run VirusTotal tests
45- run : ./.tests/virustotal.sh
46- env :
47- VIRUSTOTAL_API_KEY : ${{ secrets.VIRUSTOTAL_API_KEY }}
141+ run : bash .tests/bw.sh "${{ needs.tag.outputs.bw_tag }}"
142+ - name : Run ${{ matrix.plugin }} tests
143+ run : bash .tests/${{ matrix.plugin }}.sh
48144
145+ build-push :
146+ needs : [tag, integration]
147+ if : github.ref == 'refs/heads/main'
148+ runs-on : ubuntu-latest
149+ steps :
150+ - name : Checkout source code
151+ uses : actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
152+ - name : Login to Docker Hub
153+ uses : docker/login-action@650006c6eb7dba73a995cc03b0b2d7f5ca915bee # v4.2.0
154+ with :
155+ username : ${{ secrets.DOCKER_USERNAME }}
156+ password : ${{ secrets.DOCKER_TOKEN }}
49157 - name : Build and push APIs
50- if : env.BW_TAG == '1.6.1'
51- run : ./.tests/build-push.sh "${{ env.BW_TAG }}"
158+ run : bash .tests/build-push.sh "${{ needs.tag.outputs.bw_tag }}"
0 commit comments