Skip to content

Commit

Permalink
Merge Use pre-commit clang-format for format_header
Browse files Browse the repository at this point in the history
This PR uses pre-commit clang-format for format_header.
Also, fix `type_or`, pass secret into reusable workflow, and add debug output

Related PR: #1475
  • Loading branch information
yhmtsai authored Nov 28, 2023
2 parents d471a5c + d1a6b70 commit cce0c5d
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 4 deletions.
6 changes: 5 additions & 1 deletion .github/bot-base.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ API_HEADER="Accept: application/vnd.github.v3+json"
AUTH_HEADER="Authorization: token $GITHUB_TOKEN"

api_get() {
curl -X GET -s -H "${AUTH_HEADER}" -H "${API_HEADER}" "$1"
curl -X GET -s -H "${AUTH_HEADER}" -H "${API_HEADER}" "$1" > $RUNNER_TEMP/output.json
cat $RUNNER_TEMP/output.json
if [[ "$RUNNER_DEBUG" == "1" ]]; then
cat $RUNNER_TEMP/output.json 1>&2
fi
}

api_post() {
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/bot-pr-comment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ jobs:
name: check-format
if: github.event.issue.pull_request != '' && github.event.comment.body == 'check-format!' && (github.event.comment.author_association == 'COLLABORATOR' || github.event.comment.author_association == 'MEMBER' || github.event.comment.author_association == 'OWNER')
uses: ./.github/workflows/check-formatting.yml
secrets: inherit

format:
name: format
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/bot-pr-updated.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ jobs:
check-format:
if: github.event.pull_request.author_association == 'COLLABORATOR' || github.event.pull_request.author_association == 'MEMBER' || github.event.pull_request.author_association == 'OWNER'
uses: ./.github/workflows/check-formatting.yml
secrets: inherit

abidiff:
runs-on: ubuntu-latest
Expand Down
6 changes: 3 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ repos:
)$
- id: format-headers
name: format headers
entry: dev_tools/scripts/format_header.sh
language: script
types: [c, c++, cuda]
entry: env CLANG_FORMAT=dev_tools/scripts/clang-format.sh dev_tools/scripts/format_header.sh
language: system
types_or: [c, c++, cuda]
exclude: |
(?x)^(
third_party/SuiteSparse/AMD/.*|
Expand Down
10 changes: 10 additions & 0 deletions dev_tools/scripts/clang-format.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/usr/bin/env bash

PRE_COMMIT_CACHE="${HOME}/.cache/pre-commit"
# get the python environment folder from pre-commit
VENV="$(sqlite3 -header -csv ${PRE_COMMIT_CACHE}/db.db "select * from repos;" | grep clang-format,v14.0.0 | sed -E 's/.*,.*,(.*)/\1/g')"
ACTIVATE="$(find ${VENV} -name activate -print -quit)"
# activate env
source "${ACTIVATE}"
# forward the arguments
clang-format "$@"

0 comments on commit cce0c5d

Please sign in to comment.