@@ -6,67 +6,113 @@ permissions: read-all
6
6
on :
7
7
push :
8
8
pull_request :
9
- branches : [master]
9
+ branches :
10
+ - master
10
11
11
12
env :
12
13
APPLY_FIXES : none
13
14
APPLY_FIXES_EVENT : pull_request
14
15
APPLY_FIXES_MODE : commit
16
+ FILTER_REGEX_EXCLUDE : (mega-linter.yml)
15
17
DISABLE : SPELL
16
18
17
19
concurrency :
18
20
group : ${{ github.ref }}-${{ github.workflow }}
19
21
cancel-in-progress : true
20
22
21
23
jobs :
22
- build :
24
+ megalinter :
23
25
name : MegaLinter
24
26
runs-on : ubuntu-latest
27
+
28
+ permissions :
29
+ contents : write
30
+ issues : write
31
+ pull-requests : write
32
+
25
33
steps :
26
34
- name : Checkout Code
27
- uses : actions/checkout@v3
35
+ uses : actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11
28
36
with :
29
37
token : ${{ secrets.PAT || secrets.GITHUB_TOKEN }}
38
+ fetch-depth : 0
30
39
31
40
- name : MegaLinter
41
+ uses : oxsecurity/megalinter@7e042c726c68415475b05a65a686c612120a1232
32
42
id : ml
33
- uses : oxsecurity/megalinter@v7
34
43
env :
35
- VALIDATE_ALL_CODEBASE : true
44
+ VALIDATE_ALL_CODEBASE : >-
45
+ ${{
46
+ github.event_name == 'push' &&
47
+ contains(fromJSON('["refs/heads/main", "refs/heads/master"]'), github.ref)
48
+ }}
36
49
GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
37
50
38
51
- name : Archive production artifacts
39
- if : ${{ success() }} || ${{ failure() }}
40
- uses : actions/upload-artifact@v3
52
+ uses : actions/upload-artifact@c7d193f32edcb7bfad88892161225aeda64e9392
53
+ if : success() || failure()
41
54
with :
42
55
name : MegaLinter reports
43
56
path : |
44
57
megalinter-reports
45
58
mega-linter.log
46
59
60
+ - name : Set APPLY_FIXES_IF var
61
+ run : |
62
+ printf 'APPLY_FIXES_IF=%s\n' "${{
63
+ steps.ml.outputs.has_updated_sources == 1 &&
64
+ (
65
+ env.APPLY_FIXES_EVENT == 'all' ||
66
+ env.APPLY_FIXES_EVENT == github.event_name
67
+ ) &&
68
+ (
69
+ github.event_name == 'push' ||
70
+ github.event.pull_request.head.repo.full_name == github.repository
71
+ )
72
+ }}" >> "${GITHUB_ENV}"
73
+
74
+ - name : Set APPLY_FIXES_IF_* vars
75
+ run : |
76
+ printf 'APPLY_FIXES_IF_PR=%s\n' "${{
77
+ env.APPLY_FIXES_IF == 'true' &&
78
+ env.APPLY_FIXES_MODE == 'pull_request'
79
+ }}" >> "${GITHUB_ENV}"
80
+ printf 'APPLY_FIXES_IF_COMMIT=%s\n' "${{
81
+ env.APPLY_FIXES_IF == 'true' &&
82
+ env.APPLY_FIXES_MODE == 'commit' &&
83
+ (!contains(fromJSON('["refs/heads/main", "refs/heads/master"]'), github.ref))
84
+ }}" >> "${GITHUB_ENV}"
85
+
47
86
- name : Create Pull Request with applied fixes
87
+ uses : peter-evans/create-pull-request@153407881ec5c347639a548ade7d8ad1d6740e38
48
88
id : cpr
49
- 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)
50
- uses : peter-evans/create-pull-request@v5
89
+ if : env.APPLY_FIXES_IF_PR == 'true'
51
90
with :
52
91
token : ${{ secrets.PAT || secrets.GITHUB_TOKEN }}
53
92
commit-message : " [MegaLinter] Apply linters automatic fixes"
54
93
title : " [MegaLinter] Apply linters automatic fixes"
55
94
labels : bot
95
+
56
96
- name : Create PR output
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_name == 'push' || github.event.pull_request.head.repo.full_name == github.repository)
97
+ if : env.APPLY_FIXES_IF_PR == 'true'
58
98
run : |
59
- echo "Pull Request Number - ${{ steps.cpr.outputs.pull-request-number }}"
60
- echo "Pull Request URL - ${{ steps.cpr.outputs.pull-request-url }}"
99
+ echo "PR Number - ${{ steps.cpr.outputs.pull-request-number }}"
100
+ echo "PR URL - ${{ steps.cpr.outputs.pull-request-url }}"
61
101
62
102
- name : Prepare commit
63
- 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)
103
+ if : env.APPLY_FIXES_IF_COMMIT == 'true'
64
104
run : sudo chown -Rc $UID .git/
105
+
65
106
- name : Commit and push applied linter fixes
66
- 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)
67
- uses : stefanzweifel/git-auto-commit-action@v4
107
+ uses : stefanzweifel/git-auto-commit-action@8756aa072ef5b4a080af5dc8fef36c5d586e521d
108
+ if : env.APPLY_FIXES_IF_COMMIT == 'true'
68
109
with :
69
- branch : ${{ github.event.pull_request.head.ref || github.head_ref || github.ref }}
110
+ branch : >-
111
+ ${{
112
+ github.event.pull_request.head.ref ||
113
+ github.head_ref ||
114
+ github.ref
115
+ }}
70
116
commit_message : " [MegaLinter] Apply linters fixes"
71
117
commit_user_name : " github-actions"
72
118
commit_user_email : " github-actions[bot]@users.noreply.github.com"
0 commit comments