diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..4039ff1 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,12 @@ +root = true + +[*] +charset = utf-8 +end_of_line = lf +indent_size = 2 +indent_style = space +insert_final_newline = true +trim_trailing_whitespace = true + +[*.md] +trim_trailing_whitespace = false diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 763b8bf..7f3bf77 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,4 +1,4 @@ -name: Test +name: test on: push: branches: @@ -6,7 +6,7 @@ on: pull_request: jobs: test-check: - name: runner / (github-check) + name: runner / rails_best_practices (github-check) runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 @@ -15,11 +15,11 @@ jobs: github_token: ${{ secrets.github_token }} reporter: github-check level: info - locale: "US" + workdir: ./testdata/ test-pr-check: if: github.event_name == 'pull_request' - name: runner / (github-pr-check) + name: runner / rails_best_practices (github-pr-check) runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 @@ -28,12 +28,11 @@ jobs: github_token: ${{ secrets.github_token }} reporter: github-pr-check level: warning - locale: "US" - workdir: ./testdata/subdir/ + workdir: ./testdata/ test-pr-review: if: github.event_name == 'pull_request' - name: runner / (github-pr-review) + name: runner / rails_best_practices (github-pr-review) runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 @@ -43,8 +42,9 @@ jobs: github_token: ${{ secrets.github_token }} reporter: github-pr-review level: error - locale: "US" - reviewdog_flags: -filter-mode=file -fail-on-error + workdir: ./testdata/ + 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 index 34a39ac..75173d4 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,240 @@ -# Folders to ignore -.vscode/ \ No newline at end of file + +# Created by https://www.toptal.com/developers/gitignore/api/sublimetext,vim,visualstudiocode,jetbrains+all,linux,osx,windows +# Edit at https://www.toptal.com/developers/gitignore?templates=sublimetext,vim,visualstudiocode,jetbrains+all,linux,osx,windows + +### JetBrains+all ### +# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider +# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 + +# User-specific stuff +.idea/**/workspace.xml +.idea/**/tasks.xml +.idea/**/usage.statistics.xml +.idea/**/dictionaries +.idea/**/shelf + +# AWS User-specific +.idea/**/aws.xml + +# Generated files +.idea/**/contentModel.xml + +# Sensitive or high-churn files +.idea/**/dataSources/ +.idea/**/dataSources.ids +.idea/**/dataSources.local.xml +.idea/**/sqlDataSources.xml +.idea/**/dynamic.xml +.idea/**/uiDesigner.xml +.idea/**/dbnavigator.xml + +# Gradle +.idea/**/gradle.xml +.idea/**/libraries + +# Gradle and Maven with auto-import +# When using Gradle or Maven with auto-import, you should exclude module files, +# since they will be recreated, and may cause churn. Uncomment if using +# auto-import. +# .idea/artifacts +# .idea/compiler.xml +# .idea/jarRepositories.xml +# .idea/modules.xml +# .idea/*.iml +# .idea/modules +# *.iml +# *.ipr + +# CMake +cmake-build-*/ + +# Mongo Explorer plugin +.idea/**/mongoSettings.xml + +# File-based project format +*.iws + +# IntelliJ +out/ + +# mpeltonen/sbt-idea plugin +.idea_modules/ + +# JIRA plugin +atlassian-ide-plugin.xml + +# Cursive Clojure plugin +.idea/replstate.xml + +# SonarLint plugin +.idea/sonarlint/ + +# Crashlytics plugin (for Android Studio and IntelliJ) +com_crashlytics_export_strings.xml +crashlytics.properties +crashlytics-build.properties +fabric.properties + +# Editor-based Rest Client +.idea/httpRequests + +# Android studio 3.1+ serialized cache file +.idea/caches/build_file_checksums.ser + +### JetBrains+all Patch ### +# Ignore everything but code style settings and run configurations +# that are supposed to be shared within teams. + +.idea/* + +!.idea/codeStyles +!.idea/runConfigurations + +### Linux ### +*~ + +# temporary files which can be created if a process still has a handle open of a deleted file +.fuse_hidden* + +# KDE directory preferences +.directory + +# Linux trash folder which might appear on any partition or disk +.Trash-* + +# .nfs files are created when an open file is removed but is still being accessed +.nfs* + +### OSX ### +# General +.DS_Store +.AppleDouble +.LSOverride + +# Icon must end with two \r +Icon + +# Thumbnails +._* + +# Files that might appear in the root of a volume +.DocumentRevisions-V100 +.fseventsd +.Spotlight-V100 +.TemporaryItems +.Trashes +.VolumeIcon.icns +.com.apple.timemachine.donotpresent + +# Directories potentially created on remote AFP share +.AppleDB +.AppleDesktop +Network Trash Folder +Temporary Items +.apdisk + +### SublimeText ### +# Cache files for Sublime Text +*.tmlanguage.cache +*.tmPreferences.cache +*.stTheme.cache + +# Workspace files are user-specific +*.sublime-workspace + +# Project files should be checked into the repository, unless a significant +# proportion of contributors will probably not be using Sublime Text +# *.sublime-project + +# SFTP configuration file +sftp-config.json +sftp-config-alt*.json + +# Package control specific files +Package Control.last-run +Package Control.ca-list +Package Control.ca-bundle +Package Control.system-ca-bundle +Package Control.cache/ +Package Control.ca-certs/ +Package Control.merged-ca-bundle +Package Control.user-ca-bundle +oscrypto-ca-bundle.crt +bh_unicode_properties.cache + +# Sublime-github package stores a github token in this file +# https://packagecontrol.io/packages/sublime-github +GitHub.sublime-settings + +### Vim ### +# Swap +[._]*.s[a-v][a-z] +!*.svg # comment out if you don't need vector files +[._]*.sw[a-p] +[._]s[a-rt-v][a-z] +[._]ss[a-gi-z] +[._]sw[a-p] + +# Session +Session.vim +Sessionx.vim + +# Temporary +.netrwhist +# Auto-generated tag files +tags +# Persistent undo +[._]*.un~ + +### VisualStudioCode ### +.vscode/* +!.vscode/settings.json +!.vscode/tasks.json +!.vscode/launch.json +!.vscode/extensions.json +!.vscode/*.code-snippets + +# Local History for Visual Studio Code +.history/ + +# Built Visual Studio Code Extensions +*.vsix + +### VisualStudioCode Patch ### +# Ignore all local history of files +.history +.ionide + +# Support for Project snippet scope +.vscode/*.code-snippets + +# Ignore code-workspaces +*.code-workspace + +### Windows ### +# Windows thumbnail cache files +Thumbs.db +Thumbs.db:encryptable +ehthumbs.db +ehthumbs_vista.db + +# Dump file +*.stackdump + +# Folder config file +[Dd]esktop.ini + +# Recycle Bin used on file shares +$RECYCLE.BIN/ + +# Windows Installer files +*.cab +*.msi +*.msix +*.msm +*.msp + +# Windows shortcuts +*.lnk + +# End of https://www.toptal.com/developers/gitignore/api/sublimetext,vim,visualstudiocode,jetbrains+all,linux,osx,windows diff --git a/README.md b/README.md index 646648d..c071fca 100644 --- a/README.md +++ b/README.md @@ -1,36 +1,31 @@ -# 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) +# action-rails_best_practices -![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) +[![test](https://github.com/blooper05/action-rails_best_practices/workflows/test/badge.svg)](https://github.com/blooper05/action-rails_best_practices/actions?query=workflow%3Atest) +[![reviewdog](https://github.com/blooper05/action-rails_best_practices/workflows/reviewdog/badge.svg)](https://github.com/blooper05/action-rails_best_practices/actions?query=workflow%3Areviewdog) +[![depup](https://github.com/blooper05/action-rails_best_practices/workflows/depup/badge.svg)](https://github.com/blooper05/action-rails_best_practices/actions?query=workflow%3Adepup) +[![release](https://github.com/blooper05/action-rails_best_practices/workflows/release/badge.svg)](https://github.com/blooper05/action-rails_best_practices/actions?query=workflow%3Arelease) +[![GitHub release (latest SemVer)](https://img.shields.io/github/v/release/blooper05/action-rails_best_practices?logo=github&sort=semver)](https://github.com/blooper05/action-rails_best_practices/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) -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:! +![github-pr-review demo](https://user-images.githubusercontent.com/5299525/171834705-b2517107-e616-4289-8ed9-4e160164701c.png) +![github-pr-check demo](https://user-images.githubusercontent.com/5299525/171834709-130da062-3518-4b28-9a1c-24b58fe686b4.png) -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 action runs [rails_best_practices] with [reviewdog] on pull requests to improve +code review experience. -This repo contains a sample action to run [misspell](https://github.com/client9/misspell). +[rails_best_practices]:https://github.com/flyerhzm/rails_best_practices +[reviewdog]:https://github.com/reviewdog/reviewdog ## Input - ```yaml inputs: github_token: description: 'GITHUB_TOKEN' default: '${{ github.token }}' + tool_name: + description: 'Tool name to use for reviewdog reporter' + default: 'rails_best_practices' workdir: description: 'Working directory relative to the root directory.' default: '.' @@ -54,26 +49,24 @@ inputs: reviewdog_flags: description: 'Additional reviewdog flags' default: '' - ### Flags for ### - locale: - description: '-locale flag of misspell. (US/UK)' + ### Flags for rails_best_practices ### + rails_best_practices_flags: + description: 'rails_best_practices flags (rails_best_practices --without-color --silent . )' default: '' ``` ## Usage - ```yaml name: reviewdog on: [pull_request] jobs: - # TODO: change `linter_name`. - linter_name: - name: runner / + rails_best_practices: + name: runner / rails_best_practices runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - - uses: reviewdog/action-composite-template@v1 + - uses: blooper05/action-rails_best_practices@v1 with: github_token: ${{ secrets.github_token }} # Change reviewdog reporter if you need [github-check,github-pr-review,github-pr-check]. @@ -98,16 +91,20 @@ 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. +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-hadolint](https://github.com/reviewdog/action-hadolint) +- [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 diff --git a/action.yml b/action.yml index 112cb6d..c440939 100644 --- a/action.yml +++ b/action.yml @@ -1,10 +1,13 @@ -name: 'TODO: Run with reviewdog' -description: 'TODO: 🐶 Run with reviewdog on pull requests to improve code review experience.' -author: 'TODO: ' +name: 'Run rails_best_practices with reviewdog' +description: '🐶 Run rails_best_practices with reviewdog on pull requests to improve code review experience.' +author: 'blooper05' inputs: github_token: description: 'GITHUB_TOKEN' default: '${{ github.token }}' + tool_name: + description: 'Tool name to use for reviewdog reporter' + default: 'rails_best_practices' workdir: description: 'Working directory relative to the root directory.' default: '.' @@ -13,7 +16,7 @@ inputs: description: 'Report level for reviewdog [info,warning,error]' default: 'error' reporter: - description: 'Reporter of reviewdog command [github-check,github-pr-review].' + description: 'Reporter of reviewdog command [github-check,github-pr-review,github-pr-check].' default: 'github-check' filter_mode: description: | @@ -28,9 +31,9 @@ inputs: reviewdog_flags: description: 'Additional reviewdog flags' default: '' - ### Flags for ### - locale: - description: '-locale flag of misspell. (US/UK)' + ### Flags for rails_best_practices ### + rails_best_practices_flags: + description: 'rails_best_practices flags (rails_best_practices --without-color --silent . )' default: '' runs: using: 'composite' @@ -38,23 +41,25 @@ runs: - uses: reviewdog/action-setup@v1 with: reviewdog_version: v0.14.1 + - uses: ruby/setup-ruby@v1 + with: + ruby-version: 3.1 - 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_TOOL_NAME: ${{ inputs.tool_name }} + INPUT_WORKDIR: ${{ inputs.workdir }} 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_ESLINT_FLAGS: ${{ inputs.eslint_flags }} - INPUT_WORKDIR: ${{ inputs.workdir }} - INPUT_TOOL_NAME: ${{ inputs.tool_name }} + INPUT_RAILS_BEST_PRACTICES_FLAGS: ${{ inputs.rails_best_practices_flags }} # Ref: https://haya14busa.github.io/github-action-brandings/ -# TODO: update branding if you want. branding: - icon: 'check' - color: 'blue' + icon: 'check-circle' + color: 'red' diff --git a/script.sh b/script.sh index 37e663f..fa06b11 100755 --- a/script.sh +++ b/script.sh @@ -7,17 +7,15 @@ 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 '::group::🐶 Installing rails_best_practices ... https://github.com/flyerhzm/rails_best_practices' +gem install --no-document rails_best_practices echo '::endgroup::' -echo '::group:: Running misspell with reviewdog 🐶 ...' +echo '::group:: Running rails_best_practices with reviewdog 🐶 ...' # shellcheck disable=SC2086 -misspell -locale="${INPUT_LOCALE}" . | - reviewdog -efm="%f:%l:%c: %m" \ - -name="linter-name (misspell)" \ +rails_best_practices --without-color --silent . ${INPUT_RAILS_BEST_PRACTICES_FLAGS} | + reviewdog -efm="%f:%l - %m" -efm="%-G%.%#" \ + -name="${INPUT_TOOL_NAME}" \ -reporter="${INPUT_REPORTER}" \ -filter-mode="${INPUT_FILTER_MODE}" \ -fail-on-error="${INPUT_FAIL_ON_ERROR}" \ diff --git a/testdata/app/models/user.rb b/testdata/app/models/user.rb new file mode 100644 index 0000000..c9c1049 --- /dev/null +++ b/testdata/app/models/user.rb @@ -0,0 +1,5 @@ +# refs. https://github.com/flyerhzm/rails_best_practices/blob/HEAD/spec/rails_best_practices/reviews/default_scope_is_evil_review_spec.rb#L12-L14 +# refs. https://github.com/flyerhzm/rails_best_practices/blob/HEAD/spec/rails_best_practices/reviews/protect_mass_assignment_review_spec.rb#L17-L18 +class User < ActiveRecord::Base + default_scope -> { order('created_at desc') } +end diff --git a/testdata/subdir/text.md b/testdata/subdir/text.md deleted file mode 100644 index 5b33346..0000000 --- a/testdata/subdir/text.md +++ /dev/null @@ -1,2 +0,0 @@ -Determinisitic result is important! - diff --git a/testdata/text.md b/testdata/text.md deleted file mode 100644 index 5025db8..0000000 --- a/testdata/text.md +++ /dev/null @@ -1,5 +0,0 @@ -Determinisitic result is important. - -colour # <= Check -locale - -langauge