|
| 1 | +# MegaLinter GitHub Action configuration file |
| 2 | +# More info at https://megalinter.io |
| 3 | +# https://github.com/oxsecurity/megalinter/blob/main/TEMPLATES/mega-linter.yml |
| 4 | +--- |
| 5 | +name: MegaLinter |
| 6 | +run-name: >- |
| 7 | + ${{ |
| 8 | + format( |
| 9 | + '{0} - MegaLinter{1}', |
| 10 | + github.event_name == 'pull_request' |
| 11 | + && format('PR#{0}{1}', github.event.number, github.event.pull_request.draft && ' [DRAFT]' || '') |
| 12 | + || format('Push [{0}]', github.ref_name), |
| 13 | + github.event_name == 'pull_request' |
| 14 | + && format(' - [{0}-to-{1}]', github.event.pull_request.head.ref, github.event.pull_request.base.ref) |
| 15 | + || '' |
| 16 | + ) |
| 17 | + }} |
| 18 | +
|
| 19 | +on: |
| 20 | + push: |
| 21 | + branches: |
| 22 | + - main |
| 23 | + pull_request: |
| 24 | + branches: |
| 25 | + - main |
| 26 | + pull_request_target: |
| 27 | + types: |
| 28 | + - edited |
| 29 | + branches: |
| 30 | + - main |
| 31 | + |
| 32 | +concurrency: |
| 33 | + group: MegaLinter-${{ github.ref_name }} |
| 34 | + cancel-in-progress: true |
| 35 | + |
| 36 | +jobs: |
| 37 | + megalinter: |
| 38 | + name: MegaLinter |
| 39 | + runs-on: ubuntu-latest |
| 40 | + |
| 41 | + # Give the default GITHUB_TOKEN write permission to commit and push, comment |
| 42 | + # issues & post new PR; remove the ones you do not need |
| 43 | + permissions: |
| 44 | + contents: write |
| 45 | + issues: write |
| 46 | + pull-requests: write |
| 47 | + |
| 48 | + steps: |
| 49 | + - name: Checkout Code |
| 50 | + uses: actions/checkout@v4 |
| 51 | + with: |
| 52 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 53 | + fetch-depth: 0 |
| 54 | + |
| 55 | + - name: MegaLinter |
| 56 | + uses: oxsecurity/megalinter@v8 |
| 57 | + id: megalinter |
| 58 | + env: |
| 59 | + CONFIG_FILE: .mega-linter.yml |
| 60 | + # Only validate the whole codebase on push to main |
| 61 | + VALIDATE_ALL_CODEBASE: >- |
| 62 | + ${{ |
| 63 | + github.event_name == 'push' && |
| 64 | + contains(fromJSON('["refs/heads/main"]'), github.ref) |
| 65 | + }} |
| 66 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 67 | + |
| 68 | + # Upload MegaLinter artifacts |
| 69 | + - name: Archive production artifacts |
| 70 | + uses: actions/upload-artifact@v4 |
| 71 | + if: success() || failure() |
| 72 | + with: |
| 73 | + name: MegaLinter reports |
| 74 | + path: | |
| 75 | + megalinter-reports |
| 76 | + mega-linter.log |
| 77 | +
|
| 78 | + # Delete MegaLinter reports before creating PR |
| 79 | + - name: Delete MegaLinter Reports |
| 80 | + if: ${{ (success() || failure()) && steps.megalinter.outputs.has_updated_sources == 1 }} |
| 81 | + run: | |
| 82 | + sudo rm -rf megalinter-reports |
| 83 | + sudo rm -f mega-linter.log |
| 84 | +
|
| 85 | + # Create pull request if applicable |
| 86 | + - name: Create Pull Request with applied fixes [${{ steps.megalinter.outputs.has_updated_sources }}] |
| 87 | + uses: peter-evans/create-pull-request@v6 |
| 88 | + id: create-pr |
| 89 | + if: ${{ (success() || failure()) && steps.megalinter.outputs.has_updated_sources == 1 }} |
| 90 | + with: |
| 91 | + token: ${{ secrets.TJC_TOKEN || secrets.GITHUB_TOKEN }} |
| 92 | + base: ${{ github.event.pull_request.head.ref }} |
| 93 | + branch: MegaLinter-${{ github.event.pull_request.head.ref }} |
| 94 | + branch-suffix: short-commit-hash |
| 95 | + title: "🧹 chore: [MegaLinter] Apply [${{ steps.megalinter.outputs.has_updated_sources }}] automatic fixes" |
| 96 | + commit-message: "🧹 chore: [MegaLinter] Apply [${{ steps.megalinter.outputs.has_updated_sources }}] automatic fixes" |
| 97 | + body: >- |
| 98 | + ${{ |
| 99 | + format( |
| 100 | + '[MegaLinter](.github/workflows/mega-linter.yml) - Merge [{0}] {1} for {2}', |
| 101 | + steps.megalinter.outputs.has_updated_sources, |
| 102 | + steps.megalinter.outputs.has_updated_sources == 1 && 'fix' || 'fixes', |
| 103 | + github.event_name == 'pull_request' |
| 104 | + && format('PR #{0}', github.event.pull_request.number) |
| 105 | + || format('Push to [{0}]', github.ref_name) |
| 106 | + ) |
| 107 | + }} |
| 108 | + assignees: TylerCarrol |
| 109 | + labels: bot,linter |
| 110 | + |
| 111 | + - name: Create PR output |
| 112 | + if: ${{ (success() || failure()) && steps.megalinter.outputs.has_updated_sources == 1 }} |
| 113 | + run: | |
| 114 | + echo "PR Number - ${{ steps.create-pr.outputs.pull-request-number }}" |
| 115 | + echo "PR URL - ${{ steps.create-pr.outputs.pull-request-url }}" |
0 commit comments