|
| 1 | +name: Lint with MegaLinter & Create PR |
| 2 | +on: # yamllint disable-line rule:truthy - false positive |
| 3 | + push: |
| 4 | + branches: [lint-create-pr] |
| 5 | + pull_request: |
| 6 | + branches: [main, master, lint-create-pr] |
| 7 | +env: |
| 8 | + APPLY_FIXES: all |
| 9 | + APPLY_FIXES_EVENT: all |
| 10 | + APPLY_FIXES_MODE: pull_request |
| 11 | + APPLY_FIXES_IF_PR: "true" |
| 12 | + APPLY_FIXES_IF_COMMIT: "true" |
| 13 | + ENABLE: MARKDOWN,YAML,TERRAFORM |
| 14 | + DISABLE_LINTERS: MARKDOWN_MARKDOWN_TABLE_FORMATTER,YAML_PRETTIER,YAML_V8R,TERRAFORM_TFLINT,TERRAFORM_TERRASCAN |
| 15 | +concurrency: |
| 16 | + group: ${{ github.ref }}-${{ github.workflow }} |
| 17 | + cancel-in-progress: true |
| 18 | +permissions: {} |
| 19 | +jobs: |
| 20 | + megalinter: |
| 21 | + name: MegaLinter |
| 22 | + runs-on: ubuntu-latest |
| 23 | + permissions: |
| 24 | + contents: write |
| 25 | + issues: write |
| 26 | + pull-requests: write |
| 27 | + steps: |
| 28 | + - name: Checkout Code |
| 29 | + uses: actions/checkout@v5 |
| 30 | + - name: MegaLinter |
| 31 | + uses: oxsecurity/megalinter/flavors/terraform@v9.1.0 |
| 32 | + id: ml |
| 33 | + env: |
| 34 | + VALIDATE_ALL_CODEBASE: true |
| 35 | + FLAVOR_SUGGESTIONS: false |
| 36 | + MARKDOWN_MARKDOWNLINT_AUTO_FIX: true |
| 37 | + TERRAFORM_TERRAFORM_FMT_AUTO_FIX: true |
| 38 | + YAML_YAMLLINT_AUTO_FIX: true |
| 39 | + - name: Archive production artifacts |
| 40 | + if: success() || failure() |
| 41 | + uses: actions/upload-artifact@v4 |
| 42 | + with: |
| 43 | + name: MegaLinter reports |
| 44 | + include-hidden-files: "true" |
| 45 | + path: | |
| 46 | + megalinter-reports |
| 47 | + mega-linter.log |
| 48 | + - name: Set APPLY_FIXES_IF var |
| 49 | + if: always() |
| 50 | + run: | |
| 51 | + printf 'APPLY_FIXES_IF=%s\n' "${{ |
| 52 | + steps.ml.outputs.has_updated_sources == 1 && |
| 53 | + ( |
| 54 | + env.APPLY_FIXES_EVENT == 'all' || |
| 55 | + env.APPLY_FIXES_EVENT == github.event_name |
| 56 | + ) && |
| 57 | + ( |
| 58 | + github.event_name == 'push' || |
| 59 | + github.event.pull_request.head.repo.full_name == github.repository |
| 60 | + ) |
| 61 | + }}" >> "${GITHUB_ENV}" |
| 62 | + - name: Set APPLY_FIXES_IF_* vars |
| 63 | + if: always() |
| 64 | + run: | |
| 65 | + printf 'APPLY_FIXES_IF_PR=%s\n' "${{ |
| 66 | + env.APPLY_FIXES_IF == 'true' && |
| 67 | + env.APPLY_FIXES_MODE == 'pull_request' |
| 68 | + }}" >> "${GITHUB_ENV}" |
| 69 | + printf 'APPLY_FIXES_IF_COMMIT=%s\n' "${{ |
| 70 | + env.APPLY_FIXES_IF == 'true' && |
| 71 | + env.APPLY_FIXES_MODE == 'commit' && |
| 72 | + (!contains(fromJSON('["refs/heads/main", "refs/heads/master"]'), github.ref)) |
| 73 | + }}" >> "${GITHUB_ENV}" |
| 74 | + - name: Create Pull Request with applied fixes |
| 75 | + uses: peter-evans/create-pull-request@v7 |
| 76 | + id: cpr |
| 77 | + if: env.APPLY_FIXES_IF_PR == 'true' |
| 78 | + with: |
| 79 | + commit-message: "apply linters automatic fixes" |
| 80 | + title: "[DEMO] Apply linters automatic fixes" |
| 81 | + body: THIS IS AN AUTOMATED PR TO APPLY THE FIXES SUGGESTED BY MEGALINTER. PLEASE DO NOT REVIEW OR MERGE IT MANUALLY. |
| 82 | + labels: auto-lint-fixes, automated-pr, do-not-review, do-not-merge |
| 83 | + - name: Create PR output |
| 84 | + if: always() |
| 85 | + run: | |
| 86 | + echo "PR Number - ${{ steps.cpr.outputs.pull-request-number }}" |
| 87 | + echo "PR URL - ${{ steps.cpr.outputs.pull-request-url }}" |
0 commit comments