Skip to content

Commit a79c88c

Browse files
author
Wes Dean
committed
Add Megalinter
1 parent b72fa7d commit a79c88c

File tree

2 files changed

+153
-0
lines changed

2 files changed

+153
-0
lines changed

.github/workflows/megalinter.yml

+96
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
---
2+
# MegaLinter GitHub Action configuration file
3+
# More info at https://oxsecurity.github.io/megalinter
4+
name: MegaLinter
5+
6+
# yamllint disable-line rule:truthy
7+
on:
8+
# Trigger mega-linter at every push. Action will also be visible from Pull Requests to main
9+
pull_request:
10+
workflow_dispatch:
11+
12+
env: # Comment env block if you do not want to apply fixes
13+
# Apply linter fixes configuration
14+
APPLY_FIXES: all # When active, APPLY_FIXES must also be defined as environment variable (in github/workflows/mega-linter.yml or other CI tool)
15+
APPLY_FIXES_EVENT: all # Decide which event triggers application of fixes in a commit or a PR (pull_request, push, all)
16+
APPLY_FIXES_MODE: commit # If APPLY_FIXES is used, defines if the fixes are directly committed (commit) or posted in a PR (pull_request)
17+
18+
concurrency:
19+
group: ${{ github.ref }}-${{ github.workflow }}
20+
cancel-in-progress: true
21+
22+
jobs:
23+
build:
24+
name: MegaLinter
25+
runs-on: ubuntu-latest
26+
steps:
27+
# Git Checkout
28+
- name: Checkout Code
29+
uses: actions/checkout@v3
30+
with:
31+
token: ${{ secrets.PAT || secrets.GITHUB_TOKEN }}
32+
fetch-depth: 1
33+
34+
# MegaLinter
35+
- name: MegaLinter
36+
id: ml
37+
# You can override MegaLinter flavor used to have faster performances
38+
# More info at https://oxsecurity.github.io/megalinter/flavors/
39+
uses: oxsecurity/megalinter/flavors/terraform@v6
40+
env:
41+
# All available variables are described in documentation
42+
# https://oxsecurity.github.io/megalinter/configuration/
43+
VALIDATE_ALL_CODEBASE: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }}
44+
45+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
46+
# ADD YOUR CUSTOM ENV VARIABLES HERE OR DEFINE THEM IN A FILE .mega-linter.yml AT THE ROOT OF YOUR REPOSITORY
47+
# DISABLE: COPYPASTE,SPELL # Uncomment to disable copy-paste and spell checks
48+
49+
# Upload MegaLinter artifacts
50+
- name: Archive production artifacts
51+
if: ${{ success() }} || ${{ failure() }}
52+
uses: actions/upload-artifact@v3
53+
with:
54+
name: MegaLinter reports
55+
path: |
56+
megalinter-reports
57+
mega-linter.log
58+
59+
# Create pull request if applicable (for now works only on PR from same repository, not from forks)
60+
- name: Create Pull Request with applied fixes
61+
id: cpr
62+
if: steps.ml.outputs.has_updated_sources == 1 && (env.APPLY_FIXES_EVENT == 'all' || env.APPLY_FIXES_EVENT == github.event_name) && env.APPLY_FIXES_MODE == 'pull_request' && (github.event_name == 'push' || github.event.pull_request.head.repo.full_name == github.repository)
63+
uses: peter-evans/create-pull-request@v4
64+
with:
65+
token: ${{ secrets.PAT || secrets.GITHUB_TOKEN }}
66+
commit-message: "[MegaLinter] Apply linter automatic fixes"
67+
title: "[MegaLinter] Apply linter automatic fixes"
68+
labels: bot
69+
- name: Create PR output
70+
if: steps.ml.outputs.has_updated_sources == 1 && (env.APPLY_FIXES_EVENT == 'all' || env.APPLY_FIXES_EVENT == github.event_name) && env.APPLY_FIXES_MODE == 'pull_request' && (github.event_name == 'push' || github.event.pull_request.head.repo.full_name == github.repository)
71+
run: |
72+
echo "Pull Request Number - ${{ steps.cpr.outputs.pull-request-number }}"
73+
echo "Pull Request URL - ${{ steps.cpr.outputs.pull-request-url }}"
74+
75+
# Push new commit if applicable (for now works only on PR from same repository, not from forks)
76+
- name: Prepare commit
77+
if: steps.ml.outputs.has_updated_sources == 1 && (env.APPLY_FIXES_EVENT == 'all' || env.APPLY_FIXES_EVENT == github.event_name) && env.APPLY_FIXES_MODE == 'commit' && github.ref != 'refs/heads/main' && (github.event_name == 'push' || github.event.pull_request.head.repo.full_name == github.repository)
78+
run: sudo chown -Rc $UID .git/
79+
- name: Commit and push applied linter fixes
80+
if: steps.ml.outputs.has_updated_sources == 1 && (env.APPLY_FIXES_EVENT == 'all' || env.APPLY_FIXES_EVENT == github.event_name) && env.APPLY_FIXES_MODE == 'commit' && github.ref != 'refs/heads/main' && (github.event_name == 'push' || github.event.pull_request.head.repo.full_name == github.repository)
81+
uses: stefanzweifel/git-auto-commit-action@v4
82+
with:
83+
branch: ${{ github.event.pull_request.head.ref || github.head_ref || github.ref }}
84+
commit_message: "[MegaLinter] Apply linter fixes"
85+
86+
- name: Check to see if the SARIF a was generated
87+
id: sarif_file_exists
88+
uses: andstor/file-existence-action@v2
89+
with:
90+
files: "megalinter-reports/megalinter-report.sarif"
91+
92+
- name: Upload MegaLinter scan results to GitHub Security tab
93+
if: steps.sarif_file_exists.outputs.files_exists == 'true'
94+
uses: github/codeql-action/upload-sarif@v2
95+
with:
96+
sarif_file: "megalinter-reports/megalinter-report.sarif"

.mega-linter.yml

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
---
2+
# don't test the reports Mega-Linter created, docs, or test files
3+
ADDITIONAL_EXCLUDED_DIRECTORIES:
4+
[report, megalinter-reports, docs, test, tests, venv]
5+
6+
# don't lint test files or documentation
7+
FILTER_REGEX_EXCLUDE: (.venv/|/test/|\.test\.|_test\.|/docs/|/index.html|.github/.*\.html)
8+
9+
# don't scan files listed in .gitignore (e.g., node_modules)
10+
IGNORE_GITIGNORED_FILES: true
11+
12+
# don't attempt to apply fixes at this time
13+
APPLY_FIXES: "false"
14+
15+
# Disable devskim as it's reporting an error with no log message
16+
DISABLE_LINTERS:
17+
[
18+
REPOSITORY_DEVSKIM,
19+
SPELL_MISSPELL,
20+
SPELL_CSPELL,
21+
SPELL_PROSELINT,
22+
COPYPASTE_JSCPD,
23+
BASH_EXEC,
24+
]
25+
26+
# only scan new / updated files, not everything
27+
VALIDATE_ALL_CODEBASE: true
28+
29+
# don't print the alpaca -- it's cute, but we don't need it in the logs
30+
PRINT_ALPACA: false
31+
32+
# don't fail on finding (yet)
33+
DISABLE_ERRORS: true
34+
35+
# use prettier for JavaScript code formatting
36+
JAVASCRIPT_DEFAULT_STYLE: prettier
37+
38+
# only scan the files in This commit, not the entire history of the repo
39+
REPOSITORY_GITLEAKS_ARGUMENTS: --no-git
40+
41+
# only run CSS linting on CSS files (SCSS has it's own linter)
42+
CSS_STYLELINT_FILE_EXTENSIONS: [".css"]
43+
44+
# don't lint the generated code in the docs/ directory
45+
REPOSITORY_DEVSKIM_ARGUMENTS: "--skip-git-ignored-files"
46+
47+
# shfmt will..
48+
# - use multiples of 2 spaces for indenting
49+
# - alllow binary operations to start new lines
50+
# - indent switch case statements
51+
# - place spaces around redirections
52+
# - keep column alignment padding
53+
BASH_SHFMT_ARGUMENTS: -i 2 -bn -ci -sr -kp
54+
55+
# skip the libraries, tests, and example files
56+
BASH_EXEC_FILTER_REGEX_EXCLUDE: (libs|\.(test|sample|example)\.)
57+

0 commit comments

Comments
 (0)