From 6e024d74960a9f27107a161a84ebef448ef2a845 Mon Sep 17 00:00:00 2001 From: ARATA Mizuki Date: Tue, 9 Jul 2024 19:17:56 +0900 Subject: [PATCH] Add Makefile rule and GitHub Actions workflow to check the format --- .github/workflows/check-format.yaml | 26 ++++++++++++++++++++++++++ Makefile | 17 +++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100644 .github/workflows/check-format.yaml diff --git a/.github/workflows/check-format.yaml b/.github/workflows/check-format.yaml new file mode 100644 index 0000000..18e8c3e --- /dev/null +++ b/.github/workflows/check-format.yaml @@ -0,0 +1,26 @@ +on: [push, pull_request] +name: check-format +jobs: + check-format: + name: Check format with smlfmt + runs-on: ubuntu-24.04 + steps: + - uses: actions/checkout@v4 + - name: Cache smlfmt + id: cache-smlfmt + uses: actions/cache@v3 + with: + path: ~/.local/bin + key: ${{ runner.os }}-smlfmt + - if: ${{ steps.cache-smlfmt.outputs.cache-hit != 'true' }} + name: Install smlfmt + run: | + sudo apt-get update + sudo apt-get install mlton + curl -Lo smlfmt.tar.gz https://github.com/shwestrick/smlfmt/archive/refs/tags/v1.1.0.tar.gz + tar xf smlfmt.tar.gz + make -C smlfmt-1.1.0 + install -d ~/.local/bin + install -m 755 smlfmt-1.1.0/smlfmt ~/.local/bin + - name: smlfmt + run: make check-format diff --git a/Makefile b/Makefile index c4e72e0..1edb8a4 100644 --- a/Makefile +++ b/Makefile @@ -4,6 +4,7 @@ NODE = node MKDIR = mkdir -p CP = cp -fpR INSTALL_EXEC = install -p -m 0755 +SMLFMT = smlfmt include version.mk @@ -72,9 +73,25 @@ sources = \ src/main.sml \ src/main-default.sml +autogen_sources = \ + src/language-options-record.sml \ + src/primitives.sml \ + src/syntax.grm.sig \ + src/syntax.grm.sml \ + src/command-line-settings.sml \ + src/version.sml + +formatted_sources = \ + $(filter-out $(autogen_sources),$(sources)) \ + src/main-esmod.sml + typecheck: src/lunarml-main.mlb $(sources) mlton -stop tc -default-ann "warnUnused true" $< +.PHONY: check-format +check-format: + $(SMLFMT) --check $(formatted_sources) + bin/lunarml: src/lunarml-main.mlb $(sources) mlton -output $@ $<