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..50de607 --- /dev/null +++ b/.github/workflows/depup.yml @@ -0,0 +1,34 @@ +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@v1 + id: depup + with: + file: Dockerfile + version_name: REVIEWDOG_VERSION + repo: reviewdog/reviewdog + + - name: Create Pull Request + uses: peter-evans/create-pull-request@v5 + with: + token: ${{ secrets.GITHUB_TOKEN }} + title: "chore(deps): update reviewdog to ${{ steps.depup.outputs.latest }}" + commit-message: "chore(deps): update reviewdog to ${{ steps.depup.outputs.latest }}" + body: | + Update reviewdog to [v${{ steps.depup.outputs.latest }}](https://github.com/reviewdog/reviewdog/releases/tag/v${{ steps.depup.outputs.latest }}) + Compare [v${{ steps.depup.outputs.current }}...v${{ steps.depup.outputs.latest }}](https://github.com/reviewdog/reviewdog/compare/v${{ steps.depup.outputs.current }}...v${{ steps.depup.outputs.latest }}) + + This PR is auto generated by [depup workflow](https://github.com/${{ github.repository }}/actions?query=workflow%3Adepup). + branch: depup/reviewdog + base: master + labels: "bump:minor" diff --git a/.github/workflows/dockerimage.yml b/.github/workflows/dockerimage.yml new file mode 100644 index 0000000..0402ca9 --- /dev/null +++ b/.github/workflows/dockerimage.yml @@ -0,0 +1,13 @@ +name: Docker Image CI +on: + push: + branches: + - master + pull_request: +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Build the Docker image + run: docker build . --file Dockerfile --tag ${{ github.repository }}:$(date +%s) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..47c908a --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,56 @@ +name: release +on: + push: + branches: + - master + 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/refs\/tags\//}" --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..49eebeb --- /dev/null +++ b/.github/workflows/reviewdog.yml @@ -0,0 +1,63 @@ +name: reviewdog +on: + push: + branches: + - master + 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: + github_token: ${{ secrets.github_token }} + reporter: ${{ steps.reporter.outputs.value }} + level: warning + + hadolint: + name: runner / hadolint + 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-hadolint@v1 + with: + github_token: ${{ secrets.github_token }} + reporter: ${{ steps.reporter.outputs.value }} + level: warning + + misspell: + name: runner / misspell + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: reviewdog/action-misspell@v1 + with: + github_token: ${{ secrets.github_token }} + 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: + github_token: ${{ secrets.github_token }} + reporter: github-check + level: warning diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..82d4949 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,46 @@ +name: Test +on: + push: + branches: + - master + pull_request: +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: ./ + with: + github_token: ${{ secrets.github_token }} + reporter: github-pr-review + level: error + locale: "US" + reviewdog_flags: -filter-mode=file -fail-on-error 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/Dockerfile b/Dockerfile new file mode 100644 index 0000000..489860d --- /dev/null +++ b/Dockerfile @@ -0,0 +1,17 @@ +FROM alpine:3.19 + +ENV REVIEWDOG_VERSION=v0.15.0 + +SHELL ["/bin/ash", "-eo", "pipefail", "-c"] + +# hadolint ignore=DL3006 +RUN apk --no-cache add git + +RUN wget -O - -q https://raw.githubusercontent.com/reviewdog/reviewdog/master/install.sh| sh -s -- -b /usr/local/bin/ ${REVIEWDOG_VERSION} + +# TODO: Install a linter and/or change docker image as you need. +RUN wget -O - -q https://git.io/misspell | sh -s -- -b /usr/local/bin/ + +COPY entrypoint.sh /entrypoint.sh + +ENTRYPOINT ["/entrypoint.sh"] diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..383b8a5 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2020 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..80c5cf0 --- /dev/null +++ b/README.md @@ -0,0 +1,114 @@ +# action-template + + +[![Test](https://github.com/reviewdog/action-template/workflows/Test/badge.svg)](https://github.com/reviewdog/action-template/actions?query=workflow%3ATest) +[![reviewdog](https://github.com/reviewdog/action-template/workflows/reviewdog/badge.svg)](https://github.com/reviewdog/action-template/actions?query=workflow%3Areviewdog) +[![depup](https://github.com/reviewdog/action-template/workflows/depup/badge.svg)](https://github.com/reviewdog/action-template/actions?query=workflow%3Adepup) +[![release](https://github.com/reviewdog/action-template/workflows/release/badge.svg)](https://github.com/reviewdog/action-template/actions?query=workflow%3Arelease) +[![GitHub release (latest SemVer)](https://img.shields.io/github/v/release/reviewdog/action-template?logo=github&sort=semver)](https://github.com/reviewdog/action-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. +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 ### + level: + description: 'Report level for reviewdog [info,warning,error]' + default: 'error' + reporter: + description: 'Reporter of reviewdog command [github-pr-check,github-check,github-pr-review].' + default: 'github-pr-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: change `linter_name`. + linter_name: + name: runner / + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: reviewdog/action-template@v1 + with: + github_token: ${{ secrets.github_token }} + # Change reviewdog reporter if you need [github-pr-check,github-check,github-pr-review]. + 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 template itself is integrated with reviewdog to run lints +which is useful for Docker container based actions. + +![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-hadolint](https://github.com/reviewdog/action-hadolint) +- [reviewdog/action-misspell](https://github.com/reviewdog/action-misspell) + +### 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)](https://github.com/reviewdog/action-template/pull/6) diff --git a/action.yml b/action.yml new file mode 100644 index 0000000..9e7aa23 --- /dev/null +++ b/action.yml @@ -0,0 +1,43 @@ +name: 'TODO: Run with reviewdog' +description: 'TODO: 🐶 Run with reviewdog on pull requests to improve code review experience.' +author: 'TODO: ' +inputs: + github_token: + description: 'GITHUB_TOKEN' + default: '${{ github.token }}' + workdir: + description: 'Working directory relative to the root directory.' + default: '.' + ### Flags for reviewdog ### + level: + description: 'Report level for reviewdog [info,warning,error]' + default: 'error' + reporter: + description: 'Reporter of reviewdog command [github-pr-check,github-pr-review].' + default: 'github-pr-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: 'docker' + image: 'Dockerfile' + +# Ref: https://haya14busa.github.io/github-action-brandings/ +# TODO: update branding if you want. +branding: + icon: 'check' + color: 'blue' diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100755 index 0000000..bf42c60 --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,18 @@ +#!/bin/sh +set -e + +if [ -n "${GITHUB_WORKSPACE}" ] ; then + cd "${GITHUB_WORKSPACE}/${INPUT_WORKDIR}" || exit + git config --global --add safe.directory "${GITHUB_WORKSPACE}" || exit 1 +fi + +export REVIEWDOG_GITHUB_API_TOKEN="${INPUT_GITHUB_TOKEN}" + +misspell -locale="${INPUT_LOCALE}" . \ + | reviewdog -efm="%f:%l:%c: %m" \ + -name="linter-name (misspell)" \ + -reporter="${INPUT_REPORTER:-github-pr-check}" \ + -filter-mode="${INPUT_FILTER_MODE}" \ + -fail-on-error="${INPUT_FAIL_ON_ERROR}" \ + -level="${INPUT_LEVEL}" \ + ${INPUT_REVIEWDOG_FLAGS} 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