forked from microsoft/azurelinux
-
Notifications
You must be signed in to change notification settings - Fork 0
100 lines (87 loc) · 3.57 KB
/
lint-specs.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
name: Spec Linting
on:
push:
paths:
- '**.spec'
branches: [main, dev, 1.0*]
pull_request:
paths:
- '**.spec'
branches: [main, dev, 1.0*]
jobs:
spec-lint:
name: Spec Linting
runs-on: ubuntu-latest
steps:
# Checkout the branch of our repo that triggered this action
- name: Workflow trigger checkout
uses: actions/checkout@v3
- name: Get base commit for PRs
if: ${{ github.event_name == 'pull_request' }}
run: |
git fetch origin ${{ github.base_ref }}
echo "base_sha=$(git rev-parse origin/${{ github.base_ref }})" >> $GITHUB_ENV
echo "Merging ${{ github.sha }} into ${{ github.base_ref }}"
- name: Get base commit for Pushes
if: ${{ github.event_name == 'push' }}
run: |
git fetch origin ${{ github.event.before }}
echo "base_sha=${{ github.event.before }}" >> $GITHUB_ENV
echo "Merging ${{ github.sha }} into ${{ github.event.before }}"
- name: Get the changed files
run: |
echo "Files changed: '$(git diff-tree --no-commit-id --name-only -r ${{ env.base_sha }} ${{ github.sha }})'"
changed_specs=$(git diff-tree --no-commit-id --name-only -r ${{ env.base_sha }} ${{ github.sha }} | { grep "\.spec$" || test $? = 1; })
echo "Files to validate: '${changed_specs}'"
echo "updated-specs=$(echo ${changed_specs})" >> $GITHUB_ENV
- name: Main branch checkout
uses: actions/checkout@v3
with:
ref: 'main'
path: 'main-checkout'
# Our linter is based on the spec-cleaner tool from the folks at openSUSE
# We apply a patch to modify it for CBL-Mariner's needs
- name: spec-cleaner checkout
uses: actions/checkout@v3
with:
repository: 'rpm-software-management/spec-cleaner'
ref: 'spec-cleaner-1.2.0'
path: 'spec-cleaner'
# For consistency, we use the same major/minor version of Python that CBL-Mariner ships
- name: Setup Python 3.7
uses: actions/setup-python@v3
with:
python-version: 3.7
# We take our version of the linting tool from the master branch to ensure rules
# are consistent across all branches
- name: Patch spec-cleaner with Mariner-specific lints
run: |
pushd spec-cleaner
git apply ../main-checkout/.github/workflows/mariner-spec-cleaner.patch
popd
- name: Install patched spec-cleaner
run: |
python -m pip install --upgrade pip
pip install -e ./spec-cleaner
# Set continue-on-error to true if we're blocking too many PRs here
# We don't want this tool to have a low signal-to-noise ratio
- name: Lint changed spec files
run: |
touch linted_specs.diff
spec-cleaner -d --diff-prog="git --no-pager diff" ${{ env.updated-specs }} | tee linted_specs.diff
if [ -s linted_specs.diff ]
then
echo -e "\n====================== LINTING FAILED ======================"
echo "Specs are not correctly formatted."
echo "A diff of the changes required is printed above."
echo "Linting output is available in the linted_specs artifact."
echo "Please properly format your specs according to the output before merging."
exit 1
fi
exit 0
- uses: actions/upload-artifact@v3
if: ${{ always() }}
with:
name: linted_specs
path: linted_specs.diff
if-no-files-found: ignore