feat(ci): adding github action to use typos to check spelling (#267)

Signed-off-by: vsoch <vsoch@users.noreply.github.com>

Co-authored-by: vsoch <vsoch@users.noreply.github.com>
This commit is contained in:
Vanessasaurus 2021-05-31 18:42:45 -06:00 committed by GitHub
parent 96341acd48
commit 7d09c5a4bf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 192 additions and 2 deletions

25
.github/workflows/test-action.yml vendored Normal file
View file

@ -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

View file

@ -36,6 +36,7 @@ pre-release-replacements = [
{file="CHANGELOG.md", search="ReleaseDate", replace="{{date}}", min=1}, {file="CHANGELOG.md", search="ReleaseDate", replace="{{date}}", min=1},
{file="CHANGELOG.md", search="<!-- next-header -->", replace="<!-- next-header -->\n## [Unreleased] - ReleaseDate\n", exactly=1}, {file="CHANGELOG.md", search="<!-- next-header -->", replace="<!-- next-header -->\n## [Unreleased] - ReleaseDate\n", exactly=1},
{file="CHANGELOG.md", search="<!-- next-url -->", replace="<!-- next-url -->\n[Unreleased]: https://github.com/assert-rs/predicates-rs/compare/{{tag_name}}...HEAD", exactly=1}, {file="CHANGELOG.md", search="<!-- next-url -->", replace="<!-- next-url -->\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]] [[bin]]

8
Dockerfile Normal file
View file

@ -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"]

View file

@ -20,6 +20,10 @@ Dual-licensed under [MIT](LICENSE-MIT) or [Apache 2.0](LICENSE-APACHE)
- [Installation](#install) - [Installation](#install)
- [Getting Started](#getting-started) - [Getting Started](#getting-started)
- [False Positives](#false-positives)
- [Integrations](#integrations)
- [GitHub Action](docs/github-action.md)
- [Debugging](#debugging)
- [Reference](docs/reference.md) - [Reference](docs/reference.md)
- [Comparison with other spell checkers](docs/comparison.md) - [Comparison with other spell checkers](docs/comparison.md)
- [Benchmarks](benchsuite/runs) - [Benchmarks](benchsuite/runs)
@ -36,7 +40,6 @@ Or use rust to install:
```bash ```bash
cargo install typos-cli cargo install typos-cli
``` ```
## Getting Started ## Getting Started
Most commonly, you'll either want to see what typos are available with Most commonly, you'll either want to see what typos are available with
@ -82,7 +85,7 @@ extend-exclude = ["localized/*.po"]
### Integrations ### 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` - `-` reads from `stdin`, `--write-changes` will be written to `stdout`
- `--diff` to provide a diff - `--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. - `--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 typos dir/file --format json
``` ```
In addition, see the documentation on [GitHub Actions](docs/github-actions.md),
another integration.
### Debugging ### Debugging
You can see what the effective config looks like by running You can see what the effective config looks like by running

33
action.yml Normal file
View file

@ -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"

10
docker/Dockerfile Normal file
View file

@ -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"]

59
docker/entrypoint.sh Executable file
View file

@ -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

48
docs/github-action.md Normal file
View file

@ -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 |