@@ -17,8 +17,13 @@ on: # yamllint disable-line rule:truthy
1717env : # Comment env block if you do not want to apply fixes
1818 # Apply linter fixes configuration
1919 APPLY_FIXES : all # When active, APPLY_FIXES must also be defined as environment variable (in github/workflows/mega-linter.yml or other CI tool)
20- APPLY_FIXES_EVENT : pull_request # Decide which event triggers application of fixes in a commit or a PR (pull_request, push, all)
21- APPLY_FIXES_MODE : commit # If APPLY_FIXES is used, defines if the fixes are directly committed (commit) or posted in a PR (pull_request)
20+ APPLY_FIXES_EVENT : push # Decide which event triggers application of fixes in a commit or a PR (pull_request, push, all)
21+ # I tried around a lot to make the test workflow run on pull_request events,
22+ # but it it only worked when creating a new PR. By default, this would target the branch of the PR
23+ # and not the main branch. Instead of trying around to cherry-pick the commits from the PR
24+ # etc. I decided to just run the workflow on push events to the main branch and then create
25+ # a PR targeting the main branch.
26+ APPLY_FIXES_MODE : pull_request # If APPLY_FIXES is used, defines if the fixes are directly committed (commit) or posted in a PR (pull_request)
2227
2328concurrency :
2429 group : ${{ github.ref }}-${{ github.workflow }}
@@ -28,15 +33,18 @@ jobs:
2833 build :
2934 name : MegaLinter
3035 runs-on : ubuntu-latest
31-
3236 permissions :
33- checks : write
34- pull-requests : write
37+ # Give the default GITHUB_TOKEN write permission to commit and push, comment issues & post new PR
38+ # Remove the ones you do not need
3539 contents : write
36-
40+ issues : write
41+ pull-requests : write
3742 steps :
38- - name : Check out repository
43+ - name : Checkout Code
3944 uses : actions/checkout@v4
45+ with :
46+ ref : ${{ github.head_ref }}
47+ fetch-depth : 0
4048
4149 - name : Create alpine-wheels folder
4250 run : mkdir alpine-wheels
@@ -179,18 +187,22 @@ jobs:
179187 megalinter-reports
180188 mega-linter.log
181189
182- # Create pull request if applicable (for now works only on PR from same repository, not from forks)
190+ # Create Pull Request step
183191 - name : Create Pull Request with applied fixes
184192 id : cpr
185- 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')
193+ if : github.ref == 'refs/heads/main' && 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')
186194 uses : peter-evans/create-pull-request@v5
187195 with :
188196 token : ${{ secrets.PAT || secrets.GITHUB_TOKEN }}
189197 commit-message : " [MegaLinter] Apply linters automatic fixes"
190198 title : " [MegaLinter] Apply linters automatic fixes"
199+ branch : megalinter-fixes
191200 labels : bot
201+ base : main
202+
203+ # Output PR details
192204 - name : Create PR output
193- 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')
205+ if : github.ref == 'refs/heads/main' && 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')
194206 run : |
195207 echo "Pull Request Number - ${{ steps.cpr.outputs.pull-request-number }}"
196208 echo "Pull Request URL - ${{ steps.cpr.outputs.pull-request-url }}"
@@ -206,4 +218,4 @@ jobs:
206218 branch : ${{ github.event.pull_request.head.ref || github.head_ref || github.ref }}
207219 commit_message : " [MegaLinter] Apply linters fixes"
208220 commit_user_name : megalinter-bot
209- commit_user_email : megalinter-bot@iar.kit.edu
221+ commit_user_email : megalinter-bot@iar.kit.edu
0 commit comments