-
-
Notifications
You must be signed in to change notification settings - Fork 0
152 lines (141 loc) · 6.2 KB
/
mega-linter.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
# MegaLinter GitHub Action configuration file
# More info at https://megalinter.io
---
# yaml-language-server: $schema=https://json.schemastore.org/github-workflow.json
name: MegaLinter
on:
# Trigger mega-linter at every push. Action will also be visible from Pull Requests to master
push: # Comment this line to trigger action only on pull-requests (not recommended if you don't pay for GH Actions)
pull_request:
branches: [master, main]
env: # Comment env block if you do not want to apply fixes
# Apply linter fixes configuration
APPLY_FIXES: none # When active, APPLY_FIXES must also be defined as environment variable (in github/workflows/mega-linter.yml or other CI tool)
APPLY_FIXES_EVENT: pull_request # Decide which event triggers application of fixes in a commit or a PR (pull_request, push, all)
APPLY_FIXES_MODE: commit # If APPLY_FIXES is used, defines if the fixes are directly committed (commit) or posted in a PR (pull_request)
concurrency:
group: ${{ github.ref }}-${{ github.workflow }}
cancel-in-progress: true
permissions:
# Give the default GITHUB_TOKEN write permission to commit and push, comment issues & post new PR
# Remove the ones you do not need
contents: read
issues: write
pull-requests: write
jobs:
megalinter:
name: MegaLinter
runs-on: ubuntu-latest
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
steps:
# Git Checkout
# kics-scan ignore-line
- uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633
name: Checkout Code
with:
set-safe-directory: true
# token: ${{ secrets.PAT || secrets.GITHUB_TOKEN }}
token: ${{ secrets.GITHUB_TOKEN }}
fetch-depth: 0 # If you use VALIDATE_ALL_CODEBASE = true, you can remove this line to improve performances
# MegaLinter
# You can override MegaLinter flavor used to have faster performances
# More info at https://megalinter.io/latest/flavors
# kics-scan ignore-line
- uses: oxsecurity/megalinter/flavors/terraform@a7a0163b6c8ff7474a283d99a706e27483ddd80f
name: MegaLinter
id: ml
env:
# All available variables are described in documentation
# https://megalinter.io/latest/config-file/
# Validates all source when push on main or run in act, else just the git diff with main. Set 'true' if you always want to lint all sources
VALIDATE_ALL_CODEBASE: ${{ (github.event_name == 'push' && github.ref == 'refs/heads/main') || github.actor == 'nektos/act' }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# ADD YOUR CUSTOM ENV VARIABLES HERE TO OVERRIDE VALUES OF .mega-linter.yml AT THE ROOT OF YOUR REPOSITORY
# Upload MegaLinter artifacts
# kics-scan ignore-line
- uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3
name: Archive production artifacts
if: github.actor != 'nektos/act' && (success() || failure())
with:
name: MegaLinter reports
path: |
megalinter-reports
mega-linter.log
# Create pull request if applicable (for now works only on PR from same repository, not from forks)
- uses: peter-evans/create-pull-request@70a41aba780001da0a30141984ae2a0c95d8704e
name: Create Pull Request with applied fixes
id: cpr
if: >-
github.actor != 'nektos/act' &&
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
)
with:
token: ${{ secrets.GITHUB_TOKEN }}
commit-message: '[MegaLinter] Apply linters automatic fixes'
title: '[MegaLinter] Apply linters automatic fixes'
labels: bot
- name: Create PR output
if: >-
github.actor != 'nektos/act' &&
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
)
run: |
printf "Pull Request Number - %s\n" "${PR_NUMBER}"
printf "Pull Request URL - %s\n" "${PR_URL}"
env:
PR_NUMBER: '${{ steps.cpr.outputs.pull-request-number }}'
PR_URL: '${{ steps.cpr.outputs.pull-request-url }}'
# Push new commit if applicable (for now works only on PR from same repository, not from forks)
- name: Prepare commit
if: >-
github.actor != 'nektos/act' &&
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
)
run: 'sudo chown -Rc $UID .git/'
# kics-scan ignore-line
- uses: stefanzweifel/git-auto-commit-action@8756aa072ef5b4a080af5dc8fef36c5d586e521d
name: Commit and push applied linter fixes
if: >-
github.actor != 'nektos/act' &&
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
)
with:
branch: ${{ github.event.pull_request.head.ref || github.head_ref || github.ref }}
commit_message: '[MegaLinter] Apply linters fixes'
commit_user_name: megalinter-bot
commit_user_email: nicolas.vuillamy@ox.security