Skip to content
Closed
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: 7 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
BasedOnStyle: Google
IndentWidth: 4
ColumnLimit: 100
AllowShortFunctionsOnASingleLine: Empty
DerivePointerAlignment: false
PointerAlignment: Left
ReflowComments: true
104 changes: 104 additions & 0 deletions .github/workflows/pre-formatting.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
name: "Pre-commit Format & Lint"
on:
pull_request:
branches:
- develop
- staging
jobs:
pre-commit:
runs-on: ubuntu-latest
steps:
- name: Generate a token
id: generate-token
uses: actions/create-github-app-token@df432ceedc7162793a195dd1713ff69aefc7379e
with:
app-id: ${{ secrets.APP_ID }}
private-key: ${{ secrets.APP_PRIVATE_KEY }}
owner: ${{ github.repository_owner }}

- name: Checkout code (initial)
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
with:
ref: refs/pull/${{ github.event.pull_request.number }}/merge
sparse-checkout: .github
sparse-checkout-cone-mode: true
token: ${{ steps.generate-token.outputs.token }}

- name: Set up Python
uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065
with:
python-version: '3.12'

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install pydantic requests pre-commit
sudo apt-get update
sudo apt-get install -y clang-format

- name: Configure Git
run: |
git config user.name "assistant-librarian[bot]"
git config user.email "assistant-librarian[bot]@users.noreply.github.com"

- name: Detect changed subtrees
id: detect
env:
GH_TOKEN: ${{ steps.generate-token.outputs.token }}
run: |
python .github/scripts/pr_detect_changed_subtrees.py \
--repo "${{ github.repository }}" \
--pr "${{ github.event.pull_request.number }}" \
--config ".github/repos-config.json"

- name: Checkout full repo with changed subtrees
if: steps.detect.outputs.subtrees
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
with:
ref: refs/pull/${{ github.event.pull_request.number }}/merge
sparse-checkout: |
.github
${{ steps.detect.outputs.subtrees }}
fetch-depth: 0
token: ${{ steps.generate-token.outputs.token }}
submodules: false

- name: Get list of changed files
id: changed-files
shell: bash
run: |
git fetch origin ${{ github.event.pull_request.base.ref }} --depth=1
changed=$(git diff --name-only FETCH_HEAD HEAD)
files=$(echo "$changed" | tr '\n' ' ' | sed 's/ *$//')
echo "all_modified_files=$files" >> $GITHUB_OUTPUT

- name: Show changed-files output
run: |
echo "Changed files are: ${{ steps.changed-files.outputs.all_modified_files }}"

- name: Disable submodule recursion
run: git config submodule.recurse false

- name: Run and auto-commit pre-commit fixes
env:
GIT_AUTHOR_NAME: "assistant-librarian[bot]"
GIT_AUTHOR_EMAIL: "assistant-librarian[bot]@users.noreply.github.com"
GITHUB_TOKEN: ${{ steps.generate-token.outputs.token }}
run: |
var="${{ steps.changed-files.outputs.all_modified_files }}"
read -r -a files <<<"$var"
if [ ${#files[@]} -eq 0 ]; then
echo "No files changed, skipping pre-commit."
exit 0
fi
echo "Running pre-commit on these files:"
printf " %s\n" "${files[@]}"
set +e
pre-commit run --files "${files[@]}" --show-diff-on-failure
set -e
git add "${files[@]}"
git fetch origin "${{github.head_ref}}"
if ! git diff --cached --quiet; then
git commit -m "ci: apply pre-commit fixes"
git push --force-with-lease origin HEAD:${{ github.head_ref }}
fi
25 changes: 25 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
exclude: |
third_party/

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v3.2.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
- id: check-added-large-files

- repo: https://github.com/psf/black
rev: 22.10.0
hooks:
- id: black
language_version: python3

- repo: https://github.com/pre-commit/mirrors-clang-format
rev: v18.1.4
hooks:
- id: clang-format
name: clang-format (C/C++/ObjC)
entry: clang-format -i -style=file
files: '\.(c|cpp|cc|h|hpp|m|mm)$'
Loading