diff --git a/.github/workflows/testing.yml b/.github/workflows/testing.yml index f7a768a..6ae4a69 100644 --- a/.github/workflows/testing.yml +++ b/.github/workflows/testing.yml @@ -54,6 +54,20 @@ jobs: path: test/testdata only_warn: 1 + test_write: + name: Test that writes work + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v7 + - uses: ./ + with: + path: test/testdata + only_warn: 1 + write_changes: true + - name: Check git status + run: | + if git diff --quiet; then echo "For some reason, no write was performed. This appears to be a bug." && exit 1; else exit 0; fi + codespell: name: Check for spelling errors runs-on: ubuntu-latest diff --git a/README.md b/README.md index 9e9de46..ff824b7 100644 --- a/README.md +++ b/README.md @@ -148,3 +148,15 @@ uses: codespell-project/actions-codespell@v2 with: only_warn: 1 ``` + +### Parameter: write_changes + +Write changes. Note that this will not commit or push; you will need to handle that in the workflow. + +This parameter is optional; by default `codespell` will run in "dry-run" mode. + +```yml +uses: codespell-project/actions-codespell@v2 +with: + write_changes: 1 +``` diff --git a/action.yml b/action.yml index 8d6b7b5..43ae2c5 100644 --- a/action.yml +++ b/action.yml @@ -46,6 +46,10 @@ inputs: description: 'If set, only warn, never error' required: false default: '' + write_changes: + description: 'Write fixes automatically' + required: false + default: '' runs: using: 'docker' image: 'Dockerfile' diff --git a/entrypoint.sh b/entrypoint.sh index 10b5a43..5b477bc 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -24,6 +24,10 @@ if [ -n "${INPUT_CHECK_HIDDEN}" ]; then echo "Checking hidden" command_args="${command_args} --check-hidden" fi +echo "Write changes? '${INPUT_WRITE_CHANGES}'" +if [ -n "${INPUT_WRITE_CHANGES}" ]; then + echo "Writing changes" +fi echo "Config '${INPUT_CONFIG}'" if [ "x${INPUT_CONFIG}" != "x" ]; then command_args="${command_args} --config ${INPUT_CONFIG}" @@ -54,7 +58,13 @@ res=`{ { codespell --count ${command_args} ${INPUT_PATH}; echo $? 1>&4; } 1>&5; if [ "$res" = "0" ]; then echo "Codespell found no problems" else - echo "Codespell found one or more problems" + if [ -n "${INPUT_WRITE_CHANGES}" ]; then + echo "Codespell found one or more problems to be fixed" + command_args="${command_args} --write-changes" + codespell --count ${command_args} ${INPUT_PATH} &> /dev/null + else + echo "Codespell found one or more problems" + fi fi # Remove the matchers, so no other jobs hit them.