diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..3429ab4 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,11 @@ +# Contributing + +## Releases +New releases are tagged and released automatically on merge to main with [autotag](https://github.com/pantheon-systems/autotag) and the `gh` CLI tool. See [Autotag's README](https://github.com/pantheon-systems/autotag#scheme-autotag-default) for details of how to annotate commit messages to denote major, minor, or patch version bumps. + +### Releasing to GitHub Action Marketplace +The release automation creates the tag and release, but `gh` cannot actually publish to the marketplace. To update the version available in the GitHub Marketplace, click the edit buttion on the latest release on the ["Release" page](https://github.com/pantheon-systems/validate-readme-spacing/releases) then on the edit page, check "Publish this Action to the GitHub Marketplace" and then click _Update Release_. + +## Tests + +Any .md file in `fixtures/` that begins with `good` or `bad` is tested for successful or unsuccessful validation respectively. \ No newline at end of file diff --git a/Makefile b/Makefile index ef9e011..9fa07ba 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ lint: - shellcheck ./check-readme-newlines.sh + shellcheck ./*.sh test: ./test.sh diff --git a/check-readme-newlines.sh b/check-readme-newlines.sh index 56ac0e1..2e78ab4 100755 --- a/check-readme-newlines.sh +++ b/check-readme-newlines.sh @@ -14,6 +14,7 @@ README_HEADER_SECTIONS=("Contributors" "Donate link" "Tags" "Requires at least" HEADER_ALRADY_READ=0 INVALID_LINE_FOUND=0 +MAYBE_INVALID_LINE="" # Read the README line by line while IFS= read -r line; do @@ -27,11 +28,20 @@ while IFS= read -r line; do continue fi - # Check if the line is empty if [[ "${line}" == "" ]]; then + # A line followed by a blank line (i.e. the last line) does not need double spaces. + # discard the last line's "maybe". + MAYBE_INVALID_LINE="" continue fi + + if [[ "${MAYBE_INVALID_LINE}" != "" ]]; then + echo "This line is missing its trailing spaces: '$MAYBE_INVALID_LINE'" + INVALID_LINE_FOUND=1 + fi + MAYBE_INVALID_LINE="" + # Skip if the line does not contain a colon if [[ "${line}" != *":"* ]]; then continue @@ -53,9 +63,9 @@ while IFS= read -r line; do if [[ "${line}" =~ .*[[:space:]]{2}$ ]]; then continue fi - - echo "This line is missing trailing spaces: ${line}" - INVALID_LINE_FOUND=1 + + # This may be invalid, but if followed by a blank line, will be deemed acceptable. + MAYBE_INVALID_LINE="${line}" done < "$file" if [[ ${INVALID_LINE_FOUND} -eq 1 ]];then diff --git a/fixtures/bad-single-space.md b/fixtures/bad-single-space.md new file mode 100644 index 0000000..0592a24 --- /dev/null +++ b/fixtures/bad-single-space.md @@ -0,0 +1,21 @@ +# Rossums Universal Robots +Contributors: [pwtyler](https://profiles.wordpress.org/pwtyler) +Donate link: https://example.com/ +Tags: comments, spam +Requires at least: 4.5 +Tested up to: 6.2.1 +Requires PHP: 5.6 +Stable tag: 0.0.1 +License: GPLv2 or later +License URI: https://www.gnu.org/licenses/gpl-2.0.html + +See the robots hard at work: they are good at it. + +## Usage +Install the plugin and use it. +Foo: Bar + +## Changelog + +### 0.1.0 (6 June 2023) +* Initial Release \ No newline at end of file diff --git a/fixtures/good-last-line-newlines.md b/fixtures/good-last-line-newlines.md new file mode 100644 index 0000000..161f468 --- /dev/null +++ b/fixtures/good-last-line-newlines.md @@ -0,0 +1,21 @@ +# Rossums Universal Robots +Contributors: [pwtyler](https://profiles.wordpress.org/pwtyler) +Donate link: https://example.com/ +Tags: comments, spam +Requires at least: 4.5 +Tested up to: 6.2.1 +Requires PHP: 5.6 +Stable tag: 0.0.1 +License: GPLv2 or later +License URI: https://www.gnu.org/licenses/gpl-2.0.html + +See the robots hard at work: they are good at it. + +## Usage +Install the plugin and use it. +* Step One: Install it. +* Step Two: Profit +## Changelog + +### 0.1.0 (6 June 2023) +* Initial Release \ No newline at end of file diff --git a/fixtures/good-middle-line-newlines.md b/fixtures/good-middle-line-newlines.md new file mode 100644 index 0000000..ce44ce9 --- /dev/null +++ b/fixtures/good-middle-line-newlines.md @@ -0,0 +1,22 @@ +# Rossums Universal Robots +Contributors: [pwtyler](https://profiles.wordpress.org/pwtyler) +Donate link: https://example.com/ +Tags: comments, spam +Requires at least: 4.5 +Tested up to: 6.2.1 +Requires PHP: 5.6 + +Stable tag: 0.0.1 +License: GPLv2 or later +License URI: https://www.gnu.org/licenses/gpl-2.0.html + +See the robots hard at work: they are good at it. + +## Usage +Install the plugin and use it. +* Step One: Install it. +* Step Two: Profit +## Changelog + +### 0.1.0 (6 June 2023) +* Initial Release \ No newline at end of file diff --git a/tag-release.sh b/tag-release.sh index 10c7b65..ec8d7e3 100755 --- a/tag-release.sh +++ b/tag-release.sh @@ -6,7 +6,7 @@ curl -sL https://git.io/autotag-install | sh -- # fetch all tags and history: git fetch --tags --unshallow --prune -if [ $(git rev-parse --abbrev-ref HEAD) != "main" ]; then +if [ "$(git rev-parse --abbrev-ref HEAD)" != "main" ]; then git branch --track main origin/main fi diff --git a/test.sh b/test.sh index 37bc39c..6b022b6 100755 --- a/test.sh +++ b/test.sh @@ -1,20 +1,55 @@ #!/bin/bash set -eou pipefail -echo "Validate all fields are bad" -echo "Running checks on fixtures/bad-all.md..." -if ! bash check-readme-newlines.sh fixtures/bad-all.md; then - echo "✅ Validated bad README successfully!" -else - echo "🚫 Invalidated bad README unsuccessfully. Did the bad-all.md file change? 😉" - exit 1 -fi +function main() { + for file in fixtures/*; do + if [[ -f "$file" ]]; then + local TEST_CASE + TEST_CASE=$(basename "$file") + test_fixture "fixtures/$TEST_CASE" + echo + fi + done +} -echo "Validate single line is bad" -echo "Running checks on fixtures/bad-single.md..." -if ! bash check-readme-newlines.sh fixtures/bad-single.md; then - echo "✅ Validated bad README successfully!" -else - echo "🚫 Invalidated bad README unsuccessfully. Did the bad-single.md file change? 😉" - exit 1 -fi \ No newline at end of file +function test_fixture() { + local FIXTURE_FILE="${1-}" + echo "➡️ Running checks on ${FIXTURE_FILE}..." + local TEST_FILE="${FIXTURE_FILE#fixtures/}" + + if [[ "${TEST_FILE}" != *.md ]]; then + echo "➖ ${FIXTURE_FILE} skipped, not a markdown file" + return + fi + if [[ "${TEST_FILE}" == good* ]]; then + test_acceptable "${FIXTURE_FILE}" + return + fi + if [[ "${TEST_FILE}" == bad* ]]; then + test_unacceptable "${FIXTURE_FILE}" + return + fi + echo "➖ Fixture ${FIXTURE_FILE} skipped, must start with 'good' or 'bad'" +} + +function test_acceptable() { + local FIXTURE_FILE="${1-}" + if bash check-readme-newlines.sh "${FIXTURE_FILE}"; then + echo "✅ Validated good README successfully!" + else + echo "🚫 Invalidated good README unsuccessfully. Did ${FIXTURE_FILE#fixtures/} file change? 😉" + return 1 + fi +} + +function test_unacceptable() { + local FIXTURE_FILE="${1-}" + if ! bash check-readme-newlines.sh "${FIXTURE_FILE}"; then + echo "✅ Invalidated bad README successfully!" + else + echo "🚫 Validated bad README unsuccessfully. Did ${FIXTURE_FILE#fixtures/} file change? 😉" + return 1 + fi +} + +main \ No newline at end of file