|
| 1 | +# Copyright 2010 New Relic, Inc. |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | + |
| 15 | +--- |
| 16 | +# MegaLinter GitHub Action configuration file |
| 17 | +# More info at https://megalinter.io |
| 18 | +name: MegaLinter |
| 19 | + |
| 20 | +on: |
| 21 | + # Trigger mega-linter at every push. Action will also be visible from Pull Requests to main |
| 22 | + # push: # Comment this line to trigger action only on pull-requests (not recommended if you don't pay for GH Actions) |
| 23 | + pull_request: |
| 24 | + |
| 25 | +env: # Comment env block if you don't want to apply fixes |
| 26 | + # Apply linter fixes configuration |
| 27 | + APPLY_FIXES: all # When active, APPLY_FIXES must also be defined as environment variable (in github/workflows/mega-linter.yml or other CI tool) |
| 28 | + APPLY_FIXES_EVENT: pull_request # Decide which event triggers application of fixes in a commit or a PR (pull_request, push, all) |
| 29 | + APPLY_FIXES_MODE: commit # If APPLY_FIXES is used, defines if the fixes are directly committed (commit) or posted in a PR (pull_request) |
| 30 | + |
| 31 | +concurrency: |
| 32 | + group: ${{ github.ref || github.run_id }}-${{ github.workflow }} |
| 33 | + cancel-in-progress: true |
| 34 | + |
| 35 | +jobs: |
| 36 | + megalinter: |
| 37 | + name: MegaLinter |
| 38 | + runs-on: ubuntu-latest |
| 39 | + permissions: |
| 40 | + # Give the default GITHUB_TOKEN write permission to commit and push, comment issues & post new PR |
| 41 | + # Remove the ones you do not need |
| 42 | + contents: write |
| 43 | + issues: write |
| 44 | + pull-requests: write |
| 45 | + steps: |
| 46 | + # Git Checkout |
| 47 | + - name: Checkout Code |
| 48 | + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # 4.2.2 |
| 49 | + with: |
| 50 | + token: ${{ secrets.PAT || secrets.GITHUB_TOKEN }} |
| 51 | + |
| 52 | + # MegaLinter |
| 53 | + - name: MegaLinter |
| 54 | + id: ml |
| 55 | + # You can override MegaLinter flavor used to have faster performances |
| 56 | + # More info at https://megalinter.io/flavors/ |
| 57 | + uses: oxsecurity/megalinter/flavors/python@146333030da68e2e58c6ff826633824fabe01eaf # 8.5.0 |
| 58 | + env: |
| 59 | + # All available variables are described in documentation |
| 60 | + # https://megalinter.io/configuration/ |
| 61 | + VALIDATE_ALL_CODEBASE: "true" |
| 62 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 63 | + # ADD YOUR CUSTOM ENV VARIABLES HERE OR DEFINE THEM IN A FILE .mega-linter.yml AT THE ROOT OF YOUR REPOSITORY |
| 64 | + GITHUB_COMMENT_REPORTER: "true" |
| 65 | + PYTHON_RUFF_ARGUMENTS: --config pyproject.toml --config 'output-format="github"' |
| 66 | + PYTHON_RUFF_FORMAT_ARGUMENTS: --config pyproject.toml --config 'output-format="github"' |
| 67 | + |
| 68 | + # Upload MegaLinter artifacts |
| 69 | + - name: Archive production artifacts |
| 70 | + if: success() || failure() |
| 71 | + uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # 4.6.2 |
| 72 | + with: |
| 73 | + name: MegaLinter reports |
| 74 | + path: | |
| 75 | + megalinter-reports |
| 76 | + mega-linter.log |
| 77 | +
|
| 78 | + # Push new commit if applicable (for now works only on PR from same repository, not from forks) |
| 79 | + - name: Prepare commit |
| 80 | + 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') |
| 81 | + run: sudo chown -Rc $UID .git/ |
| 82 | + - name: Commit and push applied linter fixes |
| 83 | + 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') |
| 84 | + uses: stefanzweifel/git-auto-commit-action@b863ae1933cb653a53c021fe36dbb774e1fb9403 # 5.2.0 |
| 85 | + with: |
| 86 | + branch: ${{ github.event.pull_request.head.ref || github.head_ref || github.ref }} |
| 87 | + commit_message: "[MegaLinter] Apply linters fixes" |
| 88 | + commit_user_name: newrelic-python-agent-team |
| 89 | + commit_user_email: [email protected] |
0 commit comments