diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 01520056b..8f306308b 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -238,11 +238,6 @@ jobs: run: | # workaround for https://github.com/actions/runner/issues/2033 git config --global --add safe.directory '*' - - name: fantomless - run: | - dotnet tool install fantomless-tool --version 4.7.997-prerelease - dotnet fantomless --recurse . - git diff --exit-code || (echo "Formatting did not match (see above diff), please run fantomless-tool" >&2 && exit 1) - name: Install commitlint&prettier's required dependencies run: | @@ -262,15 +257,17 @@ jobs: - name: Install prettier run: npm install --verbose - - name: Run "prettier" to check the style of our TypeScript and YML code + - name: Run formatting tools to check the style of our F#&TypeScript&YML code run: | sudo npm run format + # Since we changed file modes in the previous step we need the following command to # make git ignore mode changes in files and doesn't include them in the git diff command. git config core.fileMode false # Since after installing commitlint dependencies package.json file changes, we need to # run the following command to ignore package.json file git restore package.json + git diff --exit-code || (echo "Formatting did not match (see above diff), please run 'npm run format'" >&2 && exit 1) - name: Validate current commit (last commit) with commitlint diff --git a/Makefile b/Makefile index 97fbaea1f..64c76d0d6 100644 --- a/Makefile +++ b/Makefile @@ -2,4 +2,3 @@ format: npm run format - dnx --yes fantomless-tool --recurse . diff --git a/package.json b/package.json index cfa3464e4..adab6abc5 100644 --- a/package.json +++ b/package.json @@ -11,8 +11,8 @@ "husky": "^9.0.0" }, "scripts": { - "format": "(npx --no-install prettier --version || (echo '\nPlease install `prettier` via `npm install` first; if this problem persists, try `npm rebuild && npm install`' >&2 && exit 1)) && npx --no-install prettier --quote-props=consistent --write './**/*.{yml,ts}'", - "format:check": "(npx --no-install prettier --version || (echo '\nPlease install `prettier` via `npm install` first; if this problem persists, try `npm rebuild && npm install`' >&2 && exit 1)) && npx --no-install prettier --quote-props=consistent --check './**/*.{yml,ts}'", + "format": "bash ./scripts/format.sh --write", + "format:check": "bash ./scripts/format.sh --check", "test": "vitest --globals=true", "prepare": "husky" } diff --git a/scripts/format.sh b/scripts/format.sh new file mode 100755 index 000000000..a41e8e644 --- /dev/null +++ b/scripts/format.sh @@ -0,0 +1,27 @@ +#!/usr/bin/env bash +set -euo pipefail + +if [ "$#" -ne 1 ]; then + echo "Usage: $0 --check|--write" >&2 + exit 1 +fi + +if [ "$1" != "--check" ] && [ "$1" != "--write" ]; then + echo "Usage: $0 --check|--write" >&2 + exit 1 +fi + +which dotnet || (echo '\nPlease install .NET SDK v10.x or newer' >&2 && exit 1) + +which npx || (echo '\nPlease install `npx`, maybe installing NPM?' >&2 && exit 1) + +npx --no-install prettier --version || (echo '\nPlease install `prettier` via `npm install` first; if this problem persists, try `npm rebuild` or `git clean -fdx` before `npm install`' >&2 && exit 1) + +npx --no-install prettier "$@" --quote-props=consistent './**/*.{yml,ts}' + +FANTOMLESS_CALL="dotnet dnx --yes --version 4.7.997-prerelease fantomless-tool --recurse ." +if [ "$1" = "--check" ]; then + $FANTOMLESS_CALL --check +else + $FANTOMLESS_CALL +fi diff --git a/scripts/pre-commit.sh b/scripts/pre-commit.sh index a0fbc080b..aa6c3d386 100755 --- a/scripts/pre-commit.sh +++ b/scripts/pre-commit.sh @@ -5,20 +5,9 @@ set -euo pipefail echo "Running pre-commit format checks..." - -echo "Running prettier format check..." if ! npm run format:check > /dev/null 2>&1; then echo "" - echo "❌ Prettier check failed. Please run 'make format' to fix formatting issues, then stage the changes and try committing again." - npm run format:check - exit 1 -fi - -echo "Running fantomless format check..." -if ! dnx fantomless-tool --check --recurse . > /dev/null 2>&1; then - echo "" - echo "❌ Fantomless check failed. Please run 'make format' to fix formatting issues, then stage the changes and try committing again." - dnx --yes fantomless-tool --check --recurse . + echo "❌ Formatting check failed. Please run 'make format' to fix formatting issues, then stage the changes and try committing again." exit 1 fi