Skip to content

Commit b116536

Browse files
committed
Updated linting workflow
1 parent 71d4db3 commit b116536

File tree

1 file changed

+78
-77
lines changed

1 file changed

+78
-77
lines changed

.github/workflows/linting.yml

Lines changed: 78 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
name: linter
22

33
on:
4-
pull_request:
4+
pull_request:
55
branches: [main]
6+
paths-ignore: ['.github/**', '**.md']
67

78
permissions:
8-
contents: read
9-
packages: read
10-
statuses: write
9+
contents: read
10+
packages: read
11+
statuses: write
1112

1213
jobs:
13-
checkout:
14+
checkout:
1415
name: checkout
1516
runs-on: ubuntu-latest
1617
outputs:
@@ -20,101 +21,101 @@ jobs:
2021
needs_python_linting: ${{ steps.check_extension.outputs.python }}
2122
needs_other_linting: ${{ steps.check_extension.outputs.other }}
2223
steps:
23-
- name: Checking out the repo
24-
uses: actions/[email protected]
25-
- name: Setup Python
26-
uses: actions/[email protected]
27-
- name: Fetching PR Details
28-
run: |
24+
- name: Checking out the repo
25+
uses: actions/[email protected]
26+
- name: Setup Python
27+
uses: actions/[email protected]
28+
- name: Fetching PR Details
29+
run: |
2930
touch pr.json
3031
gh pr view $PR_NUMBER --json files > pr.json
31-
env:
32-
PR_NUMBER: ${{ github.event.pull_request.number }}
33-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
34-
- name: Checking file extensions
35-
id: check_extension
36-
uses: jannekem/run-python-script-action@v1
37-
with:
38-
script: |
39-
import os
40-
import json
32+
env:
33+
PR_NUMBER: ${{ github.event.pull_request.number }}
34+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
35+
- name: Checking file extensions
36+
id: check_extension
37+
uses: jannekem/run-python-script-action@v1
38+
with:
39+
script: |
40+
import os
41+
import json
4142
42-
# Setting default variables
43-
checks = { lang:'false' for lang in ['c_cpp', 'java', 'javascript', 'python', 'other'] }
44-
c_cpp_ext = ['.c', '.cpp', '.h', '.hpp', '.cc', '.hh', '.cxx', '.hxx']
43+
# Setting default variables
44+
checks = { lang:'false' for lang in ['c_cpp', 'java', 'javascript', 'python', 'other'] }
45+
c_cpp_ext = ['.c', '.cpp', '.h', '.hpp', '.cc', '.hh', '.cxx', '.hxx']
4546
46-
# Reading contents of PR
47-
with open('pr.json','r') as json_file:
48-
data = json.load(json_file)
47+
# Reading contents of PR
48+
with open('pr.json','r') as json_file:
49+
data = json.load(json_file)
4950
50-
# Iterating over data
51-
for file in data["files"]:
52-
path = file["path"]
53-
54-
# Ending loop if all are 'true'
55-
if all([val == 'true' for val in checks.values()]):
56-
break
51+
# Iterating over data
52+
for file in data["files"]:
53+
path = file["path"]
54+
55+
# Ending loop if all are 'true'
56+
if all([val == 'true' for val in checks.values()]):
57+
break
5758
58-
# Checking for extensions
59-
if os.path.exists(path):
60-
for key,value in checks.items():
61-
if value == 'true':
62-
continue
63-
if any([path.endswith(ext) for ext in c_cpp_ext]):
64-
checks['c_cpp']='true'
65-
elif path.endswith('.java'):
66-
checks['java']='true'
67-
elif path.endswith('.js'):
68-
checks['javascript']='true'
69-
elif path.endswith('.py'):
70-
checks['python']='true'
71-
elif '.' in path.split('/')[-1] and not path.endswith('.md'):
72-
checks['other']='true'
59+
# Checking for extensions
60+
if os.path.exists(path):
61+
for key,value in checks.items():
62+
if value == 'true':
63+
continue
64+
if any([path.endswith(ext) for ext in c_cpp_ext]):
65+
checks['c_cpp']='true'
66+
elif path.endswith('.java'):
67+
checks['java']='true'
68+
elif path.endswith('.js'):
69+
checks['javascript']='true'
70+
elif path.endswith('.py'):
71+
checks['python']='true'
72+
elif '.' in path.split('/')[-1] and not (path.startswith('.github') or path.endswith('.md')):
73+
checks['other']='true'
7374
74-
# Setting output variables based on file extensions
75-
for lang,val in checks.items():
76-
os.system(f'echo "{lang}={val}" >> "$GITHUB_OUTPUT"')
75+
# Setting output variables based on file extensions
76+
for lang,val in checks.items():
77+
os.system(f'echo "{lang}={val}" >> "$GITHUB_OUTPUT"')
7778
78-
c-cpp-linter:
79+
c-cpp-linter:
7980
needs: [checkout]
8081
if: ${{ needs.checkout.outputs.needs_c_cpp_linting == 'true' }}
8182
uses: Grow-with-Open-Source/C-CPP-Projects/.github/workflows/c-cpp-linter.yml@main
8283

83-
java-linter:
84+
java-linter:
8485
needs: [checkout]
8586
if: ${{ needs.checkout.outputs.needs_java_linting == 'true' }}
8687
uses: Grow-with-Open-Source/Java-Projects/.github/workflows/java-linter.yml@main
8788

88-
javascript-linter:
89+
javascript-linter:
8990
needs: [checkout]
9091
if: ${{ needs.checkout.outputs.needs_javascript_linting == 'true' }}
9192
uses: Grow-with-Open-Source/Javascript-Projects/.github/workflows/javascript-linter.yml@main
9293

93-
python-linter:
94+
python-linter:
9495
needs: [checkout]
9596
if: ${{ needs.checkout.outputs.needs_python_linting == 'true' }}
9697
uses: Grow-with-Open-Source/Python-Projects/.github/workflows/python-linter.yml@main
97-
98-
other-linter:
99-
needs: [checkout, c-cpp-linter, java-linter, javascript-linter, python-linter]
100-
if: ${{
101-
always() &&
102-
needs.checkout.outputs.needs_other_linting == 'true' ||
103-
((needs.c-cpp-linter.result == 'skipped' || needs.checkout.outputs.needs_c_cpp_linting == 'false') &&
104-
(needs.java-linter.result == 'skipped' || needs.checkout.outputs.needs_java_linting == 'false') &&
105-
(needs.javascript-linter.result == 'skipped' || needs.checkout.outputs.needs_javascript_linting == 'false') &&
106-
(needs.python-linter.result == 'skipped' || needs.checkout.outputs.needs_python_linting == 'false'))
107-
}}
98+
99+
other-linter:
100+
needs:
101+
[checkout, c-cpp-linter, java-linter, javascript-linter, python-linter]
102+
if: ${{
103+
always() &&
104+
needs.checkout.outputs.needs_other_linting == 'true' ||
105+
((needs.c-cpp-linter.result == 'skipped' || needs.checkout.outputs.needs_c_cpp_linting == 'false') &&
106+
(needs.java-linter.result == 'skipped' || needs.checkout.outputs.needs_java_linting == 'false') &&
107+
(needs.javascript-linter.result == 'skipped' || needs.checkout.outputs.needs_javascript_linting == 'false') &&
108+
(needs.python-linter.result == 'skipped' || needs.checkout.outputs.needs_python_linting == 'false'))
109+
}}
108110
runs-on: ubuntu-latest
111+
109112
steps:
110-
- name: Checking out the repo
111-
uses: actions/[email protected]
112-
with:
113-
fetch-depth: 0
114-
ref: ${{ github.event.pull_request.head.ref }}
115-
- name: Super Linter
116-
uses: super-linter/[email protected]
117-
env:
118-
VALIDATE_ALL_CODEBASE: false
119-
DEFAULT_BRANCH: main
113+
- name: Checkout code
114+
uses: actions/checkout@v4
115+
with:
116+
fetch-depth: 0
117+
118+
- name: Super-linter
119+
uses: super-linter/[email protected] # x-release-please-version
120+
env:
120121
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

0 commit comments

Comments
 (0)