|
| 1 | +name: Lint |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + branches: [main] |
| 6 | + |
| 7 | +permissions: read-all |
| 8 | + |
| 9 | +env: |
| 10 | + APPLY_FIXES: all |
| 11 | + APPLY_FIXES_EVENT: pull_request |
| 12 | + APPLY_FIXES_MODE: commit |
| 13 | + |
| 14 | +concurrency: |
| 15 | + group: ${{ github.ref }}-${{ github.workflow }} |
| 16 | + cancel-in-progress: true |
| 17 | + |
| 18 | +jobs: |
| 19 | + lint: |
| 20 | + name: Lint |
| 21 | + runs-on: ubuntu-22.04 |
| 22 | + permissions: |
| 23 | + checks: write |
| 24 | + pull-requests: write |
| 25 | + |
| 26 | + steps: |
| 27 | + - name: Checkout repo |
| 28 | + uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c |
| 29 | + with: |
| 30 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 31 | + fetch-depth: 0 |
| 32 | + |
| 33 | + - name: Lint |
| 34 | + id: ml |
| 35 | + uses: oxsecurity/megalinter@c1612a7969ca083ca64ea4d55fe174ec7ea54740 |
| 36 | + env: |
| 37 | + VALIDATE_ALL_CODEBASE: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }} |
| 38 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 39 | + |
| 40 | + - name: Upload report |
| 41 | + if: ${{ success() }} || ${{ failure() }} |
| 42 | + uses: actions/upload-artifact@0b7f8abb1508181956e8e162db84b466c27e18ce |
| 43 | + with: |
| 44 | + name: Lint Report |
| 45 | + path: | |
| 46 | + megalinter-reports |
| 47 | + mega-linter.log |
| 48 | +
|
| 49 | + - name: Create pull request with applied fixes |
| 50 | + id: cpr |
| 51 | + 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') |
| 52 | + uses: peter-evans/create-pull-request@2b011faafdcbc9ceb11414d64d0573f37c774b04 |
| 53 | + with: |
| 54 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 55 | + commit-message: "Apply lint fixes" |
| 56 | + title: "Apply lint fixes" |
| 57 | + labels: bot |
| 58 | + - name: Output pull request |
| 59 | + 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') |
| 60 | + run: | |
| 61 | + echo "PR: ${{ steps.cpr.outputs.pull-request-number }}" |
| 62 | + echo "PR URL: ${{ steps.cpr.outputs.pull-request-url }}" |
| 63 | +
|
| 64 | + - name: Prepare commit |
| 65 | + 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') |
| 66 | + run: sudo chown -Rc $UID .git/ |
| 67 | + - name: Commit and push applied lint fixes |
| 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 == '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') |
| 69 | + uses: stefanzweifel/git-auto-commit-action@3ea6ae190baf489ba007f7c92608f33ce20ef04a |
| 70 | + with: |
| 71 | + branch: ${{ github.event.pull_request.head.ref || github.head_ref || github.ref }} |
| 72 | + commit_message: "Apply lint fixes" |
0 commit comments