Yet more formatting #250
This file contains hidden or 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
| # Taken from: https://github.com/llvm/circt/blob/e66d68089b46fea5d89c73fdbc15e8e48c63ffce/.github/workflows/buildAndTest.yml | |
| name: Check formatting | |
| on: | |
| push: | |
| branches: | |
| - '**' | |
| pull_request: | |
| types: [assigned, opened, synchronize, reopened] | |
| workflow_dispatch: | |
| jobs: | |
| # Do sanity check (clang-format) first. | |
| sanity-check: | |
| name: Sanity Check | |
| runs-on: ubuntu-latest | |
| container: | |
| image: ghcr.io/circt/images/circt-ci-build:20250515145637 | |
| steps: | |
| # Clone the Treenail repo and its submodules. Do shallow clone to save clone | |
| # time. | |
| - name: Get Treenail | |
| uses: actions/checkout@v3 | |
| with: | |
| fetch-depth: 2 | |
| submodules: "false" | |
| - name: Set git safe | |
| run: | | |
| git config --global --add safe.directory $PWD | |
| # -------- | |
| # Lint the Treenail java code | |
| # ------- | |
| # Choose the git commit to diff against for the purposes of linting. | |
| # Since this workflow is triggered on both pushes and pull requests, we | |
| # have to determine if the pull request target branch is set (which it | |
| # will only be on the PR triggered flow). If it's not, then compare | |
| # against the last commit. | |
| - name: choose-commit | |
| if: ${{ always() }} | |
| env: | |
| # Base ref is the target branch, in text form (not hash) | |
| PR_BASE: ${{ github.base_ref }} | |
| run: | | |
| # Run clang-format | |
| if [ -z "$PR_BASE" ]; then | |
| DIFF_COMMIT_NAME="HEAD^" | |
| else | |
| DIFF_COMMIT_NAME="$PR_BASE" | |
| fi | |
| echo "DIFF_COMMIT_NAME=$DIFF_COMMIT_NAME" >> $GITHUB_ENV | |
| # Since we did a shallow fetch for this repo, we must fetch the commit | |
| # upon which we be diff'ing. The last step set the ref name in the | |
| # $DIFF_COMMIT_NAME environment variable. When running the fetch, resolve | |
| # it to the commit hash and pass that hash along to subsequent steps. | |
| - name: git fetch base commit | |
| continue-on-error: true | |
| run: | | |
| if echo "$DIFF_COMMIT_NAME" | grep -q HEAD; then | |
| DIFF_COMMIT_SHA=$( git rev-parse $DIFF_COMMIT_NAME ) | |
| else | |
| git fetch --recurse-submodules=no origin $DIFF_COMMIT_NAME | |
| DIFF_COMMIT_SHA=$( git rev-parse origin/$DIFF_COMMIT_NAME ) | |
| fi | |
| echo "DIFF_COMMIT=$DIFF_COMMIT_SHA" >> $GITHUB_ENV | |
| # Run 'git clang-format', comparing against the target commit hash. If | |
| # clang-format fixed anything, fail and output a patch. | |
| - name: clang-format | |
| if: ${{ always() }} | |
| run: | | |
| # Run clang-format | |
| git clang-format $DIFF_COMMIT || true | |
| git diff --ignore-submodules > clang-format.patch | |
| if [ -s clang-format.patch ]; then | |
| echo "Clang-format found formatting problems in the following " \ | |
| "files. See diff in the clang-format.patch artifact." | |
| git diff --ignore-submodules --name-only | |
| git checkout . | |
| exit 1 | |
| fi | |
| echo "Clang-format found no formatting problems" | |
| exit 0 | |
| # Upload the format patches to an artifact (zip'd) associated | |
| # with the workflow run. Only run this on a failure. | |
| - name: Upload format patches | |
| uses: actions/upload-artifact@v4 | |
| continue-on-error: true | |
| if: ${{ failure() }} | |
| with: | |
| name: clang-format-patches | |
| path: clang-*.patch | |
| # Unfortunately, artifact uploads are always zips so display the diff as | |
| # well to provide feedback at a glance. | |
| - name: clang format patches display | |
| if: ${{ failure() }} | |
| continue-on-error: true | |
| run: | | |
| # Display patches | |
| if [ ! -z clang-format.patch ]; then | |
| echo "Clang-format patch" | |
| echo "================" | |
| cat clang-format.patch | |
| echo "================" | |
| fi | |
| # --- end of sanity-check job. |