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