Skip to content

Commit da6805c

Browse files
committed
update ci/cd
1 parent 98ddf59 commit da6805c

File tree

1 file changed

+62
-16
lines changed

1 file changed

+62
-16
lines changed

.github/workflows/mega-linter.yml

Lines changed: 62 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,67 +6,113 @@ permissions: read-all
66
on:
77
push:
88
pull_request:
9-
branches: [master]
9+
branches:
10+
- master
1011

1112
env:
1213
APPLY_FIXES: none
1314
APPLY_FIXES_EVENT: pull_request
1415
APPLY_FIXES_MODE: commit
16+
FILTER_REGEX_EXCLUDE: (mega-linter.yml)
1517
DISABLE: SPELL
1618

1719
concurrency:
1820
group: ${{ github.ref }}-${{ github.workflow }}
1921
cancel-in-progress: true
2022

2123
jobs:
22-
build:
24+
megalinter:
2325
name: MegaLinter
2426
runs-on: ubuntu-latest
27+
28+
permissions:
29+
contents: write
30+
issues: write
31+
pull-requests: write
32+
2533
steps:
2634
- name: Checkout Code
27-
uses: actions/checkout@v3
35+
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11
2836
with:
2937
token: ${{ secrets.PAT || secrets.GITHUB_TOKEN }}
38+
fetch-depth: 0
3039

3140
- name: MegaLinter
41+
uses: oxsecurity/megalinter@7e042c726c68415475b05a65a686c612120a1232
3242
id: ml
33-
uses: oxsecurity/megalinter@v7
3443
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+
}}
3649
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
3750

3851
- name: Archive production artifacts
39-
if: ${{ success() }} || ${{ failure() }}
40-
uses: actions/upload-artifact@v3
52+
uses: actions/upload-artifact@c7d193f32edcb7bfad88892161225aeda64e9392
53+
if: success() || failure()
4154
with:
4255
name: MegaLinter reports
4356
path: |
4457
megalinter-reports
4558
mega-linter.log
4659
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+
4786
- name: Create Pull Request with applied fixes
87+
uses: peter-evans/create-pull-request@153407881ec5c347639a548ade7d8ad1d6740e38
4888
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'
5190
with:
5291
token: ${{ secrets.PAT || secrets.GITHUB_TOKEN }}
5392
commit-message: "[MegaLinter] Apply linters automatic fixes"
5493
title: "[MegaLinter] Apply linters automatic fixes"
5594
labels: bot
95+
5696
- 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'
5898
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 }}"
61101
62102
- 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'
64104
run: sudo chown -Rc $UID .git/
105+
65106
- 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'
68109
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+
}}
70116
commit_message: "[MegaLinter] Apply linters fixes"
71117
commit_user_name: "github-actions"
72118
commit_user_email: "github-actions[bot]@users.noreply.github.com"

0 commit comments

Comments
 (0)