Skip to content

Commit 8581c7f

Browse files
committed
chore(*) speed up Github Action
1 parent 324bb39 commit 8581c7f

File tree

2 files changed

+207
-30
lines changed

2 files changed

+207
-30
lines changed

.github/workflows/codecov.yml

Lines changed: 101 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,112 @@ defaults:
77
shell: bash
88

99
jobs:
10-
codecov:
10+
build_deps:
11+
name: Build dependencies
1112
runs-on: ubuntu-latest
13+
14+
env:
15+
BUILD_CACHE_NONCE: 0
16+
1217
steps:
18+
- name: Set environment variables
19+
run: |
20+
echo "CACHE_ROOT=$HOME/cache-root" >> $GITHUB_ENV
21+
1322
- uses: actions/checkout@v2
1423
with:
1524
ref: ${{ github.ref }}
25+
26+
- name: Checkout SpiderLabs/ModSecurity
27+
uses: actions/checkout@v3
28+
with:
29+
repository: SpiderLabs/ModSecurity
30+
path: ModSecurity
31+
32+
- name: Get ModSecurity commit hash
33+
run: |
34+
cd ModSecurity
35+
echo "MODSECURITY_COMMIT_HASH=$(git rev-parse HEAD)" >> $GITHUB_ENV
36+
37+
- name: Lookup build cache
38+
uses: actions/cache@v3
39+
id: cache-deps
40+
with:
41+
path: ${{ env.CACHE_ROOT }}
42+
key: ${{ env.MODSECURITY_COMMIT_HASH }}-${{ env.BUILD_CACHE_NONCE }}
43+
44+
- name: Install dependencies
45+
if: steps.cache-deps.outputs.cache-hit != 'true'
46+
run: |
47+
sudo apt-get --yes update
48+
sudo apt-get install --yes libsodium23 libsodium-dev build-essential zlib1g-dev libpcre3 libpcre3-dev libssl-dev libxslt1-dev libxml2-dev libgeoip-dev libgd-dev libperl-dev libcurl4-openssl-dev
49+
50+
- name: Download and install ModSecurity
51+
if: steps.cache-deps.outputs.cache-hit != 'true'
52+
run: |
53+
cd ModSecurity
54+
./build.sh
55+
git submodule init
56+
git submodule update
57+
./configure --prefix=/usr/local/modsecurity
58+
make -j$(nproc)
59+
sudo make install
60+
61+
- name: Package dependencies
62+
if: steps.cache-deps.outputs.cache-hit != 'true'
63+
run: |
64+
mkdir -p ${{ env.CACHE_ROOT }}
65+
mkdir -p /tmp/cache/usr/local
66+
sudo cp -r /usr/local/modsecurity /tmp/cache/usr/local
67+
tar -C /tmp/cache/ -cvzf ${{ env.CACHE_ROOT }}/cache.tar.gz .
68+
69+
codecov:
70+
runs-on: ubuntu-latest
71+
needs: build_deps
72+
73+
env:
74+
BUILD_CACHE_NONCE: 0
75+
76+
steps:
77+
- name: Set environment variables
78+
run: |
79+
echo "CACHE_ROOT=$HOME/cache-root" >> $GITHUB_ENV
80+
1681
- uses: actions/setup-python@v2
1782
with:
1883
python-version: '3.x'
1984
architecture: 'x64'
85+
86+
- uses: actions/checkout@v2
87+
with:
88+
ref: ${{ github.ref }}
89+
90+
- name: Checkout SpiderLabs/ModSecurity
91+
uses: actions/checkout@v3
92+
with:
93+
repository: SpiderLabs/ModSecurity
94+
path: ModSecurity
95+
96+
- name: Get ModSecurity commit hash
97+
run: |
98+
cd ModSecurity
99+
echo "MODSECURITY_COMMIT_HASH=$(git rev-parse HEAD)" >> $GITHUB_ENV
100+
101+
- name: Lookup build cache
102+
uses: actions/cache@v3
103+
id: cache-deps
104+
with:
105+
path: ${{ env.CACHE_ROOT }}
106+
key: ${{ env.MODSECURITY_COMMIT_HASH }}-${{ env.BUILD_CACHE_NONCE }}
107+
108+
- name: Extract the deps
109+
run: sudo tar -C / -xzvf ${{ env.CACHE_ROOT }}/cache.tar.gz
110+
20111
- name: Install dependencies
21112
run: |
22113
sudo apt-get --yes update
23114
sudo apt-get install --yes libsodium23 libsodium-dev build-essential zlib1g-dev libpcre3 libpcre3-dev libssl-dev libxslt1-dev libxml2-dev libgeoip-dev libgd-dev libperl-dev libcurl4-openssl-dev gcovr
115+
24116
- name: Download nginx
25117
run: |
26118
sudo chmod 777 -R /usr/local/src
@@ -29,30 +121,21 @@ jobs:
29121
lastversion download nginx:stable
30122
mkdir nginx
31123
tar zxf nginx-*.tar.gz --directory nginx --strip-components=1
32-
- name: Download and install modsecurity
33-
run: |
34-
sudo chmod 777 -R /usr/local/src
35-
cd /usr/local/src
36-
git clone https://github.com/SpiderLabs/ModSecurity.git
37-
sudo chmod 777 -R /usr/local/src
38-
cd ModSecurity
39-
./build.sh
40-
git submodule init
41-
git submodule update
42-
./configure --prefix=/usr/local/modsecurity
43-
make -j$(nproc)
44-
sudo make install
124+
45125
- name: Download DaveGamble/cJSON.git
46126
run: |
47127
git clone -b v1.7.15 https://github.com/DaveGamble/cJSON.git lib/cjson
128+
48129
- name: Download troydhanson/uthash
49130
run: |
50131
git clone -b v2.3.0 https://github.com/troydhanson/uthash.git lib/uthash
132+
51133
- name: Configure nginx
52134
run: |
53135
cd /usr/local/src/nginx
54136
export LIB_MODSECURITY=/usr/local/modsecurity
55137
./configure --add-module=${{ github.workspace }} --with-http_realip_module --with-cc-opt='-fprofile-arcs -ftest-coverage -O0 -g3' --with-ld-opt='-lgcov'
138+
56139
- name: Install nginx
57140
run: |
58141
cd /usr/local/src/nginx
@@ -61,16 +144,19 @@ jobs:
61144
sudo useradd nginx -s /sbin/nologin -M
62145
sudo chmod 777 -R /usr/local/nginx
63146
sudo ln -s /usr/local/nginx/sbin/nginx /usr/local/bin/nginx
147+
64148
- name: Install Test::Nginx
65149
run: |
66150
sudo cpan Test::Nginx
151+
67152
- name: Test
68153
run: |
69154
sudo chmod 777 -R /tmp
70155
cd test/test-nginx
71156
export MODULE_TEST_PATH=/tmp/module_test
72157
sh ./init.sh
73158
exec sudo sh start.sh t/*.t
159+
74160
- name: Generate coverage report
75161
run: |
76162
sudo chmod -R 777 /usr/local/src
@@ -83,6 +169,7 @@ jobs:
83169
cp ${{ github.workspace }}/src/* /usr/local/src/empty/
84170
sudo chmod -R 777 ${{ github.workspace }}
85171
sudo chmod -R 777 /usr/local/src
172+
86173
- name: Run codacy-coverage-reporter
87174
uses: codacy/codacy-coverage-reporter-action@v1
88175
with:

.github/workflows/test.yml

Lines changed: 106 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -30,26 +30,121 @@ jobs:
3030
-H "Accept: application/vnd.github.v3+json" \
3131
https://api.github.com/repos/ADD-SP/ngx_waf/actions/workflows/${{ github.workflow }}.yml/dispatches \
3232
-d '{"ref":"refs/heads/current"}'
33+
34+
build_deps:
35+
name: Build dependencies
36+
runs-on: ubuntu-latest
37+
38+
env:
39+
BUILD_CACHE_NONCE: 0
40+
41+
steps:
42+
- name: Set environment variables
43+
run: |
44+
echo "CACHE_ROOT=$HOME/cache-root" >> $GITHUB_ENV
45+
46+
- uses: actions/checkout@v2
47+
with:
48+
ref: ${{ github.ref }}
49+
50+
- name: Checkout SpiderLabs/ModSecurity
51+
uses: actions/checkout@v3
52+
with:
53+
repository: SpiderLabs/ModSecurity
54+
path: ModSecurity
55+
56+
- name: Get ModSecurity commit hash
57+
run: |
58+
cd ModSecurity
59+
echo "MODSECURITY_COMMIT_HASH=$(git rev-parse HEAD)" >> $GITHUB_ENV
60+
61+
- name: Lookup build cache
62+
uses: actions/cache@v3
63+
id: cache-deps
64+
with:
65+
path: ${{ env.CACHE_ROOT }}
66+
key: ${{ env.MODSECURITY_COMMIT_HASH }}-${{ env.BUILD_CACHE_NONCE }}
67+
68+
- name: Install dependencies
69+
if: steps.cache-deps.outputs.cache-hit != 'true'
70+
run: |
71+
sudo apt-get --yes update
72+
sudo apt-get install --yes libsodium23 libsodium-dev build-essential zlib1g-dev libpcre3 libpcre3-dev libssl-dev libxslt1-dev libxml2-dev libgeoip-dev libgd-dev libperl-dev libcurl4-openssl-dev
73+
74+
- name: Download and install ModSecurity
75+
if: steps.cache-deps.outputs.cache-hit != 'true'
76+
run: |
77+
cd ModSecurity
78+
./build.sh
79+
git submodule init
80+
git submodule update
81+
./configure --prefix=/usr/local/modsecurity
82+
make -j$(nproc)
83+
sudo make install
84+
85+
- name: Package dependencies
86+
if: steps.cache-deps.outputs.cache-hit != 'true'
87+
run: |
88+
mkdir -p ${{ env.CACHE_ROOT }}
89+
mkdir -p /tmp/cache/usr/local
90+
sudo cp -r /usr/local/modsecurity /tmp/cache/usr/local
91+
tar -C /tmp/cache/ -cvzf ${{ env.CACHE_ROOT }}/cache.tar.gz .
92+
93+
3394
native:
3495
runs-on: ubuntu-latest
3596
if: ${{ github.event_name != 'schedule' }}
97+
needs: build_deps
98+
99+
env:
100+
BUILD_CACHE_NONCE: 0
101+
36102
strategy:
37103
matrix:
38104
nginx-version: ['stable', 'mainline']
39105
module-type: ['static', 'dynamic']
40106
pcre-version: ['pcre', 'pcre2']
107+
41108
steps:
42-
- uses: actions/checkout@v2
43-
with:
44-
ref: ${{ github.ref }}
109+
- name: Set environment variables
110+
run: |
111+
echo "CACHE_ROOT=$HOME/cache-root" >> $GITHUB_ENV
112+
45113
- uses: actions/setup-python@v2
46114
with:
47115
python-version: '3.x'
48116
architecture: 'x64'
117+
118+
- uses: actions/checkout@v2
119+
with:
120+
ref: ${{ github.ref }}
121+
122+
- name: Checkout SpiderLabs/ModSecurity
123+
uses: actions/checkout@v3
124+
with:
125+
repository: SpiderLabs/ModSecurity
126+
path: ModSecurity
127+
128+
- name: Get ModSecurity commit hash
129+
run: |
130+
cd ModSecurity
131+
echo "MODSECURITY_COMMIT_HASH=$(git rev-parse HEAD)" >> $GITHUB_ENV
132+
133+
- name: Lookup build cache
134+
uses: actions/cache@v3
135+
id: cache-deps
136+
with:
137+
path: ${{ env.CACHE_ROOT }}
138+
key: ${{ env.MODSECURITY_COMMIT_HASH }}-${{ env.BUILD_CACHE_NONCE }}
139+
140+
- name: Extract the deps
141+
run: sudo tar -C / -xzvf ${{ env.CACHE_ROOT }}/cache.tar.gz
142+
49143
- name: Install dependencies
50144
run: |
51145
sudo apt-get --yes update
52146
sudo apt-get install --yes libsodium23 libsodium-dev build-essential zlib1g-dev libpcre3 libpcre3-dev libssl-dev libxslt1-dev libxml2-dev libgeoip-dev libgd-dev libperl-dev libcurl4-openssl-dev
147+
53148
- name: Download nginx-${{ matrix.nginx-version }}
54149
run: |
55150
sudo chmod 777 -R /usr/local/src
@@ -58,6 +153,7 @@ jobs:
58153
lastversion download nginx:${{ matrix.nginx-version }}
59154
mkdir nginx
60155
tar zxf nginx-*.tar.gz --directory nginx --strip-components=1
156+
61157
- name: Download PCRE
62158
if: ${{ matrix.pcre-version == 'pcre' || (matrix.pcre-version == 'pcre2' && matrix.nginx-version == 'stable') }}
63159
run: |
@@ -67,6 +163,7 @@ jobs:
67163
mkdir pcre
68164
tar zxf pcre.tar.gz --directory pcre --strip-components=1
69165
sudo chmod 777 -R /usr/local/src
166+
70167
- name: Download PCRE2
71168
if: ${{ matrix.pcre-version == 'pcre2' && matrix.nginx-version == 'mainline' }}
72169
run: |
@@ -76,25 +173,15 @@ jobs:
76173
mkdir pcre
77174
tar zxf pcre.tar.gz --directory pcre --strip-components=1
78175
sudo chmod 777 -R /usr/local/src
79-
- name: Download and install modsecurity
80-
run: |
81-
sudo chmod 777 -R /usr/local/src
82-
cd /usr/local/src
83-
git clone https://github.com/SpiderLabs/ModSecurity.git
84-
sudo chmod 777 -R /usr/local/src
85-
cd ModSecurity
86-
./build.sh
87-
git submodule init
88-
git submodule update
89-
./configure --prefix=/usr/local/modsecurity
90-
make -j$(nproc)
91-
sudo make install
176+
92177
- name: Download cjson
93178
run: |
94179
git clone -b v1.7.15 https://github.com/DaveGamble/cJSON.git lib/cjson
180+
95181
- name: Download uthash
96182
run: |
97183
git clone -b v2.3.0 https://github.com/troydhanson/uthash.git lib/uthash
184+
98185
- name: Configure ${{ matrix.module-type }}
99186
run: |
100187
cd /usr/local/src/nginx
@@ -105,6 +192,7 @@ jobs:
105192
fi
106193
export LIB_MODSECURITY=/usr/local/modsecurity
107194
./configure ${opt}=${{ github.workspace }} --with-pcre=/usr/local/src/pcre --with-http_realip_module --with-cc-opt='-Wno-unused-but-set-variable -Wno-unused-function -fstack-protector-strong'
195+
108196
- name: Install nginx-${{ matrix.nginx-version }}
109197
run: |
110198
cd /usr/local/src/nginx
@@ -113,9 +201,11 @@ jobs:
113201
sudo useradd nginx -s /sbin/nologin -M
114202
sudo chmod 777 -R /usr/local/nginx
115203
sudo ln -s /usr/local/nginx/sbin/nginx /usr/local/bin/nginx
204+
116205
- name: Install Test::Nginx
117206
run: |
118207
sudo cpan Test::Nginx
208+
119209
- name: Test
120210
run: |
121211
sudo chmod 777 -R /tmp

0 commit comments

Comments
 (0)