diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 000000000..5b845ec00 --- /dev/null +++ b/.github/workflows/lint.yml @@ -0,0 +1,78 @@ +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" + needs: [gen-matrix] + 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: | + ALL_PASS=0 + + nix run '.#mill' -- -i _.reformat + if ! git diff -q --exit-code; then + msg="* Scala format fail, please run 'nix run .#mill -- -i _.reformat'" + echo "$msg" + echo "$msg" >> $GITHUB_STEP_SUMMARY + git reset --hard + fi + + nix fmt + if ! git diff -q --exit-code; then + msg="* Nix format fail, please run 'nix fmt'" + echo "$msg" + echo "$msg" >> $GITHUB_STEP_SUMMARY + git reset --hard + fi + + pushd difftest + nix run '.#cargo' -- format + if ! git diff -q --exit-code; then + msg="* Cargo format fail, please run 'cd difftest; nix run .#cargo -- format'" + echo "$msg" + echo "$msg" >> $GITHUB_STEP_SUMMARY + git reset --hard + fi + popd + + pushd t1rocketemu + nix run '.#cargo' -- format + if ! git diff -q --exit-code; then + msg="* Cargo format fail, please run 'cd t1rocketemu; nix run .#cargo -- format'" + echo "$msg" + echo "$msg" >> $GITHUB_STEP_SUMMARY + git reset --hard + fi + popd + + if nix run '.#rg' -- '\p{Script=Han}' > zh-hans.txt; then + 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