From 5f6e055321034d322a87566c84eaf940e2953125 Mon Sep 17 00:00:00 2001 From: Wangchong Zhou Date: Thu, 18 Apr 2024 11:46:52 +0800 Subject: [PATCH 1/3] chore(ci): use temporary branch in PR events and turn off push trigger on PR --- .github/workflows/tests.yml | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 10d24289..b758a117 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -3,6 +3,8 @@ name: Tests on: pull_request: push: + branches: + - master env: KONG_VERSION: master @@ -16,6 +18,8 @@ jobs: build: name: Build dependencies runs-on: ubuntu-22.04 + permissions: + contents: write # required to create branch steps: - name: Checkout source code @@ -34,7 +38,7 @@ jobs: branch="" if [ ${{ github.event_name }} == 'pull_request' ]; then - branch=${GITHUB_HEAD_REF} + branch=${GITHUB_HEAD_REF}/merge else branch=${GITHUB_REF} fi @@ -51,6 +55,12 @@ jobs: ${{ 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: | @@ -72,6 +82,11 @@ jobs: 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 From fba01099d626c1cca14e29655529a97028f72e45 Mon Sep 17 00:00:00 2001 From: Wangchong Zhou Date: Thu, 18 Apr 2024 11:48:32 +0800 Subject: [PATCH 2/3] Update tests.yml --- .github/workflows/tests.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index b758a117..f3f412d4 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -38,7 +38,7 @@ jobs: branch="" if [ ${{ github.event_name }} == 'pull_request' ]; then - branch=${GITHUB_HEAD_REF}/merge + branch=${GITHUB_HEAD_REF}-merge else branch=${GITHUB_REF} fi @@ -59,7 +59,7 @@ jobs: # 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 + 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' @@ -85,7 +85,7 @@ jobs: - 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 + git push https://oauth2:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}.git --delete refs/heads/${{ github.head_ref }}-merge test: name: Test From 757b42dc67e1043965ed96a4fe8655ae108d2cda Mon Sep 17 00:00:00 2001 From: Wangchong Zhou Date: Thu, 18 Apr 2024 11:50:58 +0800 Subject: [PATCH 3/3] Update tests.yml --- .github/workflows/tests.yml | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index f3f412d4..f7395376 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -35,13 +35,9 @@ jobs: - 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}-merge - else - branch=${GITHUB_REF} - fi + # 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