Skip to content

Commit f1fb6c6

Browse files
authored
Merge pull request #62 from ONS-Innovation/KEH-1221
KEH-1221 - Add additional linters
2 parents c92c7b1 + 9bf254b commit f1fb6c6

31 files changed

+797
-497
lines changed

.checkov.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Checkov configuration file
2+
# This file is used to configure Checkov, a static code analysis tool for infrastructure as code.
3+
---
4+
skip-check:
5+
# IAM Resourcing using wildcards
6+
- CKV_AWS_356
7+
- CKV_AWS_111
8+
9+
# Lambda Encryption and Dead Letter Queue
10+
- CKV_AWS_173
11+
- CKV_AWS_116
12+
13+
# Cloudwatch Logs KMS Encryption and Retention
14+
- CKV_AWS_158
15+
- CKV_AWS_338
16+
17+
# Pin module sources to a commit hash (false positive)
18+
- CKV_TF_1
19+
20+
# These ignores are TEMPORARY. They will be resolved in the future.
21+
- CKV_AWS_108
22+
- CKV_AWS_272

.github/pull_request_template.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,38 @@
1-
## What type of PR is this? (check all applicable)
1+
# What type of PR is this? (check all applicable)
22

33
- [ ] Refactor
44
- [ ] Feature
55
- [ ] Bug Fix
66
- [ ] Optimization
77
- [ ] Documentation Update
88

9-
### What
9+
## What
1010

1111
Describe what you have changed and why.
1212

13-
### Testing
13+
## Testing
1414

1515
Have any new tests been added as part of this issue? If not, try to explain why test coverage is not needed here.
1616

1717
- [ ] Yes
1818
- [ ] No
19-
Please write a brief description of why test coverage is not necessary here.
19+
Please write a brief description of why test coverage is not necessary here.
2020
- [ ] Not as part of this ticket. (Could be done at a later point)
2121

22-
### Documentation
22+
## Documentation
2323

24-
Has any new documentation been written as part of this issue? We should try to keep documentation up to date
24+
Has any new documentation been written as part of this issue? We should try to keep documentation up to date
2525
as new code is added, rather than leaving it for the future.
2626

2727
- [ ] Yes
2828
- [ ] No
29-
Please write a brief description of why documentation is not necessary here.
29+
Please write a brief description of why documentation is not necessary here.
3030
- [ ] Not as part of this ticket. (Could be done at a later point)
3131

32-
### Related issues
32+
## Related issues
3333

3434
Provide links to any related issues.
3535

36-
### How to review
36+
## How to review
3737

38-
Describe the steps required to test the changes.
38+
Describe the steps required to test the changes.

.github/workflows/ci.yml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ on: # yamllint disable-line rule:truthy
77
pull_request:
88
branches: [main]
99

10+
permissions: read-all
11+
1012
concurrency:
1113
group: "${{ github.head_ref || github.ref }}-${{ github.workflow }}"
1214
cancel-in-progress: true
@@ -15,12 +17,10 @@ jobs:
1517
lint-test:
1618
name: Lint and Test
1719
runs-on: ubuntu-22.04
18-
permissions:
19-
contents: read
2020
strategy:
2121
matrix:
2222
python-version: ["3.12"]
23-
23+
2424
steps:
2525
- uses: actions/checkout@v4
2626
- name: Install Poetry
@@ -31,18 +31,18 @@ jobs:
3131
with:
3232
python-version: ${{ matrix.python-version }}
3333
cache: poetry
34-
34+
3535
- name: Display Python version
3636
run: python -c "import sys; print(sys.version)"
3737

3838
- name: Install dependencies
3939
run: make install-dev
4040

41-
- name: Lint Python (check only)
42-
run: make lint
41+
- name: Lint Python and Markdown (check only)
42+
run: make lint-check
4343

4444
- name: Run tests
4545
run: make test
46-
47-
- name: Cleanup residue file
48-
run: make clean
46+
47+
- name: Cleanup residue files
48+
run: make clean

.github/workflows/deploy_mkdocs.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@ jobs:
1919
- uses: actions/setup-python@v5
2020
with:
2121
python-version: 3.x
22-
- run: echo "cache_id=$(date --utc '+%V')" >> $GITHUB_ENV
22+
- run: echo "cache_id=$(date --utc '+%V')" >> $GITHUB_ENV
2323
- uses: actions/cache@v4
2424
with:
2525
key: mkdocs-material-${{ env.cache_id }}
26-
path: .cache
26+
path: .cache
2727
restore-keys: |
2828
mkdocs-material-
2929
- run: pip install poetry
3030
- run: poetry install --only docs
31-
- run: poetry run mkdocs gh-deploy --force
31+
- run: poetry run mkdocs gh-deploy --force

.github/workflows/megalinter.yml

Lines changed: 204 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,204 @@
1+
# MegaLinter GitHub Action configuration file
2+
# More info at https://megalinter.io
3+
---
4+
name: MegaLinter
5+
6+
# Trigger mega-linter at every push. Action will also be visible from
7+
# Pull Requests to main
8+
on: # yamllint disable-line rule:truthy
9+
push:
10+
branches: [main]
11+
pull_request:
12+
branches: [main]
13+
14+
permissions:
15+
contents: write
16+
issues: write
17+
pull-requests: write
18+
statuses: write
19+
20+
# Comment env block if you do not want to apply fixes
21+
env:
22+
# Apply linter fixes configuration
23+
#
24+
# When active, APPLY_FIXES must also be defined as environment variable
25+
# (in github/workflows/mega-linter.yml or other CI tool)
26+
# This is dynamically set based on the presence of the PAT secret.
27+
# If the PAT secret is not present, the APPLY_FIXES environment variable is set to none.
28+
# Without a PAT token, commits/PRs will not trigger workflow runs.
29+
# This is a GitHub Actions limitation to prevent infinite loops.
30+
APPLY_FIXES: all
31+
32+
# Decide which event triggers application of fixes in a commit or a PR
33+
# (pull_request, push, all)
34+
APPLY_FIXES_EVENT: pull_request
35+
36+
# If APPLY_FIXES is used, defines if the fixes are directly committed (commit)
37+
# or posted in a PR (pull_request)
38+
APPLY_FIXES_MODE: commit
39+
40+
# Show individual linter status in GitHub Actions status summary
41+
GITHUB_STATUS_REPORTER: true
42+
43+
# Enable to show lint results in GitHub PR comments.
44+
GITHUB_COMMENT_REPORTER: true
45+
46+
# Set to simple to avoid external images in generated markdown
47+
REPORTERS_MARKDOWN_TYPE: simple
48+
49+
concurrency:
50+
group: "${{ github.head_ref || github.ref }}-${{ github.workflow }}"
51+
cancel-in-progress: true
52+
53+
jobs:
54+
lint:
55+
name: MegaLinter
56+
runs-on: ubuntu-latest
57+
58+
# Give the default GITHUB_TOKEN write permission to commit and push, comment
59+
# issues, and post new Pull Requests; remove the ones you do not need
60+
permissions:
61+
contents: write
62+
issues: write
63+
pull-requests: write
64+
statuses: write
65+
66+
steps:
67+
# Git Checkout
68+
- name: Checkout Code
69+
uses: actions/checkout@v4
70+
with:
71+
token: ${{ secrets.PAT || secrets.GITHUB_TOKEN }}
72+
73+
# If you use VALIDATE_ALL_CODEBASE = true, you can remove this line to
74+
# improve performance
75+
fetch-depth: 0
76+
77+
- name: Check PAT and Set APPLY_FIXES
78+
run: |
79+
if [ -z "${{ secrets.PAT }}" ]; then
80+
echo "APPLY_FIXES=none" >> "$GITHUB_ENV"
81+
fi
82+
83+
# MegaLinter
84+
- name: MegaLinter
85+
86+
# You can override MegaLinter flavor used to have faster performances
87+
# More info at https://megalinter.io/latest/flavors/
88+
uses: oxsecurity/megalinter@1fc052d03c7a43c78fe0fee19c9d648b749e0c01
89+
90+
id: ml
91+
92+
# All available variables are described in documentation
93+
# https://megalinter.io/latest/config-file/
94+
env:
95+
# Validates all source when push on main, else just the git diff with
96+
# main. Override with true if you always want to lint all sources
97+
#
98+
# To validate the entire codebase, set to:
99+
# VALIDATE_ALL_CODEBASE: true
100+
#
101+
# To validate only diff with main, set to:
102+
# VALIDATE_ALL_CODEBASE: >-
103+
# ${{
104+
# github.event_name == 'push' &&
105+
# github.ref == 'refs/heads/main'
106+
# }}
107+
VALIDATE_ALL_CODEBASE: true
108+
109+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
110+
111+
# ADD YOUR CUSTOM ENV VARIABLES HERE TO OVERRIDE VALUES OF
112+
# .mega-linter.yml AT THE ROOT OF YOUR REPOSITORY
113+
114+
# Upload MegaLinter artifacts
115+
- name: Archive production artifacts
116+
uses: actions/upload-artifact@v4
117+
if: success() || failure()
118+
with:
119+
name: MegaLinter reports
120+
path: |
121+
megalinter-reports
122+
mega-linter.log
123+
124+
# Create pull request if applicable
125+
# (for now works only on PR from same repository, not from forks)
126+
- name: Create Pull Request with applied fixes
127+
uses: peter-evans/create-pull-request@5e914681df9dc83aa4e4905692ca88beb2f9e91f
128+
id: cpr
129+
if: >-
130+
steps.ml.outputs.has_updated_sources == 1 &&
131+
(
132+
env.APPLY_FIXES_EVENT == 'all' ||
133+
env.APPLY_FIXES_EVENT == github.event_name
134+
) &&
135+
env.APPLY_FIXES_MODE == 'pull_request' &&
136+
(
137+
github.event_name == 'push' ||
138+
github.event.pull_request.head.repo.full_name == github.repository
139+
) &&
140+
!contains(github.event.head_commit.message, 'skip fix')
141+
with:
142+
token: ${{ secrets.PAT || secrets.GITHUB_TOKEN }}
143+
commit-message: "[MegaLinter] Apply linters automatic fixes"
144+
title: "[MegaLinter] Apply linters automatic fixes"
145+
labels: bot
146+
147+
- name: Create PR output
148+
if: >-
149+
steps.ml.outputs.has_updated_sources == 1 &&
150+
(
151+
env.APPLY_FIXES_EVENT == 'all' ||
152+
env.APPLY_FIXES_EVENT == github.event_name
153+
) &&
154+
env.APPLY_FIXES_MODE == 'pull_request' &&
155+
(
156+
github.event_name == 'push' ||
157+
github.event.pull_request.head.repo.full_name == github.repository
158+
) &&
159+
!contains(github.event.head_commit.message, 'skip fix')
160+
run: |
161+
echo "PR Number - ${{ steps.cpr.outputs.pull-request-number }}"
162+
echo "PR URL - ${{ steps.cpr.outputs.pull-request-url }}"
163+
164+
# Push new commit if applicable
165+
# (for now works only on PR from same repository, not from forks)
166+
- name: Prepare commit
167+
if: >-
168+
steps.ml.outputs.has_updated_sources == 1 &&
169+
(
170+
env.APPLY_FIXES_EVENT == 'all' ||
171+
env.APPLY_FIXES_EVENT == github.event_name
172+
) &&
173+
env.APPLY_FIXES_MODE == 'commit' &&
174+
github.ref != 'refs/heads/main' &&
175+
(
176+
github.event_name == 'push' ||
177+
github.event.pull_request.head.repo.full_name == github.repository
178+
) &&
179+
!contains(github.event.head_commit.message, 'skip fix')
180+
run: sudo chown -Rc $UID .git/
181+
182+
- name: Commit and push applied linter fixes
183+
uses: stefanzweifel/git-auto-commit-action@8621497c8c39c72f3e2a999a26b4ca1b5058a842
184+
if: >-
185+
steps.ml.outputs.has_updated_sources == 1 &&
186+
(
187+
env.APPLY_FIXES_EVENT == 'all' ||
188+
env.APPLY_FIXES_EVENT == github.event_name
189+
) &&
190+
env.APPLY_FIXES_MODE == 'commit' &&
191+
github.ref != 'refs/heads/main' &&
192+
(
193+
github.event_name == 'push' ||
194+
github.event.pull_request.head.repo.full_name == github.repository
195+
) &&
196+
!contains(github.event.head_commit.message, 'skip fix')
197+
with:
198+
branch: >-
199+
${{
200+
github.event.pull_request.head.ref ||
201+
github.head_ref ||
202+
github.ref
203+
}}
204+
commit_message: "[MegaLinter] Apply linters fixes"

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,6 @@ terraform.rc
6363

6464
# VS Code settings
6565
.vscode/
66+
67+
# Ignore MegaLinter reports
68+
megalinter-reports/

.markdownlint.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"MD013": false
3+
}

.markdownlintignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
venv

0 commit comments

Comments
 (0)