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: ''