Skip to content

Commit 90ded2b

Browse files
authored
Add MegaLinter GitHub Action configuration
This file configures the MegaLinter GitHub Action to run on pushes and pull requests, applying linter fixes automatically and managing permissions.
1 parent 888778f commit 90ded2b

File tree

1 file changed

+185
-0
lines changed

1 file changed

+185
-0
lines changed

.github/workflows/megalinter.yml

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

0 commit comments

Comments
 (0)