|
| 1 | +--- |
| 2 | +# MegaLinter GitHub Action configuration file |
| 3 | +# More info at https://megalinter.io |
| 4 | +name: MegaLinter |
| 5 | + |
| 6 | +on: |
| 7 | + push: |
| 8 | + branches: |
| 9 | + - "**" |
| 10 | + |
| 11 | +env: # Comment env block if you do not want to apply fixes |
| 12 | + # Apply linter fixes configuration |
| 13 | + APPLY_FIXES: all # When active, APPLY_FIXES must also be defined as environment variable (in github/workflows/mega-linter.yml or other CI tool) |
| 14 | + APPLY_FIXES_EVENT: all # Decide which event triggers application of fixes in a commit or a PR (pull_request, push, all) |
| 15 | + 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) |
| 16 | + |
| 17 | +concurrency: |
| 18 | + group: ${{ github.ref }}-${{ github.workflow }} |
| 19 | + cancel-in-progress: true |
| 20 | + |
| 21 | +jobs: |
| 22 | + build: |
| 23 | + name: MegaLinter |
| 24 | + runs-on: ubuntu-latest |
| 25 | + permissions: |
| 26 | + # Give the default GITHUB_TOKEN write permission to commit and push, comment issues & post new PR |
| 27 | + # Remove the ones you do not need |
| 28 | + contents: write |
| 29 | + issues: write |
| 30 | + pull-requests: write |
| 31 | + steps: |
| 32 | + # Git Checkout |
| 33 | + - name: Checkout Code |
| 34 | + uses: actions/checkout@v3 |
| 35 | + with: |
| 36 | + token: ${{ secrets.PAT || secrets.GITHUB_TOKEN }} |
| 37 | + fetch-depth: 0 # If you use VALIDATE_ALL_CODEBASE = true, you can remove this line to improve performances |
| 38 | + |
| 39 | + # MegaLinter |
| 40 | + - name: MegaLinter |
| 41 | + id: ml |
| 42 | + # You can override MegaLinter flavor used to have faster performances |
| 43 | + # More info at https://megalinter.io/flavors/ |
| 44 | + uses: oxsecurity/megalinter@beta |
| 45 | + env: |
| 46 | + # All available variables are described in documentation |
| 47 | + # https://megalinter.io/configuration/ |
| 48 | + VALIDATE_ALL_CODEBASE: true |
| 49 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 50 | + # ADD YOUR CUSTOM ENV VARIABLES HERE TO OVERRIDE VALUES OF .mega-linter.yml AT THE ROOT OF YOUR REPOSITORY |
| 51 | + APPLY_FIXES: all |
| 52 | + DISABLE_ERRORS: true # Uncomment if you want MegaLinter to detect errors but not block CI to pass |
| 53 | + |
| 54 | + # Upload MegaLinter artifacts |
| 55 | + - name: Archive production artifacts |
| 56 | + if: ${{ success() }} || ${{ failure() }} |
| 57 | + uses: actions/upload-artifact@v3 |
| 58 | + with: |
| 59 | + name: MegaLinter reports |
| 60 | + path: | |
| 61 | + megalinter-reports |
| 62 | + mega-linter.log |
| 63 | +
|
| 64 | + # Create pull request if applicable (for now works only on PR from same repository, not from forks) |
| 65 | + - name: Create Pull Request with applied fixes |
| 66 | + id: cpr |
| 67 | + 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') |
| 68 | + uses: peter-evans/create-pull-request@v5 |
| 69 | + with: |
| 70 | + token: ${{ secrets.PAT || secrets.GITHUB_TOKEN }} |
| 71 | + commit-message: "[MegaLinter] Apply linters automatic fixes" |
| 72 | + title: "[MegaLinter] Apply linters automatic fixes" |
| 73 | + labels: bot |
| 74 | + - name: Create PR output |
| 75 | + 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') |
| 76 | + run: | |
| 77 | + echo "Pull Request Number - ${{ steps.cpr.outputs.pull-request-number }}" |
| 78 | + echo "Pull Request URL - ${{ steps.cpr.outputs.pull-request-url }}" |
| 79 | +
|
| 80 | + # Push new commit if applicable (for now works only on PR from same repository, not from forks) |
| 81 | + - name: Prepare commit |
| 82 | + 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') |
| 83 | + run: sudo chown -Rc $UID .git/ |
| 84 | + - name: Commit and push applied linter fixes |
| 85 | + 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') |
| 86 | + uses: stefanzweifel/git-auto-commit-action@v4 |
| 87 | + with: |
| 88 | + branch: ${{ github.event.pull_request.head.ref || github.head_ref || github.ref }} |
| 89 | + commit_message: "[MegaLinter] Apply linters fixes" |
| 90 | + commit_user_name: megalinter-bot |
| 91 | + commit_user_email: [email protected] |
0 commit comments