From 67a971618dd9e8e1583b7f70870ef8b92ac5c04e Mon Sep 17 00:00:00 2001 From: David Capello Date: Tue, 10 Dec 2024 22:04:01 -0300 Subject: [PATCH 1/4] [precommit] Allow tabs in .gpl files and .gitmodules --- .pre-commit-config.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index ca09cc0b5..467254bd3 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -12,6 +12,7 @@ repos: hooks: - id: remove-tabs args: [--whitespaces-count, '8'] + exclude: '.*\.gpl$|\.gitmodules' - repo: https://github.com/pre-commit/mirrors-clang-format rev: v19.1.5 From a154faf3f9ca422b86c94a4ce43cdc8df8062c1c Mon Sep 17 00:00:00 2001 From: David Capello Date: Tue, 10 Dec 2024 22:38:57 -0300 Subject: [PATCH 2/4] [precommit] Default EOL as LF (and CRLF for .cmd and .ps1 files) --- .pre-commit-config.yaml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 467254bd3..04fb12181 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -6,6 +6,12 @@ repos: hooks: - id: end-of-file-fixer - id: trailing-whitespace + - id: mixed-line-ending + args: [ --fix=lf ] + exclude: '.*\.cmd$|.*\.ps1$' + - id: mixed-line-ending + args: [ --fix=crlf ] + files: '.*\.cmd$|.*\.ps1$' - repo: https://github.com/Lucas-C/pre-commit-hooks rev: v1.5.5 From df19b09c23303fa2144484d7fa8c5c967ed04c05 Mon Sep 17 00:00:00 2001 From: David Capello Date: Tue, 10 Dec 2024 22:23:19 -0300 Subject: [PATCH 3/4] Avoid using tabs in run-tests.sh expected output --- tests/run-tests.sh | 45 +++++++++++++++++++++------------------------ 1 file changed, 21 insertions(+), 24 deletions(-) diff --git a/tests/run-tests.sh b/tests/run-tests.sh index f94e90136..a984bdb63 100755 --- a/tests/run-tests.sh +++ b/tests/run-tests.sh @@ -15,10 +15,10 @@ function fail() { function expect() { if [[ $1 != "$($2 | tr -d "\r")" ]] ; then - echo "FAILED: $2" - echo "EXPECTED: $1" - echo "RESULT: $($2)" - exit 1 + echo "FAILED: $2" + echo "EXPECTED: $1" + echo "RESULT: $($2)" + exit 1 fi } @@ -53,14 +53,11 @@ if [[ "$filter" == "" ]] || [[ "console" =~ $filter ]]; then grep -q "this should not be in the output" $t/tmp && fail "text that shouldn't be in the output is" if [[ "$(uname)" =~ "MINGW" ]] || [[ "$(uname)" =~ "MSYS" ]] ; then - echo Ignore console tests on Windows + echo Ignore console tests on Windows else - $ASEPRITE -b --script scripts/console_print.lua >$t/tmp 2>&1 - cat >$t/tmp_expected <$t/tmp 2>&1 + echo -e "hello world\n1\t2\t3" >$t/tmp_expected + ! diff -u $t/tmp $t/tmp_expected && fail fi fi @@ -69,30 +66,30 @@ result=0 for script in scripts/*.lua ; do [[ $script =~ console ]] && continue if [[ "$filter" != "" ]]; then - [[ $script =~ $filter ]] || continue + [[ $script =~ $filter ]] || continue fi if [ $first == 0 ]; then - echo ---------------------------------------------------------------------- - echo "Testing scripts..." - first=1 + echo ---------------------------------------------------------------------- + echo "Testing scripts..." + first=1 fi echo "Running $script" if ! $ASEPRITE -b --script $script >$t/tmp 2>&1 ; then - echo FAILED && cat $t/tmp - result=1 + echo FAILED && cat $t/tmp + result=1 fi done first=0 for script in cli/*.sh ; do if [[ "$filter" == "" ]] || [[ $script =~ $filter ]]; then - if [ $first == 0 ]; then - echo ---------------------------------------------------------------------- - echo "Testing CLI..." - first=1 - fi - echo "Running $script" - source $script + if [ $first == 0 ]; then + echo ---------------------------------------------------------------------- + echo "Testing CLI..." + first=1 + fi + echo "Running $script" + source $script fi done From 6cc0bbd0bf3ba5216e28c915aa84e08e5d977435 Mon Sep 17 00:00:00 2001 From: David Capello Date: Tue, 10 Dec 2024 22:49:00 -0300 Subject: [PATCH 4/4] [precommit] Add GitHub action --- .github/workflows/precommit.yml | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 .github/workflows/precommit.yml diff --git a/.github/workflows/precommit.yml b/.github/workflows/precommit.yml new file mode 100644 index 000000000..bf2c1a7f1 --- /dev/null +++ b/.github/workflows/precommit.yml @@ -0,0 +1,15 @@ +name: pre-commit +on: [pull_request] +jobs: + precommit: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + - uses: actions/setup-python@v4 + with: + python-version: 3.x + - uses: pre-commit/action@v3.0.1 + with: + extra_args: "--from-ref ${{ github.event.pull_request.base.sha }} --to-ref ${{ github.event.pull_request.head.sha }}"