-
Notifications
You must be signed in to change notification settings - Fork 0
104 lines (91 loc) · 3.4 KB
/
code-style-review.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# HMS Networks Solution Center
# Code Style Review Action for Maven-based Ewon ETK Projects
# Version: 1.0
#
# This action is configured to automatically run when a push
# is made or pull request is merged to the `main` or `master`
# branch.
name: Code Style Review
on:
pull_request:
branches:
- main
jobs:
checkstyle:
permissions:
checks: write
contents: read
pull-requests: write
runs-on: ubuntu-latest
steps:
- name: Checkout project
uses: actions/checkout@v3
- name: Set Up JDK
uses: actions/setup-java@v3
with:
distribution: 'corretto'
java-version: 16
- name: Cache local Maven repository
uses: actions/cache@v3
with:
path: |
~/.m2/repository
target/buildJdk
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
restore-keys: |
${{ runner.os }}-maven-
- name: Resolve outdated Reviewdog comments
uses: actions/github-script@v6
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const pr_issue_number = context.issue.number;
const owner = context.repo.owner;
const repo = context.repo.repo;
const botName = "github-actions[bot]";
// List review comments on this issue/PR
const comments = await github.rest.pulls.listReviewComments({
owner,
repo,
issue_number: pr_issue_number,
});
// Filter comments from the bot
const botComments = comments.data.filter((comment) => comment.user.login === botName);
// Loop through bot comments and resolve them (if they are outdated)
for (const comment of botComments) {
const outdated = comment.outdated;
const comment_id = comment.id;
if (outdated) {
await github.rest.pulls.updateReviewComment({
owner,
repo,
comment_id,
body: "This comment is from an outdated version of the code style review. This comment has been resolved automatically.",
});
console.log(`Resolved outdated comment with id ${comment_id}`);
}
}
- name: Install Reviewdog
uses: reviewdog/action-setup@v1
with:
reviewdog_version: latest
- name: Run Checkstyle via Maven
run: mvn checkstyle:checkstyle -f pom.xml
continue-on-error: true
- name: Run Reviewdog
env:
REVIEWDOG_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Need PAT for private repositories
# Also need to check https://github.com/apps/reviewdog as may be able to simply allow access to all repositories
run: |
cat ./target/checkstyle-result.xml | reviewdog -f=checkstyle -name="Checkstyle" -reporter=github-pr-review -level=warning -fail-on-error=true
- name: Approve Pull Request if No Checkstyle Violations
uses: actions/github-script@v6
if: success()
with:
script: |
github.rest.pulls.createReview({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: context.issue.number,
event: "APPROVE"
})