forked from chipsalliance/verible-formatter-action
-
Notifications
You must be signed in to change notification settings - Fork 1
/
action.yml
137 lines (131 loc) · 5.33 KB
/
action.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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
name: 'verible-formatter'
description: 'This action formats Verilog/SystemVerilog code'
author: 'Antmicro'
inputs:
parameters:
description: 'Additional parameters passed to formatter executable'
required: false
default: ''
files:
description: 'Optional array of files with source code to format'
required: false
default: './**/*.{v,sv}'
github_token:
description: 'GITHUB_TOKEN'
default: ''
fail_on_formatting_suggestions:
description: 'If there are any formatting issues in the codebase, the action will return with an error'
required: false
default: 'false'
verible_version:
description: 'Use selected Verible version (defaults to latest release)'
default: 'latest'
runs:
using: 'composite'
steps:
- name: Check if running on Ubuntu Linux
shell: bash
run: |
source /etc/os-release
case "$ID" in
ubuntu) echo 'Running on Ubuntu Linux'; exit 0 ;;
*) echo 'Not running on Ubuntu Linux'; exit 1 ;;
esac
- name: Install dependencies
shell: bash
run: |
sudo apt-get update -qq
sudo apt-get -y install --no-install-recommends git
- name: Install Verible
uses: chipsalliance/verible-actions-common/install-verible@main
with:
github_token: ${{ inputs.github_token }}
verible_version: ${{ inputs.verible_version }}
- name: Install reviewdog
uses: chipsalliance/verible-actions-common/build-reviewdog@main
- name: Run Verible formatter with reviewdog
shell: bash
run: |
echo "### Run information ###"
echo "-----------------------"
echo "GITHUB_ACTION : ${{ github.action }}"
echo "GITHUB_EVENT_NAME : ${{ github.event_name }}"
echo "GITHUB_WORKSPACE : ${{ github.workspace }}"
echo "artifact_path=$GITHUB_WORKSPACE" >> $GITHUB_ENV
echo "ARTIFACT_PATH : $artifact_path"
echo "# --- "
if [ "${{ github.event_name }}" == "pull_request" ] || [ "${{ github.event_name }}" == "pull_request_target" ]; then
echo "### Prepare PR branch ###"
echo "-------------------------"
event_file=event.json
diff_cmd="git diff FETCH_HEAD"
if [ -f "$event_file" ]; then
pr_branch=$(python3 -c "import sys, json; print(json.load(sys.stdin)['${{ github.event_name }}']['head']['ref'])" < $event_file)
base_branch=$(python3 -c "import sys, json; print(json.load(sys.stdin)['${{ github.event_name }}']['base']['ref'])" < $event_file)
git fetch origin $pr_branch
git checkout $pr_branch
echo "PR branch : $pr_branch"
echo "Base branch : $base_branch"
echo "# --- "
diff_cmd="git diff $base_branch $pr_branch"
export OVERRIDE_GITHUB_EVENT_PATH=`pwd`/$event_file
fi
echo "# --- "
fi
echo "### Run Verible formatter ###"
echo "-----------------------------"
echo "PARAMETERS = ${{ inputs.parameters }}"
echo "FILES = ${{ inputs.files }}"
shopt -s globstar nullglob
verible-verilog-format --inplace ${{ inputs.parameters }} ${{ inputs.files }} > /dev/null 2> $GITHUB_WORKSPACE/vvf_err.log
git diff > vvf_git_diff.log
git diff --name-only > vvf_files.log
git stash
echo "# --- "
if [ "${{ github.event_name }}" == "pull_request" ] || [ "${{ github.event_name }}" == "pull_request_target" ]; then
echo "### Run reviewdog ###"
echo "---------------------"
export REVIEWDOG_GITHUB_API_TOKEN="${{ inputs.github_token }}"
echo "running reviewdog"
reviewdog -name="verible-verilog-format" \
-f=diff -f.diff.strip=1 \
-reporter="github-pr-review" \
-filter-mode="diff_context" \
-level="info" \
-diff="$diff_cmd" \
-fail-on-error="false" <vvf_git_diff.log || true
fi
if [ "${{ github.event_name }}" == "push" ]; then
if [ "${{ inputs.fail_on_formatting_suggestions }}" == "true" ]; then
if [[ -s "vvf_git_diff.log" || -s "vvf_err.log" ]]; then
echo "Either:"
echo " - Found code non-compliant with formatting rules"
echo "Or:"
echo " - The formatter returned with an error in processing of at least one file"
echo "Marking this workflow run as: FAIL"
echo "Check saved artifacts for more detailed logs."
exit 1
else
echo "Codebase is compliant with formatting rules: SUCCESS"
fi
else
echo "Checks for files, which are not in current PR: DISABLED"
fi
echo "# --- "
fi
echo "### Run summary ###"
echo "-------------------"
echo "The diff file contains the following number of:"
echo "newlines, words, bytes"
cat "vvf_git_diff.log" | wc
echo "# --- "
- name: Upload artifacts
if: failure()
uses: actions/upload-artifact@v3
with:
name: vvf_logs
retention-days: 7
path: |
${{ env.artifact_path }}/vvf_git_diff.log
${{ env.artifact_path }}/vvf_files.log
${{ env.artifact_path }}/vvf_err.log