Skip to content

Commit 0cb7899

Browse files
authored
Create mega-linter.yml
1 parent 5b427f8 commit 0cb7899

File tree

1 file changed

+84
-0
lines changed

1 file changed

+84
-0
lines changed

.github/workflows/mega-linter.yml

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
---
2+
# MegaLinter GitHub Action configuration file
3+
# More info at https://megalinter.io
4+
name: MegaLinter
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+
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: 0 # If you use VALIDATE_ALL_CODEBASE = true, you can remove this line to improve performances
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://megalinter.io/flavors/
39+
uses: oxsecurity/megalinter/flavors/javascript@v7
40+
env:
41+
# All available variables are described in documentation
42+
# https://megalinter.io/configuration/
43+
VALIDATE_ALL_CODEBASE: true # Set ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }} to validate only diff with main branch
44+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
45+
# ADD YOUR CUSTOM ENV VARIABLES HERE TO OVERRIDE VALUES OF .mega-linter.yml AT THE ROOT OF YOUR REPOSITORY
46+
47+
# Upload MegaLinter artifacts
48+
- name: Archive production artifacts
49+
if: ${{ success() }} || ${{ failure() }}
50+
uses: actions/upload-artifact@v3
51+
with:
52+
name: MegaLinter reports
53+
path: |
54+
megalinter-reports
55+
mega-linter.log
56+
57+
# Create pull request if applicable (for now works only on PR from same repository, not from forks)
58+
- name: Create Pull Request with applied fixes
59+
id: cpr
60+
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) && !contains(github.event.head_commit.message, 'skip fix')
61+
uses: peter-evans/create-pull-request@v5
62+
with:
63+
token: ${{ secrets.PAT || secrets.GITHUB_TOKEN }}
64+
commit-message: '[MegaLinter] Apply linters automatic fixes'
65+
title: '[MegaLinter] Apply linters automatic fixes'
66+
labels: bot
67+
- name: Create PR output
68+
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) && !contains(github.event.head_commit.message, 'skip fix')
69+
run: |
70+
echo "Pull Request Number - ${{ steps.cpr.outputs.pull-request-number }}"
71+
echo "Pull Request URL - ${{ steps.cpr.outputs.pull-request-url }}"
72+
73+
# Push new commit if applicable (for now works only on PR from same repository, not from forks)
74+
- name: Prepare commit
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/main' && (github.event_name == 'push' || github.event.pull_request.head.repo.full_name == github.repository) && !contains(github.event.head_commit.message, 'skip fix')
76+
run: sudo chown -Rc $UID .git/
77+
- name: Commit and push applied linter fixes
78+
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) && !contains(github.event.head_commit.message, 'skip fix')
79+
uses: stefanzweifel/git-auto-commit-action@v4
80+
with:
81+
branch: ${{ github.event.pull_request.head.ref || github.head_ref || github.ref }}
82+
commit_message: '[MegaLinter] Apply linters fixes'
83+
commit_user_name: megalinter-bot
84+
commit_user_email: nicolas.vuillamy@ox.security

0 commit comments

Comments
 (0)