Skip to content

Commit

Permalink
Add code
Browse files Browse the repository at this point in the history
Signed-off-by: Hollow Man <hollowman@opensuse.org>
  • Loading branch information
HollowMan6 committed Apr 17, 2023
1 parent a56a83c commit b0c0eb7
Show file tree
Hide file tree
Showing 9 changed files with 145 additions and 117 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/dockerimage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,6 @@ jobs:
steps:
- uses: actions/checkout@v3
- name: Build the Docker image
run: docker build . --file Dockerfile --tag ${{ github.repository }}:$(date +%s)
run: |
NAME=$(echo "${{ github.repository }}" | tr '[:upper:]' '[:lower:]')
docker build . --file Dockerfile --tag ${NAME}:$(date +%s)
46 changes: 0 additions & 46 deletions .github/workflows/test.yml

This file was deleted.

10 changes: 5 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ ENV REVIEWDOG_VERSION=v0.14.1

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/
ENV PYTHONUNBUFFERED=1
RUN apk add --update --no-cache python3 && ln -sf python3 /usr/bin/python

Check warning on line 10 in Dockerfile

View workflow job for this annotation

GitHub Actions / runner / hadolint

[hadolint] reported by reviewdog 🐶 Pin versions in apk add. Instead of `apk add <package>` use `apk add <package>=<version>` Raw Output: message:"Pin versions in apk add. Instead of `apk add <package>` use `apk add <package>=<version>`" location:{path:"Dockerfile" range:{start:{line:10 column:1}}} severity:WARNING source:{name:"hadolint" url:"https://github.com/hadolint/hadolint"} code:{value:"DL3018" url:"https://github.com/hadolint/hadolint/wiki/DL3018"}
RUN python3 -m ensurepip
RUN pip3 install --no-cache --upgrade pip setuptools

Check warning on line 12 in Dockerfile

View workflow job for this annotation

GitHub Actions / runner / hadolint

[hadolint] reported by reviewdog 🐶 Pin versions in pip. Instead of `pip install <package>` use `pip install <package>==<version>` or `pip install --requirement <requirements file>` Raw Output: message:"Pin versions in pip. Instead of `pip install <package>` use `pip install <package>==<version>` or `pip install --requirement <requirements file>`" location:{path:"Dockerfile" range:{start:{line:12 column:1}}} severity:WARNING source:{name:"hadolint" url:"https://github.com/hadolint/hadolint"} code:{value:"DL3013" url:"https://github.com/hadolint/hadolint/wiki/DL3013"}

Check warning on line 12 in Dockerfile

View workflow job for this annotation

GitHub Actions / runner / hadolint

[hadolint] reported by reviewdog 🐶 Avoid use of cache directory with pip. Use `pip install --no-cache-dir <package>` Raw Output: message:"Avoid use of cache directory with pip. Use `pip install --no-cache-dir <package>`" location:{path:"Dockerfile" range:{start:{line:12 column:1}}} severity:WARNING source:{name:"hadolint" url:"https://github.com/hadolint/hadolint"} code:{value:"DL3042" url:"https://github.com/hadolint/hadolint/wiki/DL3042"}

Check warning on line 12 in Dockerfile

View workflow job for this annotation

GitHub Actions / runner / hadolint

[hadolint] reported by reviewdog 🐶 Multiple consecutive `RUN` instructions. Consider consolidation. Raw Output: message:"Multiple consecutive `RUN` instructions. Consider consolidation." location:{path:"Dockerfile" range:{start:{line:12 column:1}}} severity:INFO source:{name:"hadolint" url:"https://github.com/hadolint/hadolint"} code:{value:"DL3059" url:"https://github.com/hadolint/hadolint/wiki/DL3059"}

COPY entrypoint.sh /entrypoint.sh
COPY convert.py /convert.py

ENTRYPOINT ["/entrypoint.sh"]
63 changes: 24 additions & 39 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,44 +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)
# SARIF for Reviewdog
[![Test](https://github.com/HollowMan6/sarif4reviewdog/workflows/Test/badge.svg)](https://github.com/HollowMan6/sarif4reviewdog/actions?query=workflow%3ATest)
[![reviewdog](https://github.com/HollowMan6/sarif4reviewdog/workflows/reviewdog/badge.svg)](https://github.com/HollowMan6/sarif4reviewdog/actions?query=workflow%3Areviewdog)
[![depup](https://github.com/HollowMan6/sarif4reviewdog/workflows/depup/badge.svg)](https://github.com/HollowMan6/sarif4reviewdog/actions?query=workflow%3Adepup)
[![release](https://github.com/HollowMan6/sarif4reviewdog/workflows/release/badge.svg)](https://github.com/HollowMan6/sarif4reviewdog/actions?query=workflow%3Arelease)
[![GitHub release (latest SemVer)](https://img.shields.io/github/v/release/HollowMan6/sarif4reviewdog?logo=github&sort=semver)](https://github.com/HollowMan6/sarif4reviewdog/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

<!-- 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 ###
tool_name:
description: 'Tool name to use for reviewdog reporter'
default: 'SARIF'
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'
description: 'Reporter of reviewdog command [github-pr-check,github-pr-review].'
default: 'github-pr-review'
filter_mode:
description: |
Filtering mode for the reviewdog command [added,diff_context,file,nofilter].
Expand All @@ -52,27 +35,31 @@ inputs:
reviewdog_flags:
description: 'Additional reviewdog flags'
default: ''
### Flags for <linter-name> ###
locale:
description: '-locale flag of misspell. (US/UK)'
### Flags for linter ###
file:
description: 'SARIF file path'
default: ''
required: true
```

## Usage
<!-- TODO: update. replace `template` with the linter name -->

```yaml
name: reviewdog
name: sarif4reviewdog
on: [pull_request]
jobs:
# TODO: change `linter_name`.
linter_name:
name: runner / <linter-name>
sarif_reviewdog:
name: sarif reviewdog
runs-on: ubuntu-latest
permissions:
pull-requests: write
steps:
- uses: actions/checkout@v2
- uses: reviewdog/action-template@v1
- uses: HollowMan6/sarif4reviewdog@v1
with:
file: 'results.sarif'
# Remember to allow GitHub Actions to create and approve pull requests
# https://docs.github.com/en/repositories/managing-your-repositorys-settings-and-features/enabling-features-for-your-repository/managing-github-actions-settings-for-a-repository#preventing-github-actions-from-creating-or-approving-pull-requests
github_token: ${{ secrets.github_token }}
# Change reviewdog reporter if you need [github-pr-check,github-check,github-pr-review].
reporter: github-pr-review
Expand Down Expand Up @@ -110,5 +97,3 @@ Supported linters:
### 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)
21 changes: 11 additions & 10 deletions action.yml
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
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: 'SARIF support for reviewdog 🐶'
description: 'Support SARIF for reviewdog on pull requests to improve code review experience.'
author: 'HollowMan6'
inputs:
github_token:
description: 'GITHUB_TOKEN'
default: '${{ github.token }}'
workdir:
description: 'Working directory relative to the root directory.'
default: '.'
### Flags for reviewdog ###
tool_name:
description: 'Tool name to use for reviewdog reporter'
default: 'SARIF'
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'
default: 'github-pr-review'
filter_mode:
description: |
Filtering mode for the reviewdog command [added,diff_context,file,nofilter].
Expand All @@ -28,10 +28,11 @@ inputs:
reviewdog_flags:
description: 'Additional reviewdog flags'
default: ''
### Flags for <linter-name> ###
locale:
description: '-locale flag of misspell. (US/UK)'
### Flags for linter ###
file:
description: 'SARIF file path'
default: ''
required: true
runs:
using: 'docker'
image: 'Dockerfile'
Expand Down
98 changes: 98 additions & 0 deletions convert.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
#!/usr/bin/env python3
import sys
import json

content = {}
with open(sys.argv[1]) as file:
content = json.load(file)

for run in content["runs"]:
rdjson = {}
tool = run["tool"]
driver = tool["driver"]
name = driver["name"]
informationUri = driver["informationUri"]
rule = {}
ruleLevel = {}
rdjson["source"] = {
"name": name,
"url": informationUri
}
diagnostics = []
for r in driver["rules"]:
id = r["id"]
description = "\n#### " + id + " "
level = r["defaultConfiguration"]["level"]
if level == "warning":
level = "WARNING"
elif level == "error":
level = "ERROR"
elif level == "note":
level = "INFO"
else:
level = "UNKNOWN_SEVERITY"
if "shortDescription" in r:
description += r["shortDescription"]["text"] + ":\n"
if "fullDescription" in r:
description += r["fullDescription"]["text"] + "\n\n"
if "help" in r:
description += "*" + r["help"]["text"] + "*\n"
rule[id] = description
ruleLevel[id] = level
for result in run["results"]:
ruleId = result["ruleId"]
description = rule[ruleId]
# if "message" in result:
# description += result["message"]["text"] + "\n"
sarifLocation = result["locations"][0]["physicalLocation"]
path = sarifLocation["artifactLocation"]["uri"]
location = {
"path": path,
"range": {
"start": {
"line": sarifLocation["region"]["startLine"],
"column": sarifLocation["region"]["startColumn"]
}
}
}
if "endLine" in sarifLocation["region"]:
location["range"]["end"] = {
"line": sarifLocation["region"]["endLine"],
"column": sarifLocation["region"]["endColumn"]
}
suggestions = []
if "fixes" in result:
for fix in result["fixes"]:
ac = fix["artifactChanges"][0]
if path != ac["artifactLocation"]["uri"]:
continue
replace = ac["replacements"][0]
deleted = replace["deletedRegion"]
suggest = {
"range": {
"start": {
"line": deleted["startLine"],
"column": deleted["startColumn"]
},
"end": {
"line": deleted["endLine"],
"column": deleted["endColumn"]
}
}
}
location["range"] = suggest
if "insertedContent" in replace:
suggest["text"] = replace["insertedContent"]["text"]
suggestions.append(suggest)
diagnostic = {
"message": description,
"location": location,
"severity": ruleLevel[ruleId],
"code": {
"value": ruleId,
},
"suggestions": suggestions,
}
diagnostics.append(diagnostic)
rdjson["diagnostics"] = diagnostics
print(json.dumps(rdjson))
13 changes: 4 additions & 9 deletions entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
#!/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}" \
/convert.py "${INPUT_FILE}" \
| reviewdog -f="rdjson" \
-name="${INPUT_TOOL_NAME:-SARIF}" \
-reporter="${INPUT_REPORTER:-github-pr-review}" \
-filter-mode="${INPUT_FILTER_MODE}" \
-fail-on-error="${INPUT_FAIL_ON_ERROR}" \
-level="${INPUT_LEVEL}" \
Expand Down
2 changes: 0 additions & 2 deletions testdata/subdir/text.md

This file was deleted.

5 changes: 0 additions & 5 deletions testdata/text.md

This file was deleted.

0 comments on commit b0c0eb7

Please sign in to comment.