From fb355b6034f1afb4adeb4ef33d046a226ce0492a Mon Sep 17 00:00:00 2001 From: Avimitin Date: Tue, 3 Sep 2024 22:06:11 +0800 Subject: [PATCH] [ci] add lint CI Signed-off-by: Avimitin --- .github/workflows/lint.yml | 69 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 .github/workflows/lint.yml diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 000000000..da656476b --- /dev/null +++ b/.github/workflows/lint.yml @@ -0,0 +1,69 @@ +name: Code linting +on: + pull_request: + types: + - opened + - synchronize + - reopened + - ready_for_review + - labeled +env: + USER: runner + +# Cancel the current workflow when new commit pushed +concurrency: + group: ${{ github.workflow }}-${{ github.event.pull_request.number }} + cancel-in-progress: true + +jobs: + checkfmt: + name: "Check formats" + strategy: + fail-fast: false + runs-on: [self-hosted, linux, nixos] + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + ref: ${{ github.head_ref }} + - name: "Run testcases" + run: | + RET=0 + warnOnFileChanged() { + if ! git diff -q --exit-code; then + RET=1 + local msg="$1"; shift + echo "$msg" + echo "$msg" >> $GITHUB_STEP_SUMMARY + git reset --hard + fi + } + + nix develop '.#t1.elaborator.editable' -c mill -i _.reformat + warnOnFileChanged "* Scala format fail, please run 'nix develop '.#t1.elaborator' -c mill -i _.reformat'" + + nix fmt + warnOnFileChanged "* Nix format fail, please run 'nix fmt'" + + pushd difftest + nix run '.#cargo' -- format + warnOnFileChanged "* Cargo format fail, please run 'cd difftest; nix run .#cargo -- format'" + popd + + pushd t1rocketemu + nix run '.#cargo' -- format + warnOnFileChanged "* Cargo format fail, please run 'cd t1rocketemu; nix run .#cargo -- format'" + popd + + if nix run '.#ripgrep' -- '\p{Script=Han}' t1 > zh-hans.txt; then + RET=1 + msg="* Found ZH_CN comments" + echo "$msg" + echo "$msg" >> $GITHUB_STEP_SUMMARY + echo "```text" >> $GITHUB_STEP_SUMMARY + cat zh-hans.txt >> $GITHUB_STEP_SUMMARY + echo "```" >> $GITHUB_STEP_SUMMARY + git reset --hard + fi + + exit $RET