-
Notifications
You must be signed in to change notification settings - Fork 591
120 lines (106 loc) · 4.01 KB
/
static-checks.yaml
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
on:
workflow_call:
inputs:
runs-on:
description: 'A tag to indicate which runner to use'
required: true
type: string
gochannel:
description: 'The snap store channel to use to install the go snap'
required: true
type: string
jobs:
static-checks:
runs-on: ${{ inputs.runs-on }}
env:
# Set PATH to ignore the load of magic binaries from /usr/local/bin And
# to use the go snap automatically. Note that we install go from the
# snap in a step below. Without this we get the GitHub-controlled latest
# version of go.
PATH: /snap/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:${{ github.workspace }}/bin
GOROOT: ""
GITHUB_PULL_REQUEST_TITLE: ${{ github.event.pull_request.title }}
BASE_REF: ${{ github.base_ref }}
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
# needed for git commit history
fetch-depth: 0
# Fetch base ref, needed for golangci-lint
- name: Fetching base ref ${{ github.base_ref }}
run: |
git fetch origin ${{ github.base_ref }}:${{ github.base_ref }}
- name: Download and install Debian dependencies
# Github does not allow variables in "uses"; this has to be a hard-coded path
uses: ./.github/actions/download-install-debian-deps
with:
snapd-src-dir: "${{ github.workspace }}"
# golang latest ensures things work on the edge
- name: Install the go snap
run: |
sudo snap install --classic --channel=${{ inputs.gochannel }} go
- name: Install ShellCheck as a snap
run: |
sudo apt-get remove --purge shellcheck
sudo snap install shellcheck
- name: Get C vendoring
run: |
cd c-vendor && ./vendor.sh
- name: Install golangci-lint snap
run: |
sudo snap install --classic golangci-lint
- name: Get changed files
id: changed-files
uses: tj-actions/[email protected]
with:
path: ./
- name: Save changes files
run: |
CHANGED_FILES="${{ steps.changed-files.outputs.all_changed_files }}"
echo "CHANGED_FILES=$CHANGED_FILES" >> $GITHUB_ENV
echo "The changed files found are: $CHANGED_FILES"
- name: Run static checks
run: |
# run gofmt checks only with the latest stable Go
if [ "${{ matrix.gochannel }}" != "latest/stable" ]; then
export SKIP_GOFMT=1
echo "Formatting checks will be skipped due to the use of Go version ${{ inputs.gochannel }}"
fi
sudo apt-get install -y python3-yamlordereddictloader
./run-checks --static
- name: Cache prebuilt indent
id: cache-indent-bin
uses: actions/cache@v4
with:
path: indent-bin
key: ${{ runner.os }}-indent-2.2.13
# build indent 2.2.13 which has this patch
# https://git.savannah.gnu.org/cgit/indent.git/commit/?id=22b83d68e9a8b429590f42920e9f473a236123cf
- name: Build indent 2.2.13
if: steps.cache-indent-bin.outputs.cache-hit != 'true'
run: |
sudo apt install texinfo autopoint
curl -O https://ftp.gnu.org/gnu/indent/indent-2.2.13.tar.xz
tar xvf indent-2.2.13.tar.xz
cd indent-2.2.13
autoreconf -if
# set prefix in case we want to pack to tar/extract into system
./configure --prefix=/opt/indent
make -j
make install DESTDIR=${{ github.workspace }}/indent-bin
find ${{ github.workspace }}/indent-bin -ls
- name: Check C source code formatting
run: |
set -x
cd cmd/
./autogen.sh
# apply formatting
PATH=${{ github.workspace }}/indent-bin/opt/indent/bin:$PATH make fmt
set +x
if [ -n "$(git diff --stat)" ]; then
git diff
echo "C files are not fomratted correctly, run 'make fmt'"
echo "make sure to have clang-format and indent 2.2.13+ installed"
exit 1
fi