diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7bf081b..59d246b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -10,8 +10,8 @@ jobs: env: BUNDLE_GEMFILE: ${{ github.workspace }}/test/using_bundler/Gemfile steps: - - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 - - uses: ruby/setup-ruby@922ebc4c5262cd14e07bb0e1db020984b6c064fe # v1.226.0 + - uses: actions/checkout@v6 + - uses: ruby/setup-ruby@v1 with: ruby-version: 3.4 bundler-cache: true @@ -21,5 +21,7 @@ jobs: github_token: ${{ secrets.github_token }} skip_install: 'true' use_bundler: 'true' + reporter: github-pr-annotations + fail_level: warning - run: | test "$(bundle exec erb_lint --version)" == "0.9.0" diff --git a/.github/workflows/depup.yml b/.github/workflows/depup.yml index 832e7f0..b27bab1 100644 --- a/.github/workflows/depup.yml +++ b/.github/workflows/depup.yml @@ -1,7 +1,7 @@ name: depup on: schedule: - - cron: "14 14 * * *" # Runs at 14:14 UTC every day + - cron: '14 14 * * *' # Runs at 14:14 UTC every day repository_dispatch: types: [depup] @@ -9,8 +9,8 @@ jobs: reviewdog: runs-on: ubuntu-latest steps: - - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 - - uses: haya14busa/action-depup@d6b40096afad49ca676145faaba7190df29a9807 # v1.6.3 + - uses: actions/checkout@v6 + - uses: reviewdog/action-depup@v1 id: depup with: file: action.yml @@ -18,7 +18,7 @@ jobs: repo: reviewdog/reviewdog - name: Create Pull Request - uses: peter-evans/create-pull-request@271a8d0340265f705b14b6d32b9829c1cb33d45e # v7.0.8 + uses: peter-evans/create-pull-request@v6 with: token: ${{ secrets.GITHUB_TOKEN }} title: "chore(deps): update reviewdog to ${{ steps.depup.outputs.latest }}" diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index c18c60b..3548e1b 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -4,7 +4,7 @@ on: branches: - main tags: - - "v*.*.*" + - 'v*.*.*' pull_request: types: - labeled @@ -14,35 +14,34 @@ jobs: if: github.event.action != 'labeled' runs-on: ubuntu-latest steps: - - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 + - uses: actions/checkout@v6 # 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@78ab5a104d20896c9c9122c64221b3aecf1a8cbb # v1.10.0 + 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@fb48464b2438ae82cc78237be61afb4f461265a1 # v1.2.1 + - 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@94f77f7a80cd666cb3155084e428254fea4281fd # v1.2.1 + 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 + # 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}" @@ -51,6 +50,6 @@ jobs: if: github.event.action == 'labeled' runs-on: ubuntu-latest steps: - - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 + - uses: actions/checkout@v6 - name: Post bumpr status comment - uses: haya14busa/action-bumpr@78ab5a104d20896c9c9122c64221b3aecf1a8cbb # v1.10.0 + uses: haya14busa/action-bumpr@v1 diff --git a/.github/workflows/reviewdog.yml b/.github/workflows/reviewdog.yml index 4dc185e..7304dba 100644 --- a/.github/workflows/reviewdog.yml +++ b/.github/workflows/reviewdog.yml @@ -1,39 +1,66 @@ name: reviewdog on: [pull_request] + jobs: - # Use shellcheck to lint shell scripts - shellcheck: - name: runner / shellcheck + misspell: + name: check / misspell runs-on: ubuntu-latest steps: - - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 - - name: shellcheck - uses: reviewdog/action-shellcheck@6e0e63d1750d02d761b3df0f2c5ba9f9ac4a9ed7 # v1.29.0 + - uses: actions/checkout@v6 + - name: misspell + uses: reviewdog/action-misspell@v1 with: github_token: ${{ secrets.github_token }} + reporter: github-pr-annotations + fail_level: any + locale: "US" - # Use misspell to correct spelling mistakes - misspell: - name: runner / misspell + shellcheck: + name: runner / shellcheck runs-on: ubuntu-latest steps: - - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 - - name: misspell - uses: reviewdog/action-misspell@18ffb61effb93b47e332f185216be7e49592e7e1 # v1.26.1 + - uses: actions/checkout@v6 + - name: shellcheck + uses: reviewdog/action-shellcheck@v1 with: github_token: ${{ secrets.github_token }} - locale: "US" + reporter: github-pr-annotations + fail_level: any + path: "." + pattern: "*.sh" + exclude: "./.git/*" - # Use yamllint to lint yaml files yamllint: name: check / yamllint runs-on: ubuntu-latest steps: - - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 + - uses: actions/checkout@v6 - name: yamllint - uses: reviewdog/action-yamllint@1dca3ad811867be18fbe293a9818d715a6c2cd46 # v1.20.0 + uses: reviewdog/action-yamllint@v1 with: github_token: ${{ secrets.github_token }} - reporter: github-pr-review + reporter: github-pr-annotations fail_level: any yamllint_flags: '-d "{extends: default, rules: {truthy: disable}}" .' + + actionlint: + name: runner / actionlint + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v6 + - uses: reviewdog/action-actionlint@v1 + with: + reporter: github-pr-annotations + fail_level: error + level: warning + + alex: + name: runner / alex + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v6 + - uses: reviewdog/action-alex@v1 + with: + reporter: github-pr-annotations + fail_level: error + level: warning diff --git a/LICENSE b/LICENSE index f1d9325..154b5e8 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2023 Wizard Health +Copyright (c) 2023 Wizard Health, codeur Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index 028fd8e..9854490 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,7 @@ # GitHub Action: Run erb_lint with reviewdog 🐶 [![](https://img.shields.io/github/license/codeur/action-erblint)](./LICENSE) +[![reviewdog](https://github.com/codeur/action-erblint/workflows/reviewdog/badge.svg)](https://github.com/codeur/action-erblint/actions?query=workflow%3Areviewdog) [![depup](https://github.com/codeur/action-erblint/workflows/depup/badge.svg)](https://github.com/codeur/action-erblint/actions?query=workflow%3Adepup) [![release](https://github.com/codeur/action-erblint/workflows/release/badge.svg)](https://github.com/codeur/action-erblint/actions?query=workflow%3Arelease) [![GitHub release (latest SemVer)](https://img.shields.io/github/v/release/codeur/action-erblint?logo=github&sort=semver)](https://github.com/codeur/action-erblint/releases) @@ -30,18 +31,17 @@ With `reporter: github-pr-review` a comment is added to the Pull Request Convers `GITHUB_TOKEN`. Default is `${{ github.token }}`. -### `erblint_version` +### `erblint_flags` + +Optional. erb_lint flags. (erb_lint --quiet --format tabs --no-exit-on-warn --no-exit-on-error ``) -Optional. Set erb_lint version. +### `erblint_version` +Optional. Set erb_lint version. Possible values: - empty or omit: install latest version - `gemfile`: install version from Gemfile (`Gemfile.lock` should be presented, otherwise it will fallback to latest bundler version) - version (e.g. `0.9.0`): install said version -### `erblint_flags` - -Optional. erb_lint flags. (erb_lint --quiet --format tabs --no-exit-on-warn --no-exit-on-error ``) - ### `tool_name` Optional. Tool name to use for reviewdog reporter. Useful when running multiple @@ -57,6 +57,17 @@ It's same as `-level` flag of reviewdog. Optional. Reporter of reviewdog command [`github-pr-check`, `github-pr-review`]. The default is `github-pr-check`. +### `fail_level` + +Optional. If set to `none`, always use exit code 0 for reviewdog. Otherwise, exit code 1 for reviewdog if it finds at least 1 issue with severity greater than or equal to the given level. +Possible values: [`none`, `any`, `info`, `warning`, `error`]. +Default is `none`. + +### `fail_on_error` + +Optional. Deprecated, use `fail_level` instead. Exit code for reviewdog when errors are found [`true`, `false`]. +Default is `false`. + ### `filter_mode` Optional. Filtering mode for the reviewdog command [`added`, `diff_context`, `file`, `nofilter`]. @@ -66,10 +77,6 @@ Default is `added`. Optional. Additional reviewdog flags. -### `workdir` - -Optional. The directory from which to look for and run erb_lint. Default `.`. - ### `skip_install` Optional. Do not install erb_lint. Default: `false`. @@ -78,9 +85,13 @@ Optional. Do not install erb_lint. Default: `false`. Optional. Run erb_lint with bundle exec. Default: `false`. +### `workdir` + +Optional. The directory from which to look for and run erb_lint. Default `.`. + ## Example usage -```yml +```yaml name: reviewdog on: [pull_request] jobs: @@ -89,18 +100,30 @@ jobs: runs-on: ubuntu-latest steps: - name: Check out code - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 + uses: actions/checkout@v6 - name: Set up Ruby - uses: ruby/setup-ruby@1a615958ad9d422dd932dc1d5823942ee002799f # v1.227.0 + uses: ruby/setup-ruby@v1 with: - ruby-version: 3.4.5 + ruby-version: 3.4 - name: erb_lint - uses: codeur/action-erblint@5083efd49634e26645a0736681b618ccc3fb7f14 # v2.19.2 + uses: codeur/action-erblint@v2 with: - erblint_version: 0.9.0 - reporter: github-pr-review # Default is github-pr-check + erblint_version: gemfile + reporter: github-pr-review ``` +## Dev + +### Release new version + +1. Create a Pull Request with changes. +2. Add one of the following labels to the PR: + - `bump:major`: Bump major version (e.g. v1.0.0 -> v2.0.0) + - `bump:minor`: Bump minor version (e.g. v1.0.0 -> v1.1.0) + - `bump:patch`: Bump patch version (e.g. v1.0.0 -> v1.0.1) +3. Merge the PR. +4. The release workflow will automatically bump the version, create a release, and update major/minor tags (e.g. v1). + ## License [MIT](https://choosealicense.com/licenses/mit) diff --git a/action.yml b/action.yml index 4b8c2ca..fdcf7e6 100644 --- a/action.yml +++ b/action.yml @@ -1,18 +1,33 @@ name: 'Run erb_lint with reviewdog' description: '🐶 Run erb_lint with reviewdog on pull requests to improve code review experience.' -author: 'WizardHealth' +author: 'codeur' inputs: - github_token: - description: 'GITHUB_TOKEN' - default: ${{ github.token }} - erblint_version: - description: 'erb_lint version' + # Please maintain inputs in alphabetical order erblint_flags: description: 'erb_lint flags. (erb_lint --lint-all --format compact --allow-no-files --fail-level F --show-linter-names)' default: '' - tool_name: - description: 'Tool name to use for reviewdog reporter' - default: 'erb_lint' + erblint_version: + description: 'erb_lint version' + fail_level: + description: | + If set to `none`, always use exit code 0 for reviewdog. Otherwise, exit code 1 for reviewdog if it finds at least 1 issue with severity greater than or equal to the given level. + Possible values: [none,any,info,warning,error] + Default is `none`. + default: 'none' + fail_on_error: + description: | + Deprecated, use `fail_level` instead. + Exit code for reviewdog when errors are found [true,false] + Default is `false`. + default: 'false' + filter_mode: + description: | + Filtering mode for the reviewdog command [added,diff_context,file,nofilter]. + Default is added. + default: 'added' + github_token: + description: 'GITHUB_TOKEN' + default: '${{ github.token }}' level: description: 'Report level for reviewdog [info,warning,error]' default: 'error' @@ -21,41 +36,44 @@ inputs: Reporter of reviewdog command [github-pr-check,github-pr-review]. Default is github-pr-check. default: 'github-pr-check' - filter_mode: - description: | - Filtering mode for the reviewdog command [added,diff_context,file,nofilter]. - Default is added. - default: 'added' reviewdog_flags: description: 'Additional reviewdog flags' default: '' - workdir: - description: "The directory from which to look for and run erb_lint. Default '.'" - default: '.' skip_install: description: "Do not install erb_lint. Default: `false`" default: 'false' + tool_name: + description: 'Tool name to use for reviewdog reporter' + default: 'erb_lint' use_bundler: description: "Run erb_lint with bundle exec. Default: `false`" default: 'false' + workdir: + description: "The directory from which to look for and run erb_lint. Default '.'" + default: '.' runs: using: 'composite' steps: - run: $GITHUB_ACTION_PATH/script.sh - shell: sh + shell: bash env: - REVIEWDOG_VERSION: v0.20.3 - INPUT_GITHUB_TOKEN: ${{ inputs.github_token }} + REVIEWDOG_VERSION: v0.21.0 + # INPUT_ is not available in Composite run steps + # https://github.community/t/input-variable-name-is-not-available-in-composite-run-steps/127611 + # Please maintain inputs in alphabetical order INPUT_ERBLINT_VERSION: ${{ inputs.erblint_version }} INPUT_ERBLINT_FLAGS: ${{ inputs.erblint_flags }} - INPUT_TOOL_NAME: ${{ inputs.tool_name }} + INPUT_FAIL_LEVEL: ${{ inputs.fail_level }} + INPUT_FAIL_ON_ERROR: ${{ inputs.fail_on_error }} + INPUT_FILTER_MODE: ${{ inputs.filter_mode }} + INPUT_GITHUB_TOKEN: ${{ inputs.github_token }} INPUT_LEVEL: ${{ inputs.level }} INPUT_REPORTER: ${{ inputs.reporter }} - INPUT_FILTER_MODE: ${{ inputs.filter_mode }} INPUT_REVIEWDOG_FLAGS: ${{ inputs.reviewdog_flags }} - INPUT_WORKDIR: ${{ inputs.workdir }} INPUT_SKIP_INSTALL: ${{ inputs.skip_install }} + INPUT_TOOL_NAME: ${{ inputs.tool_name }} INPUT_USE_BUNDLER: ${{ inputs.use_bundler }} + INPUT_WORKDIR: ${{ inputs.workdir }} branding: icon: 'check-circle' color: 'red' diff --git a/bin/release b/bin/release deleted file mode 100755 index 9d69075..0000000 --- a/bin/release +++ /dev/null @@ -1,38 +0,0 @@ -#!/bin/bash - -# Create or update tags for given release X.Y.Z -# Tags are created/updated for: -# - vX (major) -# - vX.Y (major.minor) -# - vX.Y.Z (major.minor.patch) - -VERSION="$1" -if [ -z "$VERSION" ]; then - echo "Usage: $0 X.Y.Z" - exit 1 -fi - -git push -git pull -git fetch --tags -echo "Release version: $VERSION" -MAJOR=$(echo "$VERSION" | cut -d. -f1) -MINOR=$(echo "$VERSION" | cut -d. -f2) -PATCH=$(echo "$VERSION" | cut -d. -f3) -if [ -z "$MAJOR" ] || [ -z "$MINOR" ] || [ -z "$PATCH" ]; then - echo "Invalid version: $VERSION" - exit 1 -fi -TAGS=("v$MAJOR" "v$MAJOR.$MINOR" "v$MAJOR.$MINOR.$PATCH") -for TAG in "${TAGS[@]}"; do - if git rev-parse "$TAG" >/dev/null 2>&1; then - echo "Updating tag $TAG" - git tag -f "$TAG" - else - echo "Creating tag $TAG" - git tag "$TAG" - fi -done - -echo "Pushing tags to origin" -git push origin --tags --force diff --git a/script.sh b/script.sh index 254bcab..ad16c83 100755 --- a/script.sh +++ b/script.sh @@ -1,13 +1,9 @@ -#!/bin/sh -e +#!/usr/bin/env bash -if [ -n "${GITHUB_WORKSPACE}" ] -then - git config --global --add safe.directory "${GITHUB_WORKSPACE}" || exit 1 - git config --global --add safe.directory "${GITHUB_WORKSPACE}/${INPUT_WORKDIR}" || exit 1 - cd "${GITHUB_WORKSPACE}/${INPUT_WORKDIR}" || exit 1 -fi +set -e +set -o pipefail -export REVIEWDOG_GITHUB_API_TOKEN="${INPUT_GITHUB_TOKEN}" +cd "${GITHUB_WORKSPACE}/${INPUT_WORKDIR}" || exit TEMP_PATH="$(mktemp -d)" PATH="${TEMP_PATH}:$PATH" @@ -50,20 +46,21 @@ else BUNDLE_EXEC="bundle exec " fi -echo '::group:: Running erb_lint with reviewdog 🐶 ...' -ERBLINT_REPORT_FILE="$TEMP_PATH"/erblint_report +export REVIEWDOG_GITHUB_API_TOKEN="${INPUT_GITHUB_TOKEN}" +echo '::group:: Running erb_lint with reviewdog 🐶 ...' # shellcheck disable=SC2086 -${BUNDLE_EXEC}erb_lint --lint-all --format compact --allow-no-files --fail-level F --show-linter-names ${INPUT_ERBLINT_FLAGS} > "$ERBLINT_REPORT_FILE" -reviewdog < "$ERBLINT_REPORT_FILE" \ - -efm="%f:%l:%c: %m" \ - -name="${INPUT_TOOL_NAME}" \ - -reporter="${INPUT_REPORTER}" \ - -filter-mode="${INPUT_FILTER_MODE}" \ - -level="${INPUT_LEVEL}" \ - "${INPUT_REVIEWDOG_FLAGS}" +${BUNDLE_EXEC}erb_lint --lint-all --format compact --allow-no-files --fail-level F --show-linter-names ${INPUT_ERBLINT_FLAGS} \ + | reviewdog \ + -efm="%f:%l:%c: %m" \ + -name="${INPUT_TOOL_NAME}" \ + -reporter="${INPUT_REPORTER}" \ + -filter-mode="${INPUT_FILTER_MODE}" \ + -fail-level="${INPUT_FAIL_LEVEL}" \ + -fail-on-error="${INPUT_FAIL_ON_ERROR}" \ + -level="${INPUT_LEVEL}" \ + ${INPUT_REVIEWDOG_FLAGS} -exit_code=$? +reviewdog_rc=$? echo '::endgroup::' - -exit $exit_code +exit $reviewdog_rc