1717# More info at https://megalinter.io
1818name : MegaLinter
1919
20- on :
21- # Trigger mega-linter at every push. Action will also be visible from Pull Requests to main
22- # push: # Comment this line to trigger action only on pull-requests (not recommended if you don't pay for GH Actions)
20+ on : # yamllint disable-line rule:truthy - false positive
2321 pull_request :
2422
2523permissions :
2624 contents : read
2725
28- env : # Comment env block if you don't want to apply fixes
29- # Apply linter fixes configuration
30- APPLY_FIXES : all # When active, APPLY_FIXES must also be defined as environment variable (in github/workflows/mega-linter.yml or other CI tool)
31- APPLY_FIXES_EVENT : pull_request # Decide which event triggers application of fixes in a commit or a PR (pull_request, push, all)
32- APPLY_FIXES_MODE : commit # If APPLY_FIXES is used, defines if the fixes are directly committed (commit) or posted in a PR (pull_request)
26+ env :
27+ APPLY_FIXES : all
28+ APPLY_FIXES_EVENT : pull_request
29+ APPLY_FIXES_MODE : commit
3330
3431concurrency :
3532 group : ${{ github.ref || github.run_id }}-${{ github.workflow }}
4037 name : MegaLinter
4138 runs-on : ubuntu-24.04
4239 permissions :
43- # Give the default GITHUB_TOKEN write permission to commit and push, comment issues & post new PR
44- # Remove the ones you do not need
40+ # Give the default GITHUB_TOKEN write permission to commit and push, comment
41+ # issues & post new PR; remove the ones you do not need
4542 contents : write
4643 issues : write
4744 pull-requests : write
@@ -51,19 +48,19 @@ jobs:
5148 uses : actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # 5.0.0
5249 with :
5350 token : ${{ secrets.PAT || secrets.GITHUB_TOKEN }}
51+ fetch-depth : 0 # Required for pushing commits to PRs
5452
5553 # MegaLinter
5654 - name : MegaLinter
5755 id : ml
58- # You can override MegaLinter flavor used to have faster performances
59- # More info at https://megalinter.io/flavors/
60- uses : oxsecurity/megalinter/flavors/python@e08c2b05e3dbc40af4c23f41172ef1e068a7d651 # 8.8.0
56+ uses : oxsecurity/megalinter/flavors/python@0dcbedd66ea456ba2d54fd350affaa15df8a0da3 # 9.0.1
6157 env :
6258 # All available variables are described in documentation
63- # https://megalinter.io/configuration/
59+ # https://megalinter.io/latest/ configuration/
6460 VALIDATE_ALL_CODEBASE : " true"
6561 GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
66- # ADD YOUR CUSTOM ENV VARIABLES HERE OR DEFINE THEM IN A FILE .mega-linter.yml AT THE ROOT OF YOUR REPOSITORY
62+ # ADD YOUR CUSTOM ENV VARIABLES HERE OR DEFINE THEM IN A FILE
63+ # .mega-linter.yml AT THE ROOT OF YOUR REPOSITORY
6764 GITHUB_COMMENT_REPORTER : " true"
6865 PYTHON_RUFF_ARGUMENTS : --config pyproject.toml --config 'output-format="github"'
6966 PYTHON_RUFF_FORMAT_ARGUMENTS : --config pyproject.toml --config 'output-format="github"'
@@ -74,19 +71,53 @@ jobs:
7471 uses : actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # 4.6.2
7572 with :
7673 name : MegaLinter reports
74+ include-hidden-files : " true"
7775 path : |
7876 megalinter-reports
7977 mega-linter.log
8078
81- # Push new commit if applicable (for now works only on PR from same repository, not from forks)
79+ # Set APPLY_FIXES_IF var for use in future steps
80+ - name : Set APPLY_FIXES_IF var
81+ run : |
82+ printf 'APPLY_FIXES_IF=%s\n' "${{
83+ steps.ml.outputs.has_updated_sources == 1 &&
84+ (
85+ env.APPLY_FIXES_EVENT == 'all' ||
86+ env.APPLY_FIXES_EVENT == github.event_name
87+ ) &&
88+ (
89+ github.event_name == 'push' ||
90+ github.event.pull_request.head.repo.full_name == github.repository
91+ )
92+ }}" >> "${GITHUB_ENV}"
93+
94+ # Set APPLY_FIXES_IF_* vars for use in future steps
95+ - name : Set APPLY_FIXES_IF_* vars
96+ run : |
97+ printf 'APPLY_FIXES_IF_PR=%s\n' "${{
98+ env.APPLY_FIXES_IF == 'true' &&
99+ env.APPLY_FIXES_MODE == 'pull_request'
100+ }}" >> "${GITHUB_ENV}"
101+ printf 'APPLY_FIXES_IF_COMMIT=%s\n' "${{
102+ env.APPLY_FIXES_IF == 'true' &&
103+ env.APPLY_FIXES_MODE == 'commit' &&
104+ (!contains(fromJSON('["refs/heads/main", "refs/heads/master"]'), github.ref))
105+ }}" >> "${GITHUB_ENV}"
106+
82107 - name : Prepare commit
83- 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')
108+ if : env.APPLY_FIXES_IF_COMMIT == 'true'
84109 run : sudo chown -Rc $UID .git/
110+
85111 - name : Commit and push applied linter fixes
86- 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')
87112 uses : stefanzweifel/git-auto-commit-action@778341af668090896ca464160c2def5d1d1a3eb0 # 6.0.1
113+ if : env.APPLY_FIXES_IF_COMMIT == 'true'
88114 with :
89- branch : ${{ github.event.pull_request.head.ref || github.head_ref || github.ref }}
115+ branch : >-
116+ ${{
117+ github.event.pull_request.head.ref ||
118+ github.head_ref ||
119+ github.ref
120+ }}
90121 commit_message : " [MegaLinter] Apply linters fixes"
91122 commit_user_name : newrelic-python-agent-team
92123 commit_user_email :
[email protected]
0 commit comments