Giter Club home page Giter Club logo

pr-lint-action's Introduction

Pull Request Lint

It is a linter of pull requests for GitHub Actions.

Why?

To enforce pull request titles in the same format will be useful like generating standard changelog messages. Besides it can be used to parse titles and link with issue tracking systems such as JIRA.

Example:

name: PR lint

on:
  pull_request:
    types: ['opened', 'edited', 'reopened', 'synchronize']

jobs:
  pr-lint:
    runs-on: ubuntu-latest
    steps:
    - uses: seferov/pr-lint-action@master
      with:
        title-regex: '^\[PROJECT-\d*\](\ )'
        title-regex-flags: 'g' # optional
        error-message: 'Add Jira ID to your title' # optional

In this example, for every pull request the title is expected to match ^\[PROJECT-\d*\]\ regex with a global flag g. For instance, [PROJECT-123] lorem ipsum or [PROJECT-2345] dolor sit amet are valid titles for this example. You can customize the title regex for your needs. The regex flags configuration is optional.

Auto-close

It can be configured to close pull request automatically if the title does not match the pattern provided. To do so, github-token and auto-close-message options must be configured. In the message, %pattern% is replaced with the actual the pattern provided. Here is an example pull request.

Config:

name: PR lint

on:
  pull_request:
    types: ['opened', 'edited', 'reopened', 'synchronize']

jobs:
  pr-lint:
    runs-on: ubuntu-latest
    steps:
    - uses: seferov/pr-lint-action@master
      with:
        title-regex: '^\[PROJECT-\d*\](\ )'
+       github-token: ${{ secrets.GITHUB_TOKEN }}
+       auto-close-message: 'Closing this pull request since the title does not match %pattern% pattern. Please fix the title and re-open the pull request.'

pr-lint-action's People

Contributors

alexesprit avatar atn34 avatar dependabot-preview[bot] avatar dependabot[bot] avatar fabianlee1211 avatar mnthomson avatar seferov avatar vladimirf7 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

pr-lint-action's Issues

Optional inputs are not defined

Using the optional inputs results in a warning:

Warning: Unexpected input(s) 'title-regex-flags', 'error-message', valid inputs are ['entryPoint', 'args', 'title-regex']

I assume this is because they are not present in the actions.yml file but I am inexperienced with writing github actions.

[Potential bug] Once PR title is modified kicking the tests again gets the old PR name

I'm not entirely sure if this is expected behaviour, but I tested the action with a PR that does not match the regex I had put and I get a fail (that is expected)

After editing the name of the PR in github and re runing the checks it looks like the action pulls the unmodified title (which was Add pr lint action but has been changed to Feature: Add pr lint action

title: Add pr lint action
##[error]Please fix your PR title to match ^Feature:|Fix:|Refactor:
##[error]Docker run failed with exit code 1

Use JavaScript action to speed up the execution

I noticed that the execution time of your action takes around 25 seconds which seems quite a lot for such a simple thing.
In the logs, I found that only the container build process takes 22 seconds. When the actual action execution takes less than a second. See screenshot below.

image

By using JavaScript action instead of Docker container action you can get rid of those 22 seconds of the build time and speed up your action significantly.

In order to do that you just need to keep one compiled execution file with all the dependencies in your repo. And such a tool like ncc can easily help you with that.

And that's important as my application container build takes almost the same time. I don't talk about the linter which pulls the code, installs all the dependencies, and lints all the code for twice less time than I lint my PR name.

image

required property 'timeout-minutes'

Some issues were found in GitHub workflow(s).
Please review the annotations and correct the issues.

.github/workflows/pr-lint.yml#L1
data/jobs/pr-lint should have required property 'timeout-minutes'
name: PR Title lint

on:
  pull_request:
    types: ['opened', 'edited', 'reopened', 'synchronize']

jobs:
  pr-lint:
    runs-on: ubuntu-latest
    steps:
      - uses: seferov/pr-lint-action@master
        with:
          title-regex: '^(build|ci|docs|feat|fix|perf|refactor|style|test):\sTICK-\d{1,4}\s.*'
          error-message: 'Please fix the PR title'

Unexpected input(s) 'error-message', valid inputs are ['entryPoint', 'args', 'title-regex']

Providing error-message as an input to this action causes an error/warning:

Unexpected input(s) 'error-message', valid inputs are ['entryPoint', 'args', 'title-regex']

Configuration:

  lint:
    runs-on: ubuntu-22.04
    env:
      PR_TITLE: ${{inputs.pr_title}}
    steps:
      - uses: seferov/pr-lint-action@master
        with:
          title-regex: '(^(IF|KLUE|KIS)-[0-9]+|^Hotfix-([0-9]+(\/[0-9]+)+))\s--\s[^\n\r]+$'
          error-message: 'Expected format:\n(IF|KLUE|KIS)-<Jira Ticket> || Hotfix-2022/03/09 -- short description'

Unrecognized named-value: 'secrets'. Located at position 1 within expression: secrets.GITHUB_TOKEN

For some reason (might totally be me) I cannot get this workflow to run, it fails in setup

I can use other workflows fine that do similar things, but this action is the one I'd prefer to use. I tried the manual approach and the GitHub workflow helper UI. Both failed in similar fashion.

I also tried to add the following configuration but it failed in the same way.

env:
  GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

References:

Since I'm deleting and testing on a throwaway repo, here's the exact configuration of my workflow for that given failure (with the env included, though the results are the same without)

# This is a basic workflow to help you get started with Actions

name: CI

# Controls when the action will run. Triggers the workflow on push or pull request
# events but only for the master branch
on:
  pull_request:
    types: ["opened", "edited", "reopened", "synchronize"]
  # push:
  #   branches: [ master ]
  # pull_request:
  #   branches: [ master ]

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
  # This workflow contains a single job called "build"
  build:
    # The type of runner that the job will run on
    runs-on: ubuntu-latest

    # Steps represent a sequence of tasks that will be executed as part of the job
    steps:
      # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
      - uses: actions/checkout@v2

      # Runs a single command using the runners shell
      - name: Run a one-line script
        run: echo Hello, world!

      # Runs a set of commands using the runners shell
      - name: Run a multi-line script
        run: |
          echo Add other actions to build,
          echo test, and deploy your project.

      # Runs a PR Linting Action
      - name: PR Lint GitHub Action
        uses: seferov/[email protected]
        with:
          # Title regex to match
          title-regex: ^\[PROJECT-\d{3,}\] \ # default is ^\[PROJECT-\d*\]\
          # ${{ secrets.GITHUB_TOKEN }}
          # github-token: # optional
          # If set, on a failing job automatically closes pull request and comments on it with the given value
          # auto-close-message: # optional
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

GitHub Action fails

Starting today the action is failing:

24s
Build container for action use: '/home/runner/work/_actions/seferov/pr-lint-action/master/Dockerfile'.
  /usr/bin/docker build -t 1e5c35:418297ee28f5419bb5c2beafaaf1d344 -f "/home/runner/work/_actions/seferov/pr-lint-action/master/Dockerfile" "/home/runner/work/_actions/seferov/pr-lint-action/master"
  Sending build context to Docker daemon  57.34kB
  
  Step 1/5 : FROM node:slim
  slim: Pulling from library/node
  babf97a3f00a: Pulling fs layer
  d81eb1809d95: Pulling fs layer
  54b0718e1fd5: Pulling fs layer
  9f80bf52a6c0: Pulling fs layer
  28724063fd29: Pulling fs layer
  9f80bf52a6c0: Waiting
  28724063fd29: Waiting
  d81eb1809d95: Verifying Checksum
  d81eb1809d95: Download complete
  babf97a3f00a: Verifying Checksum
  babf97a3f00a: Download complete
  9f80bf52a6c0: Verifying Checksum
  9f80bf52a6c0: Download complete
  54b0718e1fd5: Verifying Checksum
  54b0718e1fd5: Download complete
  28724063fd29: Verifying Checksum
  28724063fd29: Download complete
  babf97a3f00a: Pull complete
  d81eb1809d95: Pull complete
  54b0718e1fd5: Pull complete
  9f80bf52a6c0: Pull complete
  28724063fd29: Pull complete
  Digest: sha256:a39f2854f7fc02c8636c11227ca2d6680bd46a2173168650928b69cc03dffb1c
  Status: Downloaded newer image for node:slim
   ---> 2870b8b46426
  Step 2/5 : COPY . .
   ---> f684f86b568f
  Step 3/5 : RUN npm install
   ---> Running in d2d05012eeca
  npm notice 
  npm notice New patch version of npm available! 7.0.2 -> 7.0.3
  npm notice Changelog: <https://github.com/npm/cli/releases/tag/v7.0.3>
  npm notice Run `npm install -g [email protected]` to update!
  npm notice 
  npm ERR! Maximum call stack size exceeded
  
  npm ERR! A complete log of this run can be found in:
  npm ERR!     /root/.npm/_logs/2020-10-22T20_48_13_751Z-debug.log
  The command '/bin/sh -c npm install' returned a non-zero code: 1
  
  Warning: Docker build failed with exit code 1, back off 7.108 seconds before retry.
  /usr/bin/docker build -t 1e5c35:418297ee28f5419bb5c2beafaaf1d344 -f "/home/runner/work/_actions/seferov/pr-lint-action/master/Dockerfile" "/home/runner/work/_actions/seferov/pr-lint-action/master"
  Sending build context to Docker daemon  57.34kB
  
  Step 1/5 : FROM node:slim
   ---> 2870b8b46426
  Step 2/5 : COPY . .
   ---> Using cache
   ---> f684f86b568f
  Step 3/5 : RUN npm install
   ---> Running in 53b5b5c6cf1a
  npm notice 
  npm notice New patch version of npm available! 7.0.2 -> 7.0.3
  npm notice Changelog: <https://github.com/npm/cli/releases/tag/v7.0.3>
  npm notice Run `npm install -g [email protected]` to update!
  npm notice 
  npm ERR! Maximum call stack size exceeded
  
  npm ERR! A complete log of this run can be found in:
  npm ERR!     /root/.npm/_logs/2020-10-22T20_48_22_075Z-debug.log
  The command '/bin/sh -c npm install' returned a non-zero code: 1
  
  Warning: Docker build failed with exit code 1, back off 5.19 seconds before retry.
  /usr/bin/docker build -t 1e5c35:418297ee28f5419bb5c2beafaaf1d344 -f "/home/runner/work/_actions/seferov/pr-lint-action/master/Dockerfile" "/home/runner/work/_actions/seferov/pr-lint-action/master"
  Sending build context to Docker daemon  57.34kB
  
  Step 1/5 : FROM node:slim
   ---> 2870b8b46426
  Step 2/5 : COPY . .
   ---> Using cache
   ---> f684f86b568f
  Step 3/5 : RUN npm install
   ---> Running in a6025a12c4aa
  npm notice 
  npm notice New patch version of npm available! 7.0.2 -> 7.0.3
  npm notice Changelog: <https://github.com/npm/cli/releases/tag/v7.0.3>
  npm notice Run `npm install -g [email protected]` to update!
  npm notice 
  npm ERR! Maximum call stack size exceeded
  
  npm ERR! A complete log of this run can be found in:
  npm ERR!     /root/.npm/_logs/2020-10-22T20_48_28_537Z-debug.log
  The command '/bin/sh -c npm install' returned a non-zero code: 1
  
Error: Docker build failed with exit code 1

Not sure if that is code related though.

Verbose output log

After using this Github action the following Log output (blue) is shown.
Is this normal?, if so how can I avoid showing all this verbose log.
Thank you.

Captura de Pantalla 2021-01-29 a la(s) 16 44 45

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.