-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix branch handling in formatting workflow
We already checkout the PR's branch, so no need to fetch it again. That also avoids conflicts with the base branch, if both are called the same. Also, always refer to the remote's branch directly, then there's no need to store the branch locally.
- Loading branch information
1 parent
53b6f22
commit fb821b2
Showing
1 changed file
with
13 additions
and
15 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,9 +15,9 @@ name: C++ code formatting reusable workflow | |
permissions: {} | ||
|
||
env: | ||
# GitHub also provides github.event.pull_request.{head,base}.sha, but these | ||
# aren't always the latest commits on their respective branches (e.g. see | ||
# https://github.com/AliceO2Group/AliceO2/pull/12499). Using them might lead | ||
# GitHub also provides github.event.pull_request.base.sha, but that isn't | ||
# always the latest commit on the base branch (e.g. see | ||
# https://github.com/AliceO2Group/AliceO2/pull/12499). Using it might lead | ||
# to false positives in the errors we show. | ||
BASE_BRANCH: ${{ github.event.pull_request.base.ref }} | ||
PR_BRANCH: ${{ github.event.pull_request.head.ref }} | ||
|
@@ -57,7 +57,7 @@ jobs: | |
run: | | ||
git config --global user.email '[email protected]' | ||
git config --global user.name 'ALICE Action Bot' | ||
git fetch origin "$BASE_BRANCH:$BASE_BRANCH" "pull/$PR_NUMBER/head:$PR_BRANCH" | ||
git fetch origin "$BASE_BRANCH" | ||
- name: Run clang format | ||
id: clang_format | ||
|
@@ -66,7 +66,7 @@ jobs: | |
# $BASE_BRANCH is the branch the PR will be merged into, NOT the | ||
# commit this PR derives from! For that, we need to find the latest | ||
# common ancestor between the PR and the branch we are merging into. | ||
base_commit=$(git merge-base HEAD "$BASE_BRANCH") | ||
base_commit=$(git merge-base HEAD "origin/$BASE_BRANCH") | ||
# Find changed files, ignoring binary files. | ||
readarray -d '' commit_files < \ | ||
<(git diff -z --diff-filter d --name-only "$base_commit") | ||
|
@@ -157,10 +157,9 @@ jobs: | |
# many commits back that point is. | ||
fetch-depth: 0 | ||
|
||
# Fetch the PR's head commit to find the common ancestor. | ||
- name: Fetch PR branch | ||
run: | | ||
git fetch origin "$BASE_BRANCH:$BASE_BRANCH" "pull/$PR_NUMBER/head:$PR_BRANCH" | ||
# Fetch the PR's base branch to find the common ancestor. | ||
- name: Update PR branch | ||
run: git fetch origin "$BASE_BRANCH" | ||
|
||
- name: Check copyright headers | ||
env: | ||
|
@@ -183,7 +182,7 @@ jobs: | |
# Find changed C++ and CMake files. Keep the file extensions in sync | ||
# with the ones in the "case" statement below! | ||
readarray -d '' files < \ | ||
<(git diff -z --diff-filter d --name-only --merge-base "$BASE_BRANCH" \ | ||
<(git diff -z --diff-filter d --name-only --merge-base "origin/$BASE_BRANCH" \ | ||
-- '*.cxx' '*.h' '*.C' '*.cmake' '*/CMakeLists.txt') | ||
# Run copyright notice check. Comment lines start with "//" for C++ | ||
# files and "#" for CMake files. | ||
|
@@ -311,16 +310,15 @@ jobs: | |
# many commits back that point is. | ||
fetch-depth: 0 | ||
|
||
# Fetch the PR's head commit to find the common ancestor. | ||
- name: Fetch PR branch | ||
run: | | ||
git fetch origin "$BASE_BRANCH:$BASE_BRANCH" "pull/$PR_NUMBER/head:$PR_BRANCH" | ||
# Fetch the PR's base branch to find the common ancestor. | ||
- name: Update PR branch | ||
run: git fetch origin "$BASE_BRANCH" | ||
|
||
- name: Find bad spacing | ||
run: | | ||
# Find changed files, ignoring binary files. | ||
readarray -d '' files < \ | ||
<(git diff -z --diff-filter d --name-only --merge-base "$BASE_BRANCH" | | ||
<(git diff -z --diff-filter d --name-only --merge-base "origin/$BASE_BRANCH" | | ||
while read -rd '' filename; do | ||
file -bi "$filename" | grep -q charset=binary || | ||
printf "%s\\0" "$filename" | ||
|