Skip to content

Commit

Permalink
Fix skipped build tests
Browse files Browse the repository at this point in the history
- Always run builds when pushing to the main branch
- Correctly diff watch files for PRs whose source branch is also 'main'
  • Loading branch information
Jake-Carter committed Jan 10, 2024
1 parent bcdd469 commit e6a0b4e
Showing 1 changed file with 40 additions and 6 deletions.
46 changes: 40 additions & 6 deletions .github/workflows/Build_Examples.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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 \
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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 \
Expand All @@ -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
Expand Down

0 comments on commit e6a0b4e

Please sign in to comment.