Skip to content

Commit 0c0c043

Browse files
authored
ci: create mega-linter.yml
1 parent 4ddf983 commit 0c0c043

File tree

1 file changed

+79
-0
lines changed

1 file changed

+79
-0
lines changed

.github/workflows/mega-linter.yml

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
---
2+
# Mega-Linter GitHub Action configuration file
3+
# More info at https://megalinter.io
4+
name: Mega-Linter
5+
6+
on:
7+
# Trigger mega-linter at every push. Action will also be visible from Pull Requests to master
8+
push: # Comment this line to trigger action only on pull-requests (not recommended if you don't pay for GH Actions)
9+
pull_request:
10+
branches: [master, main]
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: pull_request # 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+
jobs:
19+
build:
20+
name: Mega-Linter
21+
runs-on: ubuntu-latest
22+
steps:
23+
# Git Checkout
24+
- name: Checkout Code
25+
uses: actions/checkout@v4
26+
with:
27+
token: ${{ secrets.PAT || secrets.GITHUB_TOKEN }}
28+
fetch-depth: 0
29+
30+
# Mega-Linter
31+
- name: Mega-Linter
32+
id: ml
33+
# You can override Mega-Linter flavor used to have faster performances
34+
# More info at https://megalinter.io/latest/flavors/
35+
uses: oxsecurity/megalinter/flavors/javascript@latest
36+
env:
37+
# All available variables are described in documentation
38+
# https://megalinter.io/latest/config-file/
39+
VALIDATE_ALL_CODEBASE: true # Set ${{ github.event_name == 'push' && github.ref == 'refs/heads/master' }} to validate only diff with master branch
40+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
41+
# ADD YOUR CUSTOM ENV VARIABLES HERE TO OVERRIDE VALUES OF .mega-linter.yml AT THE ROOT OF YOUR REPOSITORY
42+
43+
# Upload Mega-Linter artifacts
44+
- name: Archive production artifacts
45+
if: success() || failure()
46+
uses: actions/upload-artifact@v4
47+
with:
48+
name: Mega-Linter reports
49+
include-hidden-files: "true"
50+
path: |
51+
megalinter-reports
52+
mega-linter.log
53+
54+
# Create pull request if applicable (for now works only on PR from same repository, not from forks)
55+
- name: Create Pull Request with applied fixes
56+
id: cpr
57+
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.pull_request.head.repo.full_name == github.repository && !contains(github.event.head_commit.message, 'skip fix')
58+
uses: peter-evans/create-pull-request@v6
59+
with:
60+
token: ${{ secrets.PAT || secrets.GITHUB_TOKEN }}
61+
commit-message: "[Mega-Linter] Apply linters automatic fixes"
62+
title: "[Mega-Linter] Apply linters automatic fixes"
63+
labels: bot
64+
- name: Create PR output
65+
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.pull_request.head.repo.full_name == github.repository && !contains(github.event.head_commit.message, 'skip fix')
66+
run: |
67+
echo "Pull Request Number - ${{ steps.cpr.outputs.pull-request-number }}"
68+
echo "Pull Request URL - ${{ steps.cpr.outputs.pull-request-url }}"
69+
70+
# Push new commit if applicable (for now works only on PR from same repository, not from forks)
71+
- name: Prepare commit
72+
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/master' && github.event.pull_request.head.repo.full_name == github.repository && !contains(github.event.head_commit.message, 'skip fix')
73+
run: sudo chown -Rc $UID .git/
74+
- name: Commit and push applied linter fixes
75+
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/master' && github.event.pull_request.head.repo.full_name == github.repository && !contains(github.event.head_commit.message, 'skip fix')
76+
uses: stefanzweifel/git-auto-commit-action@v5
77+
with:
78+
branch: ${{ github.event.pull_request.head.ref || github.head_ref || github.ref }}
79+
commit_message: "[Mega-Linter] Apply linters fixes"

0 commit comments

Comments
 (0)