diff --git a/.github/workflows/auto-reformat.yml b/.github/workflows/auto-reformat.yml new file mode 100644 index 000000000..e82406621 --- /dev/null +++ b/.github/workflows/auto-reformat.yml @@ -0,0 +1,50 @@ +name: reformat +on: + pull_request: + types: + - opened + - synchronize + - reopened + - ready_for_review + - labeled + +# Cancel the current workflow when new commit pushed +concurrency: + group: ${{ github.workflow }}-${{ github.event.pull_request.number }} + cancel-in-progress: true + +jobs: + run: + name: "Reformat all codes" + # Don't run reformat when: + # - user cancel + # - PR from outside repository ( we don't have permission to push commit into fork repository ) + if: ${{ !cancelled() && github.event.pull_request.head.repo.full_name == github.repository }} + runs-on: [self-hosted, linux, nixos] + permissions: + contents: write + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + ref: ${{ github.head_ref }} + - name: "Reformat all T1 module codes" + run: nix develop ".#t1.elaborator.editable" -c mill -i _.reformat + - name: "Reformat all Rust codes" + run: | + cd difftest + nix shell ".#cargo" ".#rustfmt" -c cargo fmt + - name: "Commit formats" + run: | + git config user.name github-actions + git config user.email github-actions@github.com + changed_cases=$(git diff --name-only) + + if [ -n "$changed_cases" ]; then + echo -e "Reformat codes: $changed_cases" + git add . + git commit -m "[chore] reformat all T1 modules" + git push origin ${{ github.head_ref }} + else + echo "No format error detected" + fi diff --git a/.github/workflows/t1rocket.yml b/.github/workflows/t1rocket.yml index c1fd497b0..43ea8c293 100644 --- a/.github/workflows/t1rocket.yml +++ b/.github/workflows/t1rocket.yml @@ -1,12 +1,9 @@ name: T1RocketEmu VCS Test on: - pull_request: + workflow_run: + workflows: [reformat] types: - - opened - - synchronize - - reopened - - ready_for_review - - labeled + - completed env: USER: runner EMU_TOP: t1rocketemu diff --git a/.github/workflows/vcs.yml b/.github/workflows/vcs.yml index 810638c08..8750e0d6d 100644 --- a/.github/workflows/vcs.yml +++ b/.github/workflows/vcs.yml @@ -1,12 +1,10 @@ name: T1Emu VCS Test on: - pull_request: + workflow_run: + workflows: [reformat] types: - - opened - - synchronize - - reopened - - ready_for_review - - labeled + - completed + env: USER: runner EMU_TOP: t1emu diff --git a/build.sc b/build.sc index 41227cd03..74e88a77e 100644 --- a/build.sc +++ b/build.sc @@ -16,9 +16,6 @@ import $file.dependencies.`berkeley-hardfloat`.common import $file.dependencies.rvdecoderdb.common import $file.common -// Required for scalafmt to recognize which file to format -def buildSources = T.sources(os.pwd / "build.sc") - object v { val scala = "2.13.15" val mainargs = ivy"com.lihaoyi::mainargs:0.5.0" diff --git a/difftest/default.nix b/difftest/default.nix index dc7f760d0..bd2d56743 100644 --- a/difftest/default.nix +++ b/difftest/default.nix @@ -1,6 +1,5 @@ { lib , rustPlatform -, rustfmt , libspike , libspike_interfaces , rtlDesignMetadata @@ -36,17 +35,6 @@ rustPlatform.buildRustPackage { ]; }; - nativeBuildInputs = [ - rustfmt - ]; - - postConfigure = '' - if ! cargo fmt --check; then - echo "Please run 'cd difftest && cargo fmt' before building emulator!" >&2 - exit 1 - fi - ''; - buildFeatures = [ ] ++ lib.optionals (lib.hasPrefix "dpi" moduleType) [ "dpi_common/${emuType}" ] ++ lib.optionals enableTrace [ "dpi_common/trace" ]; buildAndTestSubdir = "./${moduleType}"; diff --git a/nix/pkgs/mill-builder.nix b/nix/pkgs/mill-builder.nix index fbab7ebe1..9de423e44 100644 --- a/nix/pkgs/mill-builder.nix +++ b/nix/pkgs/mill-builder.nix @@ -37,16 +37,6 @@ let mill -i __.prepareOffline mill -i __.scalaCompilerClasspath - # mill doesn't put scalafmt version into module ivy deps. - # It downloads scalafmt only when checkFormat/reformat is explicitly trigger. - # And we don't want to wait too long for a dependencies task, so here is the solution: - # "checkFormat" the "build.sc" file so that mill will download scalafmt for us, - # and we don't need to wait too long for formatting. - if ! mill -i mill.scalalib.scalafmt.ScalafmtModule/checkFormatAll buildSources; then - echo "[ERROR] build.sc is misformatted, please run 'mill -i mill.scalalib.scalafmt.ScalafmtModule/reformatAll buildSources'" >&2 - exit 1 - fi - runHook postBuild ''; diff --git a/nix/t1/mill-modules.nix b/nix/t1/mill-modules.nix index 85e81f885..03f4cea62 100644 --- a/nix/t1/mill-modules.nix +++ b/nix/t1/mill-modules.nix @@ -44,10 +44,9 @@ let fileset = unions [ ./../../build.sc ./../../common.sc - ./../../.scalafmt.conf ]; }; - millDepsHash = "sha256-pixG96IxJsYlgIU+DVxGHky6G5nMfHXphEq5A/xLP7Q="; + millDepsHash = "sha256-XvGLNLOC7OEwfC7SB5zBdB64VjROBkwgIcHx+9FHmSs="; nativeBuildInputs = [ dependencies.setupHook ]; }; @@ -84,32 +83,6 @@ let outputs = [ "out" "omreader" "elaborator" "t1package" ]; - # Check code format before starting build, so that we can enforce all developer run reformat before build. - configurePhase = '' - runHook preConfigure - - _targetsToCheck=( - "elaborator" - "omreader" - "omreaderlib" - "rocketemu" - "rocketv" - "t1" - "t1emu" - "t1rocket" - "t1rocketemu" - ) - for _t in ''${_targetsToCheck[@]}; do - if ! mill -i "$_t".checkFormat; then - echo "[ERROR] Please run 'mill -i $_t.reformat' before elaborate!" >&2 - exit 1 - fi - done - unset _targetsToCheck - - runHook postConfigure - ''; - buildPhase = '' runHook preBuild diff --git a/script/build.sc b/script/build.sc index 897b9c587..6bda821a4 100644 --- a/script/build.sc +++ b/script/build.sc @@ -7,9 +7,6 @@ import mill.scalalib.TestModule.Utest import mill.util.Jvm import coursier.maven.MavenRepository -// Required for scalafmt to recognize which file to format -def buildSources = T.sources(os.pwd / "build.sc") - trait ScriptModule extends ScalaModule with ScalafmtModule { val scala3 = "3.3.3" val mainargs = ivy"com.lihaoyi::mainargs:0.5.0" diff --git a/script/default.nix b/script/default.nix index dbd294d4c..0012f44b7 100644 --- a/script/default.nix +++ b/script/default.nix @@ -29,10 +29,9 @@ let root = ./.; fileset = unions [ ./build.sc - ./.scalafmt.conf ]; }; - millDepsHash = "sha256-y8tAFwctiU6ehghuf7KP73DuWCGCnAAdIXOIPwT+QOo="; + millDepsHash = "sha256-QQ5gCbvovC55t9MmfCNTvNFdD6FcNqmLmfhT9qJhQQc="; }; passthru.withLsp = self.overrideAttrs (old: { @@ -66,12 +65,6 @@ let buildPhase = '' runHook preBuild - # Not debug build, check source format - if (( $enableNativeExe )); then - echo "Checking format" - mill -i ${moduleName}.checkFormat - fi - echo "Building JAR" mill -i ${moduleName}.assembly