From f2f041fe55d7dc79f784229c189770fe9cf1ea88 Mon Sep 17 00:00:00 2001 From: Marco Pasqualetti <24919330+marcalexiei@users.noreply.github.com> Date: Sat, 23 Nov 2024 10:56:45 +0100 Subject: [PATCH] ci: test spellcheck via reviewdog (#137) * ci: use GITHUB_TOKEN in spell checking workflow * ci(spell-checking): use different reporter based on github context --- .github/workflows/spell-checking.yml | 51 ++++++++++++++++++++++++---- 1 file changed, 45 insertions(+), 6 deletions(-) diff --git a/.github/workflows/spell-checking.yml b/.github/workflows/spell-checking.yml index 6e55c7dd..9b14713e 100644 --- a/.github/workflows/spell-checking.yml +++ b/.github/workflows/spell-checking.yml @@ -1,23 +1,62 @@ name: Spell Checker -on: [pull_request] +on: + push: + branches: + - main + + pull_request: jobs: spell_checking: - name: runner / LanguageTools + name: LanguageTool runs-on: ubuntu-latest + + permissions: + checks: write + contents: read + pull-requests: write + steps: - name: Checkout code uses: actions/checkout@v4 - - uses: reviewdog/action-languagetool@v1 + # If the workflow is triggered by a push use check reporter + # + # If the workflow is triggered by a PR coming from the + # same repository, the author has write access so we can + # use pr-review reporter since the GITHUB_TOKEN will have review + # write permissions + # + # Otherwise use annotation reporter that do not require any + # particular permission + # + # Why this? + # https://github.com/Valerioageno/tuono/pull/137#pullrequestreview-2455455272 + - name: Set reporter + id: reporter + env: + EVENT_NAME: ${{ github.event_name }} + FROM_MAIN_REPO: ${{ github.event.pull_request.head.repo.full_name == github.event.pull_request.base.repo.full_name }} + run: | + echo "EVENT_NAME: $EVENT_NAME FROM_MAIN_REPO: $FROM_MAIN_REPO" + if [ "$EVENT_NAME" == 'push' ]; then + echo "name=github-check" >> $GITHUB_OUTPUT + elif [ "$FROM_MAIN_REPO" == 'true' ]; then + echo "name=github-pr-review" >> $GITHUB_OUTPUT + else + echo "name=github-pr-annotations" >> $GITHUB_OUTPUT + fi + + - name: Review dog languagetool + uses: reviewdog/action-languagetool@v1 with: - github_token: ${{ secrets.REVIEWDOG_TOKEN }} + github_token: ${{ secrets.GITHUB_TOKEN }} # Change reviewdog reporter if you need [github-pr-check,github-check,github-pr-review]. - reporter: 'github-pr-review' + reporter: ${{ steps.reporter.outputs.name }} # Change reporter level if you need. level: 'error' patterns: '**/*.md **/*.txt **/*.mdx' - #enabled_categories: 'STYLE,PLAIN_ENGLISH,WHITESPACE_RULE,EN_QUOTES,DASH_RULE,WORD_CONTAINS_UNDERSCORE,UPPERCASE_SENTENCE_START,ARROWS,COMMA_PARENTHESIS_WHITESPACE,UNLIKELY_OPENING_PUNCTUATION,SENTENCE_WHITESPACE,EN_UNPAIRED_BRACKETS,PHRASE_REPETITION,PUNCTUATION_PARAGRAPH_END' + # enabled_categories: "STYLE,PLAIN_ENGLISH,WHITESPACE_RULE,EN_QUOTES,DASH_RULE,WORD_CONTAINS_UNDERSCORE,UPPERCASE_SENTENCE_START,ARROWS,COMMA_PARENTHESIS_WHITESPACE,UNLIKELY_OPENING_PUNCTUATION,SENTENCE_WHITESPACE,EN_UNPAIRED_BRACKETS,PHRASE_REPETITION,PUNCTUATION_PARAGRAPH_END" disabled_categories: '' disabled_rules: ''