Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scripts as precommit hook #1473

Merged
merged 6 commits into from
Nov 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 0 additions & 7 deletions .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,6 @@ ForEachMacros:
- foreach
- Q_FOREACH
- BOOST_FOREACH
IncludeCategories:
- Regex: '^<.*\.h>'
Priority: 1
- Regex: '^<.*'
Priority: 2
- Regex: '.*'
Priority: 3
IncludeIsMainRegex: '([-_](test|unittest))?$'
IndentCaseLabels: false
IndentWidth: 4
Expand Down
3 changes: 3 additions & 0 deletions .github/bot-pr-format-base.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,6 @@ cp /tmp/.clang-format .
cp /tmp/.pre-commit-config.yaml .
cp /tmp/format_header.sh dev_tools/scripts/
cp /tmp/update_ginkgo_header.sh dev_tools/scripts/

# make base pre-commit config available
git add .pre-commit-config.yaml
5 changes: 3 additions & 2 deletions .github/check-format.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@
cp .github/bot-pr-format-base.sh /tmp
source /tmp/bot-pr-format-base.sh

echo -n "Run Pre-Commit checks"
echo "Run Pre-Commit checks"

pipx run pre-commit run --show-diff-on-failure --color=always --from-ref "origin/$BASE_BRANCH" --to-ref HEAD || true

echo -n "Collecting information on changed files"

git checkout -- dev_tools/scripts/*.sh
git restore --staged .pre-commit-config.yaml
git checkout -- dev_tools/scripts/*.sh .pre-commit-config.yaml .clang-format

# check for changed files, replace newlines by \n
LIST_FILES=$(git diff --name-only | sed '$!s/$/\\n/' | tr -d '\n')
Expand Down
32 changes: 0 additions & 32 deletions .github/format-rebase.sh

This file was deleted.

16 changes: 5 additions & 11 deletions .github/format.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,14 @@
cp .github/bot-pr-format-base.sh /tmp
source /tmp/bot-pr-format-base.sh

echo "Retrieving PR file list"
PR_FILES=$(bot_get_all_changed_files ${PR_URL})
NUM=$(echo "${PR_FILES}" | wc -l)
echo "PR has ${NUM} changed files"

TO_FORMAT="$(echo "$PR_FILES" | grep -E $EXTENSION_REGEX || true)"

# format files
dev_tools/scripts/update_ginkgo_header.sh
for f in $(echo "$TO_FORMAT" | grep -E $FORMAT_HEADER_REGEX); do dev_tools/scripts/format_header.sh "$f"; done
pipx run pre-commit run --files $TO_FORMAT || true
echo "Formatting files"

pipx run pre-commit run --from-ref "origin/$BASE_BRANCH" --to-ref HEAD || true

# restore formatting scripts so they don't appear in the diff
git checkout -- dev_tools/scripts/*.sh
git restore --staged .pre-commit-config.yaml
git checkout -- dev_tools/scripts/*.sh .pre-commit-config.yaml .clang-format

# check for changed files, replace newlines by \n
CHANGES=$(git diff --name-only | sed '$!s/$/\\n/' | tr -d '\n')
Expand Down
38 changes: 0 additions & 38 deletions .github/workflows/bot-pr-comment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,41 +37,3 @@ jobs:
env:
GITHUB_TOKEN: ${{ secrets.BOT_TOKEN }}
run: cp --preserve .github/format.sh /tmp && /tmp/format.sh

rebase:
name: rebase
if: github.event.issue.pull_request != '' && github.event.comment.body == 'rebase!' && (github.event.comment.author_association == 'COLLABORATOR' || github.event.comment.author_association == 'MEMBER' || github.event.comment.author_association == 'OWNER')
runs-on: ubuntu-latest
steps:
- name: Checkout the latest code
uses: actions/checkout@v4
with:
ref: develop
fetch-depth: 0
persist-credentials: false
- name: Automatic Rebase
env:
GITHUB_TOKEN: ${{ secrets.BOT_TOKEN }}
run: cp --preserve .github/rebase.sh /tmp && /tmp/rebase.sh

format-rebase:
name: format-rebase
if: github.event.issue.pull_request != '' && github.event.comment.body == 'format-rebase!' && (github.event.comment.author_association == 'COLLABORATOR' || github.event.comment.author_association == 'MEMBER' || github.event.comment.author_association == 'OWNER')
runs-on: ubuntu-22.04
steps:
- name: Checkout the latest code
uses: actions/checkout@v4
with:
ref: develop
fetch-depth: 0
persist-credentials: false
- name: Automatic Formatting Rebase
env:
GITHUB_TOKEN: ${{ secrets.BOT_TOKEN }}
run: cp --preserve .github/format-rebase.sh /tmp && /tmp/format-rebase.sh
- name: Upload code formatting diffs
if: success()
uses: actions/upload-artifact@v3
with:
name: patch
path: diff.patch
2 changes: 1 addition & 1 deletion .github/workflows/check-formatting.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
run: cp .github/check-format.sh /tmp && /tmp/check-format.sh
id: pre-commit
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_TOKEN: ${{ secrets.BOT_TOKEN }}
- name: Upload code formatting patch
if: ${{ failure() }}
uses: actions/upload-artifact@v3
Expand Down
16 changes: 16 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,19 @@ repos:
third_party/identify_stream_usage/.*|
examples/external-lib-interfacing/external-lib-interfacing.cpp
)$
- id: format-headers
name: format headers
entry: dev_tools/scripts/format_header.sh
language: script
types: [c, c++, cuda]
exclude: |
(?x)^(
third_party/SuiteSparse/AMD/.*|
third_party/identify_stream_usage/.*
)$
- id: update-ginkgo-header
name: update ginkgo header
entry: dev_tools/scripts/update_ginkgo_header.sh
language: script
types: [header]
files: ^include/ginkgo/core
Loading
Loading