|
| 1 | +--- |
| 2 | +name: MegaLinter |
| 3 | + |
| 4 | +on: |
| 5 | + workflow_call: |
| 6 | + inputs: |
| 7 | + GRAFANA_API_REPORTER_URL: |
| 8 | + type: string |
| 9 | + GRAFANA_API_REPORTER_METRICS_URL: |
| 10 | + type: string |
| 11 | + API_REPORTER_DEBUG: |
| 12 | + type: boolean |
| 13 | + default: false |
| 14 | + API_REPORTER: |
| 15 | + type: boolean |
| 16 | + default: false |
| 17 | + DEFAULT_BRANCH: |
| 18 | + type: string |
| 19 | + default: "main" |
| 20 | + APPLY_FIXES_IF_PR: |
| 21 | + type: boolean |
| 22 | + default: false |
| 23 | + RUNS_ON: |
| 24 | + type: string |
| 25 | + default: ubuntu-latest |
| 26 | + |
| 27 | + secrets: |
| 28 | + GRAFANA_API_REPORTER_BASIC_AUTH_USERNAME: |
| 29 | + required: false |
| 30 | + GRAFANA_API_REPORTER_TOKEN: |
| 31 | + required: false |
| 32 | + GRAFANA_API_REPORTER_METRICS_BASIC_AUTH_USERNAME: |
| 33 | + required: false |
| 34 | + |
| 35 | + |
| 36 | +# Comment env block if you do not want to apply fixes |
| 37 | +env: |
| 38 | + API_REPORTER: ${{ inputs.API_REPORTER }} |
| 39 | + API_REPORTER_URL: ${{ inputs.GRAFANA_API_REPORTER_URL }} |
| 40 | + API_REPORTER_BASIC_AUTH_USERNAME: ${{ secrets.GRAFANA_API_REPORTER_BASIC_AUTH_USERNAME }} |
| 41 | + API_REPORTER_BASIC_AUTH_PASSWORD: ${{ secrets.GRAFANA_API_REPORTER_TOKEN }} |
| 42 | + API_REPORTER_METRICS_URL: ${{ inputs.GRAFANA_API_REPORTER_METRICS_URL }} |
| 43 | + API_REPORTER_METRICS_BASIC_AUTH_USERNAME: ${{ secrets.GRAFANA_API_REPORTER_METRICS_BASIC_AUTH_USERNAME }} |
| 44 | + API_REPORTER_METRICS_BASIC_AUTH_PASSWORD: ${{ secrets.GRAFANA_API_REPORTER_TOKEN }} |
| 45 | + API_REPORTER_DEBUG: ${{ inputs.API_REPORTER_DEBUG }} |
| 46 | + SARIF_REPORTER: true |
| 47 | + APPLY_FIXES_IF_PR: ${{ inputs.APPLY_FIXES_IF_PR }} |
| 48 | + |
| 49 | +concurrency: |
| 50 | + group: ${{ github.ref }}-${{ github.workflow }} |
| 51 | + cancel-in-progress: true |
| 52 | + |
| 53 | +permissions: {} |
| 54 | + |
| 55 | +jobs: |
| 56 | + megalinter: |
| 57 | + name: MegaLinter |
| 58 | + runs-on: ${{ inputs.RUNS_ON }} |
| 59 | + |
| 60 | + # Give the default GITHUB_TOKEN write permission to commit and push, comment |
| 61 | + # issues & post new PR; remove the ones you do not need |
| 62 | + permissions: |
| 63 | + contents: write |
| 64 | + issues: write |
| 65 | + pull-requests: write |
| 66 | + security-events: write |
| 67 | + actions: read |
| 68 | + |
| 69 | + steps: |
| 70 | + # Git Checkout |
| 71 | + - name: Checkout Code |
| 72 | + uses: actions/checkout@v4 |
| 73 | + with: |
| 74 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 75 | + |
| 76 | + # If you use VALIDATE_ALL_CODEBASE = true, you can remove this line to |
| 77 | + # improve performance |
| 78 | + fetch-depth: 0 |
| 79 | + |
| 80 | + # MegaLinter |
| 81 | + - name: MegaLinter |
| 82 | + |
| 83 | + # You can override MegaLinter flavor used to have faster performances |
| 84 | + # More info at https://megalinter.io/latest/flavors/ |
| 85 | + uses: oxsecurity/megalinter@v8 |
| 86 | + |
| 87 | + id: ml |
| 88 | + |
| 89 | + # All available variables are described in documentation |
| 90 | + # https://megalinter.io/latest/configuration/ |
| 91 | + env: |
| 92 | + # Validates all source when push on main, else just the git diff with |
| 93 | + # main. Override with true if you always want to lint all sources |
| 94 | + # |
| 95 | + # To validate the entire codebase, set to: |
| 96 | + # VALIDATE_ALL_CODEBASE: true |
| 97 | + # |
| 98 | + # To validate only diff with main, set to: |
| 99 | + # VALIDATE_ALL_CODEBASE: >- |
| 100 | + # ${{ |
| 101 | + # github.event_name == 'push' && |
| 102 | + # contains(fromJSON('["refs/heads/main", "refs/heads/master"]'), github.ref) |
| 103 | + # }} |
| 104 | + VALIDATE_ALL_CODEBASE: >- |
| 105 | + ${{ |
| 106 | + github.event_name == 'push' && |
| 107 | + contains(fromJSON('["refs/heads/${{inputs.DEFAULT_BRANCH}}"]'), github.ref) |
| 108 | + }} |
| 109 | +
|
| 110 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 111 | + |
| 112 | + # ADD YOUR CUSTOM ENV VARIABLES HERE OR DEFINE THEM IN A FILE |
| 113 | + # .mega-linter.yml AT THE ROOT OF YOUR REPOSITORY |
| 114 | + |
| 115 | + # Uncomment to disable copy-paste and spell checks |
| 116 | + # DISABLE: COPYPASTE,SPELL |
| 117 | + |
| 118 | + # Upload MegaLinter artifacts |
| 119 | + - name: Archive production artifacts |
| 120 | + if: success() || failure() |
| 121 | + uses: actions/upload-artifact@v4 |
| 122 | + with: |
| 123 | + name: MegaLinter reports |
| 124 | + include-hidden-files: "true" |
| 125 | + path: | |
| 126 | + megalinter-reports |
| 127 | + mega-linter.log |
| 128 | +
|
| 129 | + # Set APPLY_FIXES_IF var for use in future steps |
| 130 | + - name: Set APPLY_FIXES_IF var |
| 131 | + run: | |
| 132 | + printf 'APPLY_FIXES_IF=%s\n' "${{ |
| 133 | + steps.ml.outputs.has_updated_sources == 1 && |
| 134 | + ( |
| 135 | + env.APPLY_FIXES_EVENT == 'all' || |
| 136 | + env.APPLY_FIXES_EVENT == github.event_name |
| 137 | + ) && |
| 138 | + ( |
| 139 | + github.event_name == 'push' || |
| 140 | + github.event.pull_request.head.repo.full_name == github.repository |
| 141 | + ) |
| 142 | + }}" >> "${GITHUB_ENV}" |
| 143 | +
|
| 144 | + # Set APPLY_FIXES_IF_* vars for use in future steps |
| 145 | + - name: Set APPLY_FIXES_IF_* vars |
| 146 | + run: | |
| 147 | + printf 'APPLY_FIXES_IF_PR=%s\n' "${{ |
| 148 | + env.APPLY_FIXES_IF == 'true' && |
| 149 | + env.APPLY_FIXES_MODE == 'pull_request' |
| 150 | + }}" >> "${GITHUB_ENV}" |
| 151 | + printf 'APPLY_FIXES_IF_COMMIT=%s\n' "${{ |
| 152 | + env.APPLY_FIXES_IF == 'true' && |
| 153 | + env.APPLY_FIXES_MODE == 'commit' && |
| 154 | + (!contains(fromJSON('["refs/heads/${{ inputs.DEFAULT_BRANCH }}"]'), github.ref)) |
| 155 | + }}" >> "${GITHUB_ENV}" |
| 156 | +
|
| 157 | + # Create pull request if applicable |
| 158 | + # (for now works only on PR from same repository, not from forks) |
| 159 | + - name: Create Pull Request with applied fixes |
| 160 | + uses: peter-evans/create-pull-request@v6 |
| 161 | + id: cpr |
| 162 | + if: env.APPLY_FIXES_IF_PR == 'true' |
| 163 | + with: |
| 164 | + token: ${{ secrets.PAT || secrets.GITHUB_TOKEN }} |
| 165 | + commit-message: "[MegaLinter] Apply linters automatic fixes" |
| 166 | + title: "[MegaLinter] Apply linters automatic fixes" |
| 167 | + labels: bot |
| 168 | + |
| 169 | + - name: Create PR output |
| 170 | + if: env.APPLY_FIXES_IF_PR == 'true' |
| 171 | + run: | |
| 172 | + echo "PR Number - ${{ steps.cpr.outputs.pull-request-number }}" |
| 173 | + echo "PR URL - ${{ steps.cpr.outputs.pull-request-url }}" |
| 174 | +
|
| 175 | + # Push new commit if applicable |
| 176 | + # (for now works only on PR from same repository, not from forks) |
| 177 | + - name: Prepare commit |
| 178 | + if: env.APPLY_FIXES_IF_COMMIT == 'true' |
| 179 | + run: sudo chown -Rc $UID .git/ |
| 180 | + |
| 181 | + - name: Commit and push applied linter fixes |
| 182 | + uses: stefanzweifel/git-auto-commit-action@v4 |
| 183 | + if: env.APPLY_FIXES_IF_COMMIT == 'true' |
| 184 | + with: |
| 185 | + branch: >- |
| 186 | + ${{ |
| 187 | + github.event.pull_request.head.ref || |
| 188 | + github.head_ref || |
| 189 | + github.ref |
| 190 | + }} |
| 191 | + commit_message: "[MegaLinter] Apply linters fixes" |
| 192 | + commit_user_name: megalinter-bot |
| 193 | + commit_user_email: 129584137+megalinter-bot@users.noreply.github.com |
| 194 | + |
| 195 | + - name: Upload MegaLinter scan results to GitHub Security tab |
| 196 | + if: success() || failure() |
| 197 | + uses: github/codeql-action/upload-sarif@v3 |
| 198 | + with: |
| 199 | + sarif_file: 'megalinter-reports/megalinter-report.sarif' |
| 200 | + category: mega linter |
0 commit comments