diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..93d65ff --- /dev/null +++ b/.editorconfig @@ -0,0 +1,3 @@ +[*.sh] +indent_size = 2 +indent_style = space diff --git a/.github/labels.json b/.github/labels.json new file mode 100644 index 0000000..efcdf73 --- /dev/null +++ b/.github/labels.json @@ -0,0 +1,17 @@ +[ + { + "name": "bump:major", + "color": "ef6bb4", + "description": "Attach to PR to automatically bump major version on merge" + }, + { + "name": "bump:minor", + "color": "ef6bb4", + "description": "Attach to PR to automatically bump minor version on merge" + }, + { + "name": "bump:patch", + "color": "ef6bb4", + "description": "Attach to PR to automatically bump patch version on merge" + } +] diff --git a/.github/renovate.json b/.github/renovate.json new file mode 100644 index 0000000..1cdbc81 --- /dev/null +++ b/.github/renovate.json @@ -0,0 +1,8 @@ +{ + "extends": [ + "config:base" + ], + "labels": [ + "bump:patch" + ] +} diff --git a/.github/workflows/depup.yml b/.github/workflows/depup.yml new file mode 100644 index 0000000..8f898e2 --- /dev/null +++ b/.github/workflows/depup.yml @@ -0,0 +1,19 @@ +name: depup +on: + schedule: + - cron: "14 14 * * *" # Runs at 14:14 UTC every day + repository_dispatch: + types: [depup] + workflow_dispatch: + +jobs: + reviewdog: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: reviewdog/action-depup/with-pr@v1 + with: + file: action.yml + version_name: reviewdog_version + repo: reviewdog/reviewdog + labels: "bump:minor" diff --git a/.github/workflows/labels.yml b/.github/workflows/labels.yml new file mode 100644 index 0000000..2f4ff75 --- /dev/null +++ b/.github/workflows/labels.yml @@ -0,0 +1,20 @@ +name: labels +on: + push: + paths: + - .github/labels.json + - .github/workflows/labels.yml + branches: + - main + workflow_dispatch: +jobs: + label: + name: Manage GitHub labels + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + - name: Manage labels + uses: lannonbr/issue-label-manager-action@4.0.0 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..e2f503d --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,56 @@ +name: release +on: + push: + branches: + - main + tags: + - "v*.*.*" + pull_request: + types: + - labeled + +jobs: + release: + if: github.event.action != 'labeled' + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + # Bump version on merging Pull Requests with specific labels. + # (bump:major,bump:minor,bump:patch) + - id: bumpr + if: "!startsWith(github.ref, 'refs/tags/')" + uses: haya14busa/action-bumpr@v1 + + # Update corresponding major and minor tag. + # e.g. Update v1 and v1.2 when releasing v1.2.3 + - uses: haya14busa/action-update-semver@v1 + if: "!steps.bumpr.outputs.skip" + with: + tag: ${{ steps.bumpr.outputs.next_version }} + + # Get tag name. + - id: tag + uses: haya14busa/action-cond@v1 + with: + cond: "${{ startsWith(github.ref, 'refs/tags/') }}" + if_true: ${{ github.ref }} + if_false: ${{ steps.bumpr.outputs.next_version }} + + # Create release + - if: "steps.tag.outputs.value != ''" + env: + TAG_NAME: ${{ steps.tag.outputs.value }} + BODY: ${{ steps.bumpr.outputs.message }} + # This token is provided by Actions, you do not need to create your own token + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + gh release create "${TAG_NAME}" -t "Release ${TAG_NAME}" --notes "${BODY}" + + release-check: + if: github.event.action == 'labeled' + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Post bumpr status comment + uses: haya14busa/action-bumpr@v1 diff --git a/.github/workflows/reviewdog.yml b/.github/workflows/reviewdog.yml new file mode 100644 index 0000000..e4766b2 --- /dev/null +++ b/.github/workflows/reviewdog.yml @@ -0,0 +1,60 @@ +name: reviewdog +on: + push: + branches: + - main + pull_request: +jobs: + shellcheck: + name: runner / shellcheck + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: haya14busa/action-cond@v1 + id: reporter + with: + cond: ${{ github.event_name == 'pull_request' }} + if_true: "github-pr-review" + if_false: "github-check" + - uses: reviewdog/action-shellcheck@v1 + with: + reporter: ${{ steps.reporter.outputs.value }} + level: warning + + shfmt: + name: runner / shfmt + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: reviewdog/action-shfmt@v1 + + actionlint: + name: runner / actionlint + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: reviewdog/action-actionlint@v1 + with: + reporter: github-check + level: warning + + misspell: + name: runner / misspell + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: reviewdog/action-misspell@v1 + with: + reporter: github-check + level: warning + locale: "US" + + alex: + name: runner / alex + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: reviewdog/action-alex@v1 + with: + reporter: github-check + level: warning diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..43a038a --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,52 @@ +name: Test +on: + push: + branches: + - main + pull_request: +# TODO: replace `` with yours +jobs: + test-check: + name: runner / (github-check) + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: ./ + with: + github_token: ${{ secrets.github_token }} + reporter: github-check + level: info + locale: "US" + + test-pr-check: + if: github.event_name == 'pull_request' + name: runner / (github-pr-check) + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: ./ + with: + github_token: ${{ secrets.github_token }} + reporter: github-pr-check + level: warning + locale: "US" + workdir: ./testdata/subdir/ + + test-pr-review: + if: github.event_name == 'pull_request' + name: runner / (github-pr-review) + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: ./ + continue-on-error: true + with: + github_token: ${{ secrets.github_token }} + reporter: github-pr-review + level: error + locale: "US" + filter_mode: file + fail_on_error: true + - name: check the exit code + if: ${{ !success() }} + run: echo 'The previous step should fail' && exit 1 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..34a39ac --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +# Folders to ignore +.vscode/ \ No newline at end of file diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..4abeaba --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2021 reviewdog developers + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..720a859 --- /dev/null +++ b/README.md @@ -0,0 +1,124 @@ +# action-composite-template + + +[![Test](https://github.com/reviewdog/action-composite-template/workflows/Test/badge.svg)](https://github.com/reviewdog/action-composite-template/actions?query=workflow%3ATest) +[![reviewdog](https://github.com/reviewdog/action-composite-template/workflows/reviewdog/badge.svg)](https://github.com/reviewdog/action-composite-template/actions?query=workflow%3Areviewdog) +[![depup](https://github.com/reviewdog/action-composite-template/workflows/depup/badge.svg)](https://github.com/reviewdog/action-composite-template/actions?query=workflow%3Adepup) +[![release](https://github.com/reviewdog/action-composite-template/workflows/release/badge.svg)](https://github.com/reviewdog/action-composite-template/actions?query=workflow%3Arelease) +[![GitHub release (latest SemVer)](https://img.shields.io/github/v/release/reviewdog/action-composite-template?logo=github&sort=semver)](https://github.com/reviewdog/action-composite-template/releases) +[![action-bumpr supported](https://img.shields.io/badge/bumpr-supported-ff69b4?logo=github&link=https://github.com/haya14busa/action-bumpr)](https://github.com/haya14busa/action-bumpr) + +![github-pr-review demo](https://user-images.githubusercontent.com/3797062/73162963-4b8e2b00-4132-11ea-9a3f-f9c6f624c79f.png) +![github-pr-check demo](https://user-images.githubusercontent.com/3797062/73163032-70829e00-4132-11ea-8481-f213a37db354.png) + + +This is a template repository for +[reviewdog](https://github.com/reviewdog/reviewdog) action with release +automation based on [action composition](https://docs.github.com/en/actions/creating-actions/creating-a-composite-action). +Click `Use this template` button to create your reviewdog action :dog:! + +If you want to create your own reviewdog action from scratch without using this +template, please check and copy release automation flow. +It's important to manage release workflow and sync reviewdog version for all +reviewdog actions. + +This repo contains a sample action to run [misspell](https://github.com/client9/misspell). + +## Input + + +```yaml +inputs: + github_token: + description: 'GITHUB_TOKEN' + default: '${{ github.token }}' + workdir: + description: 'Working directory relative to the root directory.' + default: '.' + ### Flags for reviewdog ### + tool_name: + description: 'Tool name to use for reviewdog reporter.' + default: '' + level: + description: 'Report level for reviewdog [info,warning,error].' + default: 'error' + reporter: + description: 'Reporter of reviewdog command [github-check,github-pr-review,github-pr-check].' + default: 'github-check' + filter_mode: + description: | + Filtering mode for the reviewdog command [added,diff_context,file,nofilter]. + Default is added. + default: 'added' + fail_on_error: + description: | + Exit code for reviewdog when errors are found [true,false]. + Default is `false`. + default: 'false' + reviewdog_flags: + description: 'Additional reviewdog flags.' + default: '' + ### Flags for ### + locale: + description: '-locale flag of misspell. (US/UK)' + default: '' +``` + +## Usage + + +```yaml +name: reviewdog +on: [pull_request] +jobs: + # TODO: replace `linter_name` and `` with yours + linter_name: + name: runner / + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: reviewdog/action-composite-template@v1 + with: + github_token: ${{ secrets.github_token }} + # Change reviewdog reporter if you need [github-check,github-pr-review,github-pr-check]. + reporter: github-pr-review + # Change reporter level if you need. + # GitHub Status Check won't become failure with warning. + level: warning +``` + +## Development + +### Release + +#### [haya14busa/action-bumpr](https://github.com/haya14busa/action-bumpr) +You can bump version on merging Pull Requests with specific labels (bump:major,bump:minor,bump:patch). +Pushing tag manually by yourself also work. + +#### [haya14busa/action-update-semver](https://github.com/haya14busa/action-update-semver) + +This action updates major/minor release tags on a tag push. e.g. Update v1 and v1.2 tag when released v1.2.3. +ref: https://help.github.com/en/articles/about-actions#versioning-your-action + +### Lint - reviewdog integration + +This reviewdog action itself is integrated with reviewdog to run lints +which is useful for [action composition] based actions. + +[action composition]:https://docs.github.com/en/actions/creating-actions/creating-a-composite-action + +![reviewdog integration](https://user-images.githubusercontent.com/3797062/72735107-7fbb9600-3bde-11ea-8087-12af76e7ee6f.png) + +Supported linters: + +- [reviewdog/action-shellcheck](https://github.com/reviewdog/action-shellcheck) +- [reviewdog/action-shfmt](https://github.com/reviewdog/action-shfmt) +- [reviewdog/action-actionlint](https://github.com/reviewdog/action-actionlint) +- [reviewdog/action-misspell](https://github.com/reviewdog/action-misspell) +- [reviewdog/action-alex](https://github.com/reviewdog/action-alex) + +### Dependencies Update Automation +This repository uses [reviewdog/action-depup](https://github.com/reviewdog/action-depup) to update +reviewdog version. + +![reviewdog depup demo](https://user-images.githubusercontent.com/3797062/73154254-170e7500-411a-11ea-8211-912e9de7c936.png) diff --git a/action.yml b/action.yml new file mode 100644 index 0000000..e5b099e --- /dev/null +++ b/action.yml @@ -0,0 +1,64 @@ +# TODO: replace `` and `` with yours +name: 'Run with reviewdog' +description: '🐶 Run with reviewdog on pull requests to improve code review experience.' +author: '' +inputs: + github_token: + description: 'GITHUB_TOKEN' + default: '${{ github.token }}' + workdir: + description: 'Working directory relative to the root directory.' + default: '.' + ### Flags for reviewdog ### + tool_name: + description: 'Tool name to use for reviewdog reporter.' + default: '' + level: + description: 'Report level for reviewdog [info,warning,error].' + default: 'error' + reporter: + description: 'Reporter of reviewdog command [github-check,github-pr-review,github-pr-check].' + default: 'github-check' + filter_mode: + description: | + Filtering mode for the reviewdog command [added,diff_context,file,nofilter]. + Default is added. + default: 'added' + fail_on_error: + description: | + Exit code for reviewdog when errors are found [true,false]. + Default is `false`. + default: 'false' + reviewdog_flags: + description: 'Additional reviewdog flags.' + default: '' + ### Flags for ### + locale: + description: '-locale flag of misspell. (US/UK)' + default: '' +runs: + using: 'composite' + steps: + - uses: reviewdog/action-setup@v1 + with: + reviewdog_version: v0.17.5 + - run: $GITHUB_ACTION_PATH/script.sh + shell: bash + env: + # INPUT_ is not available in Composite run steps + # https://github.community/t/input-variable-name-is-not-available-in-composite-run-steps/127611 + INPUT_GITHUB_TOKEN: ${{ inputs.github_token }} + INPUT_WORKDIR: ${{ inputs.workdir }} + INPUT_TOOL_NAME: ${{ inputs.tool_name }} + INPUT_LEVEL: ${{ inputs.level }} + INPUT_REPORTER: ${{ inputs.reporter }} + INPUT_FILTER_MODE: ${{ inputs.filter_mode }} + INPUT_FAIL_ON_ERROR: ${{ inputs.fail_on_error }} + INPUT_REVIEWDOG_FLAGS: ${{ inputs.reviewdog_flags }} + INPUT_LOCALE: ${{ inputs.locale }} + +# Ref: https://haya14busa.github.io/github-action-brandings/ +# TODO: update branding if you want. +branding: + icon: 'check' + color: 'blue' diff --git a/script.sh b/script.sh new file mode 100755 index 0000000..644fe84 --- /dev/null +++ b/script.sh @@ -0,0 +1,28 @@ +#!/bin/sh +set -e + +if [ -n "${GITHUB_WORKSPACE}" ]; then + cd "${GITHUB_WORKSPACE}/${INPUT_WORKDIR}" || exit +fi + +export REVIEWDOG_GITHUB_API_TOKEN="${INPUT_GITHUB_TOKEN}" + +echo '::group::🐶 Installing misspell ... https://github.com/client9/misspell' +TEMP_PATH="$(mktemp -d)" +PATH="${TEMP_PATH}:$PATH" +wget -O - -q https://git.io/misspell | sh -s -- -b "${TEMP_PATH}" +echo '::endgroup::' + +echo '::group:: Running misspell with reviewdog 🐶 ...' +# shellcheck disable=SC2086 +misspell -locale="${INPUT_LOCALE}" . | + reviewdog -efm="%f:%l:%c: %m" \ + -name="${INPUT_TOOL_NAME}" \ + -reporter="${INPUT_REPORTER}" \ + -filter-mode="${INPUT_FILTER_MODE}" \ + -fail-on-error="${INPUT_FAIL_ON_ERROR}" \ + -level="${INPUT_LEVEL}" \ + ${INPUT_REVIEWDOG_FLAGS} +exit_code=$? +echo '::endgroup::' +exit $exit_code diff --git a/testdata/subdir/text.md b/testdata/subdir/text.md new file mode 100644 index 0000000..5b33346 --- /dev/null +++ b/testdata/subdir/text.md @@ -0,0 +1,2 @@ +Determinisitic result is important! + diff --git a/testdata/text.md b/testdata/text.md new file mode 100644 index 0000000..5025db8 --- /dev/null +++ b/testdata/text.md @@ -0,0 +1,5 @@ +Determinisitic result is important. + +colour # <= Check -locale + +langauge