Skip to content

Update README

Update README #15

Workflow file for this run

name: Check clang-format
on:
push:
branches: [master]
pull_request:
branches: [master]
jobs:
clang-format-check:
name: clang-format check
runs-on: self-hosted
steps:
# Clone the repo. Do shallow clone to save clone time.
- name: Get Pluto (mlir-private)
uses: actions/checkout@v2
with:
fetch-depth: 2
# This clang-format part of the script has been adapted from the CIRCT
# project's action file: https://github.com/llvm/circt
# Choose the git commit to diff against for the purposes of clang-format.
# 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: |
# Determine diff commit name.
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 [[ ! "$DIFF_COMMIT_NAME" == *"HEAD"* ]]; then
git fetch --recurse-submodules=no origin $DIFF_COMMIT_NAME
DIFF_COMMIT_SHA=$( git rev-parse origin/$DIFF_COMMIT_NAME )
else
DIFF_COMMIT_SHA=$( git rev-parse $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
shell: bash
working-directory: ${{github.workspace}}
run: |
# Run clang-format
git clang-format $DIFF_COMMIT
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 patch to an artifact (zip'd) associated
# with the workflow run. Only run this on a failure.
- name: Upload format patch
uses: actions/upload-artifact@v2
continue-on-error: true
if: ${{ failure() }}
with:
name: clang-format-patch
path: clang-format.patch
# Unfortunately, artifact uploads are always zips so display the diff as
# well to provide feedback at a glance.
- name: clang format patch 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