chore(ci): use temporary branch in PR events and turn off push trigge… #1216
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Tests | |
on: | |
pull_request: | |
push: | |
branches: | |
- master | |
env: | |
KONG_VERSION: master | |
BUILD_ROOT: ${{ github.workspace }}/kong/bazel-bin/build | |
concurrency: | |
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }} | |
cancel-in-progress: true | |
jobs: | |
build: | |
name: Build dependencies | |
runs-on: ubuntu-22.04 | |
permissions: | |
contents: write # required to create branch | |
steps: | |
- name: Checkout source code | |
uses: actions/checkout@v3 | |
- name: Checkout Kong source code | |
uses: actions/checkout@v3 | |
with: | |
repository: kong/kong | |
ref: ${{ env.KONG_VERSION }} | |
path: kong | |
- name: Set the LUA_KONG_NGINX_MODULE in kong/.requirements | |
run: | | |
cd kong | |
# always use the commit ID, even if it's a PR merge; we will push the commit to temporary branch | |
# so that we can cache by commit ID instead of literal PR branch name | |
branch=${GITHUB_REF} | |
branch=$(echo "$branch" | sed 's/\//\\\//g') | |
sed -i "s/LUA_KONG_NGINX_MODULE=.\+/LUA_KONG_NGINX_MODULE=${branch}/" .requirements | |
cat .requirements | |
- name: Lookup build cache | |
id: cache-deps | |
uses: actions/cache@v3 | |
with: | |
path: | | |
${{ env.BUILD_ROOT }} | |
key: ${{ hashFiles('src/**', 'lualib/**', '.github/workflows/tests.yml', 'kong/.requirements') }} | |
- name: Push PR merge to a temporary branch | |
# Push the temporary commit to a branch so that we can reference in build kong | |
if: github.event_name == 'pull_request' && steps.cache-deps.outputs.cache-hit != 'true' | |
run: | | |
git push https://oauth2:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}.git HEAD:refs/heads/${{ github.head_ref }}-merge | |
- name: Install packages | |
if: steps.cache-deps.outputs.cache-hit != 'true' | |
run: | | |
sudo apt update | |
sudo apt install libyaml-dev valgrind libprotobuf-dev cpanminus net-tools libpcre3-dev build-essential | |
- name: Build Kong | |
if: steps.cache-deps.outputs.cache-hit != 'true' | |
env: | |
GH_TOKEN: ${{ github.token }} | |
run: | | |
cd kong | |
make build-kong | |
make build-venv | |
BUILD_PREFIX=$BUILD_ROOT/kong-dev | |
export PATH="$BUILD_PREFIX/bin:$BUILD_PREFIX/openresty/nginx/sbin:$BUILD_PREFIX/openresty/bin:$PATH" | |
chmod +rw -R $BUILD_PREFIX | |
nginx -V | |
ldd $(which nginx) | |
luarocks | |
- name: Delete temporary branch | |
if: always() && github.event_name == 'pull_request' && steps.cache-deps.outputs.cache-hit != 'true' | |
run: | | |
git push https://oauth2:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}.git --delete refs/heads/${{ github.head_ref }}-merge | |
test: | |
name: Test | |
runs-on: ubuntu-22.04 | |
needs: build | |
steps: | |
- name: Checkout source code | |
uses: actions/checkout@v3 | |
- name: Checkout Kong source code | |
uses: actions/checkout@v3 | |
with: | |
repository: kong/kong | |
ref: ${{ env.KONG_VERSION }} | |
path: kong | |
- name: Set the LUA_KONG_NGINX_MODULE in kong/.requirements | |
run: | | |
cd kong | |
branch="" | |
if [ ${{ github.event_name }} == 'pull_request' ]; then | |
branch=${GITHUB_HEAD_REF} | |
else | |
branch=${GITHUB_REF} | |
fi | |
branch=$(echo "$branch" | sed 's/\//\\\//g') | |
sed -i "s/LUA_KONG_NGINX_MODULE=.\+/LUA_KONG_NGINX_MODULE=${branch}/" .requirements | |
cat .requirements | |
- name: Load build cache | |
id: cache-deps | |
uses: actions/cache@v3 | |
with: | |
path: | | |
${{ env.BUILD_ROOT }} | |
key: ${{ hashFiles('src/**', 'lualib/**', '.github/workflows/tests.yml', 'kong/.requirements') }} | |
- name: Install packages | |
run: | | |
sudo apt update | |
sudo apt install libyaml-dev valgrind libprotobuf-dev cpanminus net-tools libpcre3-dev build-essential | |
- name: Install Test::Nginx | |
run: | | |
if [ ! -e perl ]; then | |
sudo cpanm --notest Test::Nginx > build.log 2>&1 || (cat build.log && exit 1) | |
cp -r /usr/local/share/perl/ . | |
else | |
sudo cp -r perl /usr/local/share | |
fi | |
- name: Run Test | |
run: | | |
source ${{ env.BUILD_ROOT }}/kong-dev-venv.sh | |
nginx -V | |
resty -V | |
luarocks --version | |
openssl version | |
prove -r t | |
- name: Run Test with Valgrind | |
run: | | |
source ${{ env.BUILD_ROOT }}/kong-dev-venv.sh | |
export TEST_NGINX_VALGRIND='--num-callers=100 -q --tool=memcheck --leak-check=full --show-possibly-lost=no --gen-suppressions=all --suppressions=valgrind.suppress --track-origins=yes' TEST_NGINX_TIMEOUT=60 TEST_NGINX_SLEEP=1 | |
export TEST_NGINX_USE_VALGRIND=1 | |
nginx -V | |
resty -V | |
luarocks --version | |
openssl version | |
# fail if definite leak found | |
prove -r t 2>&1 | tee /dev/stderr | grep -q "match-leak-kinds: definite" && exit 1 || exit 0 |