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