|
1 | | ---- |
2 | 1 | # MegaLinter GitHub Action configuration file |
3 | 2 | # More info at https://megalinter.io |
4 | | -name: MegaLinter for mega-linter-runner |
| 3 | +--- |
| 4 | +name: MegaLinter for mega-linter-runner # ml workflow change |
5 | 5 |
|
6 | | -# Start lint on any push and on pull requests |
| 6 | +# Trigger mega-linter at every push. Action will also be visible from Pull |
| 7 | +# Requests to main |
7 | 8 | on: |
8 | | - # Trigger mega-linter at every push. Action will also be visible from Pull Requests to master |
9 | | - push: # Comment this line to trigger action only on pull-requests (not recommended if you don't pay for GH Actions) |
| 9 | + # Comment this line to trigger action only on pull-requests |
| 10 | + # (not recommended if you don't pay for GH Actions) |
| 11 | + push: |
| 12 | + |
10 | 13 | pull_request: |
11 | | - branches: [master, main, alpha] |
| 14 | + branches: |
| 15 | + - main |
| 16 | + - master |
| 17 | + - alpha # ml workflow addition |
12 | 18 |
|
13 | | -env: # Comment env block if you do not want to apply fixes |
| 19 | +# Comment env block if you do not want to apply fixes |
| 20 | +env: |
14 | 21 | # Apply linter fixes configuration |
15 | | - APPLY_FIXES: all # When active, APPLY_FIXES must also be defined as environment variable (in github/workflows/mega-linter.yml or other CI tool) |
16 | | - APPLY_FIXES_EVENT: pull_request # Decide which event triggers application of fixes in a commit or a PR (pull_request, push, all) |
17 | | - APPLY_FIXES_MODE: commit # If APPLY_FIXES is used, defines if the fixes are directly committed (commit) or posted in a PR (pull_request) |
| 22 | + # |
| 23 | + # When active, APPLY_FIXES must also be defined as environment variable |
| 24 | + # (in github/workflows/mega-linter.yml or other CI tool) |
| 25 | + APPLY_FIXES: all |
| 26 | + |
| 27 | + # Decide which event triggers application of fixes in a commit or a PR |
| 28 | + # (pull_request, push, all) |
| 29 | + APPLY_FIXES_EVENT: pull_request |
| 30 | + |
| 31 | + # If APPLY_FIXES is used, defines if the fixes are directly committed (commit) |
| 32 | + # or posted in a PR (pull_request) |
| 33 | + APPLY_FIXES_MODE: commit |
18 | 34 |
|
19 | 35 | concurrency: |
20 | 36 | group: ${{ github.ref }}-${{ github.workflow }} |
21 | 37 | cancel-in-progress: true |
22 | 38 |
|
23 | 39 | jobs: |
24 | | - build: |
| 40 | + megalinter: |
25 | 41 | name: MegaLinter |
26 | 42 | runs-on: ubuntu-latest |
| 43 | + |
| 44 | + # Give the default GITHUB_TOKEN write permission to commit and push, comment |
| 45 | + # issues & post new PR; remove the ones you do not need |
27 | 46 | permissions: |
28 | | - # Give the default GITHUB_TOKEN write permission to commit and push, comment issues & post new PR |
29 | | - # Remove the ones you do not need |
30 | 47 | contents: write |
31 | 48 | issues: write |
32 | 49 | pull-requests: write |
33 | | - environment: |
34 | | - name: dev |
| 50 | + environment: # ml workflow addition |
| 51 | + name: dev # ml workflow addition |
| 52 | + |
35 | 53 | steps: |
| 54 | + |
| 55 | + # Git Checkout |
36 | 56 | - name: Checkout Code |
37 | 57 | uses: actions/checkout@v4 |
38 | 58 | with: |
39 | 59 | token: ${{ secrets.PAT || secrets.GITHUB_TOKEN }} |
| 60 | + |
| 61 | + # If you use VALIDATE_ALL_CODEBASE = true, you can remove this line to |
| 62 | + # improve performance |
40 | 63 | fetch-depth: 0 |
41 | 64 |
|
42 | 65 | # MegaLinter |
43 | 66 | - name: MegaLinter |
44 | | - id: ml |
| 67 | + |
45 | 68 | # You can override MegaLinter flavor used to have faster performances |
46 | 69 | # More info at https://megalinter.io/flavors/ |
47 | | - uses: oxsecurity/megalinter/flavors/javascript@beta |
| 70 | + uses: oxsecurity/megalinter/flavors/javascript@beta # ml workflow change |
| 71 | + |
| 72 | + id: ml |
| 73 | + |
| 74 | + # All available variables are described in documentation |
| 75 | + # https://megalinter.io/configuration/ |
48 | 76 | env: |
49 | | - # All available variables are described in documentation |
50 | | - # https://megalinter.io/configuration/#shared-variables |
51 | | - # ADD YOUR CUSTOM ENV VARIABLES HERE OR DEFINE THEM IN A FILE .mega-linter.yml AT THE ROOT OF YOUR REPOSITORY |
52 | | - DEFAULT_WORKSPACE: mega-linter-runner |
53 | | - VALIDATE_ALL_CODEBASE: true # ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }} # Validates all source when push on main, else just the git diff with main. Override with true if you always want to lint all sources |
| 77 | + DEFAULT_WORKSPACE: mega-linter-runner # ml workflow addition |
| 78 | + |
| 79 | + # Validates all source when push on main, else just the git diff with |
| 80 | + # main. Override with true if you always want to lint all sources |
| 81 | + # |
| 82 | + # To validate the entire codebase, set to: |
| 83 | + # VALIDATE_ALL_CODEBASE: true |
| 84 | + # |
| 85 | + # To validate only diff with main, set to: |
| 86 | + # VALIDATE_ALL_CODEBASE: >- |
| 87 | + # ${{ |
| 88 | + # github.event_name == 'push' && |
| 89 | + # contains(fromJSON('["refs/heads/main", "refs/heads/master"]'), github.ref) |
| 90 | + # }} |
| 91 | + VALIDATE_ALL_CODEBASE: true # ml workflow change |
| 92 | + # >- |
| 93 | + # ${{ |
| 94 | + # github.event_name == 'push' && |
| 95 | + # contains(fromJSON('["refs/heads/main", "refs/heads/master"]'), github.ref) |
| 96 | + # }} |
| 97 | + |
54 | 98 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
55 | 99 |
|
| 100 | + # ADD YOUR CUSTOM ENV VARIABLES HERE OR DEFINE THEM IN A FILE |
| 101 | + # .mega-linter.yml AT THE ROOT OF YOUR REPOSITORY |
| 102 | + |
| 103 | + # Uncomment to disable copy-paste and spell checks |
| 104 | + # DISABLE: COPYPASTE,SPELL |
| 105 | + |
56 | 106 | # Upload MegaLinter artifacts |
57 | 107 | - name: Archive production artifacts |
58 | | - if: ${{ success() }} || ${{ failure() }} |
59 | 108 | uses: actions/upload-artifact@v3 |
| 109 | + if: ${{ success() }} || ${{ failure() }} |
60 | 110 | with: |
61 | 111 | name: MegaLinter reports |
62 | 112 | path: | |
63 | 113 | megalinter-reports |
64 | 114 | mega-linter.log |
65 | 115 |
|
66 | | - # Create pull request if applicable (for now works only on PR from same repository, not from forks) |
| 116 | + # Set APPLY_FIXES_IF var for use in future steps |
| 117 | + - name: Set APPLY_FIXES_IF var |
| 118 | + run: | |
| 119 | + printf 'APPLY_FIXES_IF=%s\n' "${{ |
| 120 | + steps.ml.outputs.has_updated_sources == 1 && |
| 121 | + ( |
| 122 | + env.APPLY_FIXES_EVENT == 'all' || |
| 123 | + env.APPLY_FIXES_EVENT == github.event_name |
| 124 | + ) && |
| 125 | + ( |
| 126 | + github.event_name == 'push' || |
| 127 | + github.event.pull_request.head.repo.full_name == github.repository |
| 128 | + ) |
| 129 | + }}" >> "${GITHUB_ENV}" |
| 130 | +
|
| 131 | + # Set APPLY_FIXES_IF_* vars for use in future steps |
| 132 | + - name: Set APPLY_FIXES_IF_* vars |
| 133 | + run: | |
| 134 | + printf 'APPLY_FIXES_IF_PR=%s\n' "${{ |
| 135 | + env.APPLY_FIXES_IF == 'true' && |
| 136 | + env.APPLY_FIXES_MODE == 'pull_request' |
| 137 | + }}" >> "${GITHUB_ENV}" |
| 138 | + printf 'APPLY_FIXES_IF_COMMIT=%s\n' "${{ |
| 139 | + env.APPLY_FIXES_IF == 'true' && |
| 140 | + env.APPLY_FIXES_MODE == 'commit' && |
| 141 | + (!contains(fromJSON('["refs/heads/main", "refs/heads/master"]'), github.ref)) |
| 142 | + }}" >> "${GITHUB_ENV}" |
| 143 | +
|
| 144 | + # Create pull request if applicable |
| 145 | + # (for now works only on PR from same repository, not from forks) |
67 | 146 | - name: Create Pull Request with applied fixes |
68 | | - id: cpr |
69 | | - 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') |
70 | 147 | uses: peter-evans/create-pull-request@v5 |
| 148 | + id: cpr |
| 149 | + if: env.APPLY_FIXES_IF_PR == 'true' |
71 | 150 | with: |
72 | 151 | token: ${{ secrets.PAT || secrets.GITHUB_TOKEN }} |
73 | 152 | commit-message: "[MegaLinter] Apply linters automatic fixes" |
74 | 153 | title: "[MegaLinter] Apply linters automatic fixes" |
75 | 154 | labels: bot |
| 155 | + |
76 | 156 | - name: Create PR output |
77 | | - 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') |
| 157 | + if: env.APPLY_FIXES_IF_PR == 'true' |
78 | 158 | run: | |
79 | | - echo "Pull Request Number - ${{ steps.cpr.outputs.pull-request-number }}" |
80 | | - echo "Pull Request URL - ${{ steps.cpr.outputs.pull-request-url }}" |
| 159 | + echo "PR Number - ${{ steps.cpr.outputs.pull-request-number }}" |
| 160 | + echo "PR URL - ${{ steps.cpr.outputs.pull-request-url }}" |
81 | 161 |
|
82 | | - # Push new commit if applicable (for now works only on PR from same repository, not from forks) |
| 162 | + # Push new commit if applicable |
| 163 | + # (for now works only on PR from same repository, not from forks) |
83 | 164 | - name: Prepare commit |
84 | | - 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') |
| 165 | + if: env.APPLY_FIXES_IF_COMMIT == 'true' |
85 | 166 | run: sudo chown -Rc $UID .git/ |
| 167 | + |
86 | 168 | - name: Commit and push applied linter fixes |
87 | | - 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') |
88 | 169 | uses: stefanzweifel/git-auto-commit-action@v5 |
| 170 | + if: env.APPLY_FIXES_IF_COMMIT == 'true' |
89 | 171 | with: |
90 | | - branch: ${{ github.event.pull_request.head.ref || github.head_ref || github.ref }} |
| 172 | + branch: >- |
| 173 | + ${{ |
| 174 | + github.event.pull_request.head.ref || |
| 175 | + github.head_ref || |
| 176 | + github.ref |
| 177 | + }} |
91 | 178 | commit_message: "[MegaLinter] Apply linters fixes" |
92 | 179 | commit_user_name: megalinter-bot |
93 | 180 | commit_user_email: [email protected] |
0 commit comments