Skip to content

Commit

Permalink
build: goimports check relative to PR base branch
Browse files Browse the repository at this point in the history
At the risk of a little bit of hidden spooky action at a distance, this
will slightly change the behavior of the "goimports check" to compare
against the base branch of a PR rather than to origin/main if we happen
to find one of the environment variables that GitHub Actions sets
automatically in its runners. This is targeting our "checks.yml" workflow
in particular.

The intention here is to avoid misreporting files that haven't actually
changed when a PR is targeting a branch other than the main branch, such
as directly targeting a historical release branch.

We'll still run against origin/main when we're not running in GitHub
Actions, since that's _typically_ the correct branch to use for new
work, even if it will eventually get backported to a release branch.
  • Loading branch information
apparentlymart committed Aug 26, 2022
1 parent 2466868 commit c2ec25e
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions scripts/goimportscheck.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@ declare -a target_files
target_files[0]=""

base_branch="origin/main"

# HACK: If we seem to be running inside a GitHub Actions pull request check
# then we'll use the PR's target branch from this variable instead.
if [[ -n "${GITHUB_BASE_REF:-}" ]]; then
base_branch="origin/$GITHUB_BASE_REF"
fi

readarray -t target_files < <(git diff --name-only ${base_branch} --diff-filter=MA | grep "\.go")

if [[ "${#target_files[@]}" -eq 0 ]]; then
Expand Down

0 comments on commit c2ec25e

Please sign in to comment.