Skip to content

Commit

Permalink
Merge pull request #1 from reviewdog/init
Browse files Browse the repository at this point in the history
Implement action-staticcheck
  • Loading branch information
haya14busa authored May 10, 2020
2 parents 1346899 + 40cb22d commit f7b2de4
Show file tree
Hide file tree
Showing 10 changed files with 79 additions and 72 deletions.
24 changes: 5 additions & 19 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:
pull_request:
jobs:
test-check:
name: runner / <linter-name> (github-check)
name: runner / staticcheck (github-check)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
Expand All @@ -15,25 +15,11 @@ jobs:
github_token: ${{ secrets.github_token }}
reporter: github-check
level: info
locale: "US"

test-pr-check:
if: github.event_name == 'pull_request'
name: runner / <linter-name> (github-pr-check)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: ./
with:
github_token: ${{ secrets.github_token }}
reporter: github-pr-check
level: warning
locale: "US"
workdir: ./testdata/subdir/
target: ./testdata/

test-pr-review:
if: github.event_name == 'pull_request'
name: runner / <linter-name> (github-pr-review)
name: runner / staticcheck (github-pr-review)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
Expand All @@ -42,5 +28,5 @@ jobs:
github_token: ${{ secrets.github_token }}
reporter: github-pr-review
level: error
locale: "US"
reviewdog_flags: -filter-mode=file -fail-on-error
workdir: ./testdata
reviewdog_flags: -filter-mode=file
10 changes: 6 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
FROM alpine:3.11
FROM golang:1.14-alpine

ENV REVIEWDOG_VERSION=v0.10.0
ENV TMPL_VERSION=v1.2.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}
RUN wget -O - -q https://raw.githubusercontent.com/reviewdog/reviewdog/master/install.sh| sh -s -- -b /usr/local/bin/ ${REVIEWDOG_VERSION} && \
wget -O - -q https://raw.githubusercontent.com/haya14busa/tmpl/master/install.sh| sh -s -- -b /usr/local/bin/ ${TMPL_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/
RUN go get honnef.co/go/tools/cmd/staticcheck

COPY entrypoint.sh /entrypoint.sh
COPY json.tmpl /json.tmpl

ENTRYPOINT ["/entrypoint.sh"]
50 changes: 22 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,34 +1,27 @@
# action-template

<!-- TODO: replace reviewdog/action-template with your repo name -->
[![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)
# action-staticcheck

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:!
[![Test](https://github.com/reviewdog/action-staticcheck/workflows/Test/badge.svg)](https://github.com/reviewdog/action-staticcheck/actions?query=workflow%3ATest)
[![reviewdog](https://github.com/reviewdog/action-staticcheck/workflows/reviewdog/badge.svg)](https://github.com/reviewdog/action-staticcheck/actions?query=workflow%3Areviewdog)
[![depup](https://github.com/reviewdog/action-staticcheck/workflows/depup/badge.svg)](https://github.com/reviewdog/action-staticcheck/actions?query=workflow%3Adepup)
[![release](https://github.com/reviewdog/action-staticcheck/workflows/release/badge.svg)](https://github.com/reviewdog/action-staticcheck/actions?query=workflow%3Arelease)
[![GitHub release (latest SemVer)](https://img.shields.io/github/v/release/reviewdog/action-staticcheck?logo=github&sort=semver)](https://github.com/reviewdog/action-staticcheck/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)

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 [staticcheck](https://staticcheck.io/) with reviewdog on pull requests to improve code review experience.

This repo contains a sample action to run [misspell](https://github.com/client9/misspell).
[![github-pr-review demo](https://user-images.githubusercontent.com/3797062/81496355-1a58f580-92f2-11ea-809b-7e61f863c147.png)](https://github.com/reviewdog/action-staticcheck/pull/1#discussion_r422620536)
<sub>Link to the staticcheck check rule is available as well. e.g. [SA9004](https://staticcheck.io/docs/checks#SA9004)</sub>

## Input

<!-- TODO: update -->
```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]'
Expand All @@ -49,26 +42,27 @@ inputs:
reviewdog_flags:
description: 'Additional reviewdog flags'
default: ''
### Flags for <linter-name> ###
locale:
description: '-locale flag of misspell. (US/UK)'
### Flags for staticcheck ###
target:
description: 'Target of staticcheck'
default: './...'
staticcheck_flags:
description: 'staticcheck flags'
default: ''
```
## Usage
<!-- TODO: update. replace `template` with the linter name -->
```yaml
name: reviewdog
on: [pull_request]
jobs:
# TODO: change `linter_name`.
linter_name:
name: runner / <linter-name>
staticcheck:
name: runner / staticcheck
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: reviewdog/action-template@v1
- uses: reviewdog/action-staticcheck@v1
with:
github_token: ${{ secrets.github_token }}
# Change reviewdog reporter if you need [github-pr-check,github-check,github-pr-review].
Expand Down
20 changes: 11 additions & 9 deletions action.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: 'TODO: Run <linter-name> with reviewdog'
description: 'TODO: 🐶 Run <linter-name> with reviewdog on pull requests to improve code review experience.'
author: 'TODO: <your-name>'
name: 'Run staticcheck with reviewdog'
description: '🐶 Run staticcheck with reviewdog on pull requests to improve code review experience.'
author: 'haya14busa'
inputs:
github_token:
description: 'GITHUB_TOKEN'
Expand All @@ -13,8 +13,8 @@ inputs:
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'
description: 'Reporter of reviewdog command [github-check,github-pr-review].'
default: 'github-pr-review'
filter_mode:
description: |
Filtering for the reviewdog command [added,diff_context,file,nofilter].
Expand All @@ -28,16 +28,18 @@ inputs:
reviewdog_flags:
description: 'Additional reviewdog flags'
default: ''
### Flags for <linter-name> ###
locale:
description: '-locale flag of misspell. (US/UK)'
### Flags for staticcheck ###
target:
description: 'Target of staticcheck'
default: './...'
staticcheck_flags:
description: 'staticcheck flags'
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'
12 changes: 7 additions & 5 deletions entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
#!/bin/sh
set -e

if [ -n "${GITHUB_WORKSPACE}" ] && [ -n "${INPUT_WORKDIR}" ]; then
if [ -n "${GITHUB_WORKSPACE}" ]; then
cd "${GITHUB_WORKSPACE}/${INPUT_WORKDIR}" || exit
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}" \
staticcheck ${INPUT_STATICCHECK_FLAGS} -f=json ${INPUT_TARGET:-.} \
| tmpl -f=jsonl /json.tmpl \
| reviewdog \
-efm="%f:%l:%c: %m" \
-name="staticcheck" \
-reporter="${INPUT_REPORTER:-github-pr-review}" \
-filter-mode="${INPUT_FILTER_MODE}" \
-fail-on-error="${INPUT_FAIL_ON_ERROR}" \
-level="${INPUT_LEVEL}" \
Expand Down
6 changes: 6 additions & 0 deletions json.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{{ range $_, $jl := . -}}
{{ $jl.location.file }}:{{ $jl.location.line }}:{{ $jl.location.column }}:{{ sp -}}
{{ $jl.message }}{{ sp -}}
[{{ $jl.code }}](https://staticcheck.io/docs/checks#{{ $jl.code }})
{{- nl -}}
{{- end -}}
3 changes: 3 additions & 0 deletions testdata/result.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{"code":"U1000","severity":"error","location":{"file":"/home/haya14busa/src/github.com/reviewdog/action-staticcheck/testdata/testdata.go","line":8,"column":6},"end":{"file":"","line":0,"column":0},"message":"func unused is unused"}
{"code":"SA9003","severity":"error","location":{"file":"/home/haya14busa/src/github.com/reviewdog/action-staticcheck/testdata/testdata.go","line":11,"column":2},"end":{"file":"/home/haya14busa/src/github.com/reviewdog/action-staticcheck/testdata/testdata.go","line":11,"column":43},"message":"empty branch"}
{"code":"SA4000","severity":"error","location":{"file":"/home/haya14busa/src/github.com/reviewdog/action-staticcheck/testdata/testdata.go","line":11,"column":5},"end":{"file":"/home/haya14busa/src/github.com/reviewdog/action-staticcheck/testdata/testdata.go","line":11,"column":43},"message":"identical expressions on the left and right side of the '==' operator"}
2 changes: 0 additions & 2 deletions testdata/subdir/text.md

This file was deleted.

19 changes: 19 additions & 0 deletions testdata/testdata.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package testdata

import (
"errors"
"regexp"
)

const (
First byte = 1
Second = 2
)

func unused() {
regexp.Compile(".+")

if errors.New("abc") == errors.New("abc") {
// test SA4000
}
}
5 changes: 0 additions & 5 deletions testdata/text.md

This file was deleted.

0 comments on commit f7b2de4

Please sign in to comment.