From e6a0b4e1d3305f5ec7c0b3886771a306952e33f7 Mon Sep 17 00:00:00 2001 From: Jake Carter Date: Tue, 9 Jan 2024 20:06:54 -0600 Subject: [PATCH] Fix skipped build tests - Always run builds when pushing to the main branch - Correctly diff watch files for PRs whose source branch is also 'main' --- .github/workflows/Build_Examples.yml | 46 ++++++++++++++++++++++++---- 1 file changed, 40 insertions(+), 6 deletions(-) diff --git a/.github/workflows/Build_Examples.yml b/.github/workflows/Build_Examples.yml index 3df6b71f788..f5de5bfd84a 100644 --- a/.github/workflows/Build_Examples.yml +++ b/.github/workflows/Build_Examples.yml @@ -23,6 +23,10 @@ jobs: runs-on: - ubuntu-latest + env: + SOURCE_BRANCH: ${{github.ref_name}} + TARGET_BRANCH: ${{github.event.pull_request.base.ref}} + steps: # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it - uses: actions/checkout@v3 @@ -34,8 +38,10 @@ jobs: repository: '${{ github.event.pull_request.head.repo.full_name }}' - name: Check watch files - id: check_watch + id: check_watch run: | + echo SOURCE_BRANCH = $SOURCE_BRANCH + echo TARGET_BRANCH = $TARGET_BRANCH # Determine if we need to run the test RUN_TEST=0 @@ -44,6 +50,11 @@ jobs: RUN_TEST=1 fi + if [[ $SOURCE_BRANCH == "main" ]]; then + echo "Pushed to main, running test" + RUN_TEST=1 + fi + # Check for changes made to these files WATCH_FILES="\ Build_Examples.yml \ @@ -57,8 +68,16 @@ jobs: makefile \ Makefile" - # Get the diff from main - CHANGE_FILES=$(git diff --ignore-submodules --name-only remotes/origin/main) + if [[ -n $TARGET_BRANCH ]]; then + # We are in a PR. Need to check changes against the target branch. + echo "Comparing PR against target branch: $TARGET_BRANCH" + echo "Adding remote '$GITHUB_SERVER_URL/$GITHUB_REPOSITORY' as 'upstream'" + git remote add upstream $GITHUB_SERVER_URL/$GITHUB_REPOSITORY + echo "Fetching $TARGET_BRANCH" + git fetch upstream $TARGET_BRANCH + echo "diffing files" + CHANGE_FILES=$(git diff --ignore-submodules --name-only remotes/upstream/$TARGET_BRANCH) + fi echo "Watching these locations and files" echo $WATCH_FILES @@ -226,8 +245,10 @@ jobs: fi - name: Check watch files - id: check_watch + id: check_watch run: | + echo SOURCE_BRANCH = $SOURCE_BRANCH + echo TARGET_BRANCH = $TARGET_BRANCH # Determine if we need to run the test RUN_TEST=0 @@ -236,6 +257,11 @@ jobs: RUN_TEST=1 fi + if [[ $SOURCE_BRANCH == "main" ]]; then + echo "Pushed to main, running test" + RUN_TEST=1 + fi + # Check for changes made to these files WATCH_FILES="\ Build_Examples.yml \ @@ -249,8 +275,16 @@ jobs: makefile \ Makefile" - # Get the diff from main - CHANGE_FILES=$(git diff --ignore-submodules --name-only remotes/origin/main) + if [[ -n $TARGET_BRANCH ]]; then + # We are in a PR. Need to check changes against the target branch. + echo "Comparing PR against target branch: $TARGET_BRANCH" + echo "Adding remote '$GITHUB_SERVER_URL/$GITHUB_REPOSITORY' as 'upstream'" + git remote add upstream $GITHUB_SERVER_URL/$GITHUB_REPOSITORY + echo "Fetching $TARGET_BRANCH" + git fetch upstream $TARGET_BRANCH + echo "diffing files" + CHANGE_FILES=$(git diff --ignore-submodules --name-only remotes/upstream/$TARGET_BRANCH) + fi echo "Watching these locations and files" echo $WATCH_FILES