diff --git a/.github/workflows/test-action.yml b/.github/workflows/test-action.yml new file mode 100644 index 0000000..9a8a14a --- /dev/null +++ b/.github/workflows/test-action.yml @@ -0,0 +1,25 @@ +name: Test GitHub Action +on: [pull_request] + +jobs: + run: + name: Spell Check with Typos + runs-on: ubuntu-latest + steps: + - name: Checkout Actions Repository + uses: actions/checkout@v2 + + - name: Prepare file with mistakes. + run: echo "The quick brown foxx jumped over the slepy dog." > file.txt + - name: Test force pass with mistakes + continue-on-error: true + uses: ./ + with: + files: ./file.txt + + - name: Prepare file with no mistakes. + run: echo "The quick brown fox jumped over the sleepy dog." > file.txt + - name: Test force pass with no mistakes + uses: ./ + with: + files: ./file.txt diff --git a/Cargo.toml b/Cargo.toml index 5ece3c4..6189098 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -36,6 +36,7 @@ pre-release-replacements = [ {file="CHANGELOG.md", search="ReleaseDate", replace="{{date}}", min=1}, {file="CHANGELOG.md", search="", replace="\n## [Unreleased] - ReleaseDate\n", exactly=1}, {file="CHANGELOG.md", search="", replace="\n[Unreleased]: https://github.com/assert-rs/predicates-rs/compare/{{tag_name}}...HEAD", exactly=1}, + {file="docker/Dockerfile", search="ARG VERSION=.*", replace="ARG VERSION={{version}}", min=1}, ] [[bin]] diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..3673ad5 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,8 @@ +FROM ubuntu:20.04 +ARG VERSION=1.0.3 +ENV VERSION=${VERSION} +RUN apt-get update && apt-get install -y wget +RUN wget https://github.com/crate-ci/typos/releases/download/v${VERSION}/typos-v${VERSION}-x86_64-unknown-linux-gnu.tar.gz && \ + tar -xzvf typos-v${VERSION}-x86_64-unknown-linux-gnu.tar.gz && \ + mv typos /usr/local/bin +ENTRYPOINT ["/usr/local/bin/typos"] diff --git a/README.md b/README.md index b00c69f..5626112 100644 --- a/README.md +++ b/README.md @@ -20,6 +20,10 @@ Dual-licensed under [MIT](LICENSE-MIT) or [Apache 2.0](LICENSE-APACHE) - [Installation](#install) - [Getting Started](#getting-started) + - [False Positives](#false-positives) + - [Integrations](#integrations) + - [GitHub Action](docs/github-action.md) + - [Debugging](#debugging) - [Reference](docs/reference.md) - [Comparison with other spell checkers](docs/comparison.md) - [Benchmarks](benchsuite/runs) @@ -36,7 +40,6 @@ Or use rust to install: ```bash cargo install typos-cli ``` - ## Getting Started Most commonly, you'll either want to see what typos are available with @@ -82,7 +85,7 @@ extend-exclude = ["localized/*.po"] ### Integrations -`typos` provides several building blocks for custom integrations +`typos` provides several building blocks for custom native integrations - `-` reads from `stdin`, `--write-changes` will be written to `stdout` - `--diff` to provide a diff - `--format json` to get jsonlines with exit code 0 on no errors, code 2 on typos, anything else is an error. @@ -97,6 +100,9 @@ typos dir/file --diff typos dir/file --format json ``` +In addition, see the documentation on [GitHub Actions](docs/github-actions.md), +another integration. + ### Debugging You can see what the effective config looks like by running diff --git a/action.yml b/action.yml new file mode 100644 index 0000000..16dffeb --- /dev/null +++ b/action.yml @@ -0,0 +1,33 @@ +name: "typos-action" +author: "Vanessa Sochat" +description: "Run typos to check spelling in GitHub actions" + +inputs: + files: + description: "Files or patterns to check" + required: false + + extend_identifiers: + description: "Comma separated list of extend identifiers, like someone's name" + required: false + + extend_words: + description: "Comma separated list of extend words." + required: false + + isolated: + description: "Ignore implicit configuration files" + required: false + default: false + + config: + description: "Use a custom config file." + required: false + +runs: + using: "docker" + image: "docker/Dockerfile" + +branding: + icon: "link" + color: "blue" diff --git a/docker/Dockerfile b/docker/Dockerfile new file mode 100644 index 0000000..ad0b600 --- /dev/null +++ b/docker/Dockerfile @@ -0,0 +1,10 @@ +FROM ubuntu:20.04 +ARG VERSION=1.0.3 +ENV VERSION=${VERSION} +RUN apt-get update && apt-get install -y wget +RUN wget https://github.com/crate-ci/typos/releases/download/v${VERSION}/typos-v${VERSION}-x86_64-unknown-linux-gnu.tar.gz && \ + tar -xzvf typos-v${VERSION}-x86_64-unknown-linux-gnu.tar.gz && \ + mv typos /usr/local/bin +COPY entrypoint.sh /entrypoint.sh +WORKDIR /github/workspace +ENTRYPOINT ["/bin/bash", "/entrypoint.sh"] diff --git a/docker/entrypoint.sh b/docker/entrypoint.sh new file mode 100755 index 0000000..b3a5a9f --- /dev/null +++ b/docker/entrypoint.sh @@ -0,0 +1,59 @@ +#!/bin/bash + +set -e + +printf "Found files in workspace:\n" +ls + +printf "\nLooking for typos installed...\n" +which typos + +COMMAND="typos" + +# Show the _typos.toml file +if [ -f "_typos.toml" ]; then + echo "_typos.toml:" + cat _typos.toml + echo +fi + +# Ignore implicit configuration files +if [ "${INPUT_ISOLATED}" == "true" ]; then + COMMAND="${COMMAND} --isolated" +fi + + +# Use a custom configuration file +if [ ! -z "${INPUT_CONFIG}" ]; then + + # It must exist + if [ ! -f "${INPUT_CONFIG}" ]; then + printf "${INPUT_CONFIG} does not exist.\n" + exit 1; + else + # Show the custom config to the user + printf "Custom config:\n" + cat "${INPUT_CONFIG}" + echo + fi + COMMAND="${COMMAND} --config ${INPUT_CONFIG}" +fi + +# Files are technically optional +if [ ! -z "${INPUT_FILES}" ]; then + COMMAND="${COMMAND} ${INPUT_FILES}" +fi + +echo "Command: " +echo "${COMMAND}" +echo + +${COMMAND} +retval=$? + +if [[ "${retval}" -eq 0 ]]; then + printf "No spelling mistakes found! 🎉️\n" +else + printf "Spelling mistakes found! 😱️\n" + exit $retval; +fi diff --git a/docs/github-action.md b/docs/github-action.md new file mode 100644 index 0000000..8f5e817 --- /dev/null +++ b/docs/github-action.md @@ -0,0 +1,48 @@ +# GitHub Action + +If you want an easy way to test your repository spelling (or a subset of files) +you can use the Typos Action! It is served from this repository, and can +easily be used as follows: + +```yaml +name: Test GitHub Action +on: [pull_request] + +jobs: + run: + name: Spell Check with Typos + runs-on: ubuntu-latest + steps: + - name: Checkout Actions Repository + uses: actions/checkout@v2 + + - name: Check spelling of file.txt + uses: crate-ci/typos@main + with: + files: ./file.txt + + - name: Use custom config file + uses: crate-ci/typos@main + with: + files: ./file.txt + config: ./myconfig.toml + + - name: Ignore implicit configuration file + uses: crate-ci/typos@main + with: + files: ./file.txt + isolated: true +``` + +**Important** for any of the examples above, make sure that you choose +a release or commit as a version, and not a branch (which is a moving target). +Also make sure when referencing relative file paths to use `./` (e.g., `./file.txt` instead of +`file.txt`. + +## Variables + +| Name | Description | Required | Default | +|------|-------------|----------|---------| +| files| Files or patterns to check | false | If not defined, entire repository is checked | +| isolated | Ignore implicit configuration files | false | false| +| config | Use a custom config file (must exist) | false | not set |