Skip to content

Commit a861e24

Browse files
authored
Add MegaLinter Config (#80)
* Add megalinter config * Remove unused config from Python Agent repo * Remove linter from tox * Format with MegaLinter * Fix copy paste artifact on addlicense * Pin setup-python
1 parent c4cbdb2 commit a861e24

File tree

8 files changed

+227
-111
lines changed

8 files changed

+227
-111
lines changed

.github/workflows/addlicense.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ jobs:
3232
steps:
3333
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # 4.2.2
3434

35-
- uses: actions/setup-python@v4
35+
- uses: actions/setup-python@8d9ed9ac5c53483de85588cdf95a591a75ab9f55 # 5.5.0
3636
with:
37-
python-version: ${{ matrix.python.version }}
37+
python-version: 3.13
3838
architecture: x64
3939

4040
- name: Check License Headers

.github/workflows/deploy.yml

Lines changed: 49 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -25,72 +25,71 @@ jobs:
2525
permissions:
2626
contents: read
2727
steps:
28-
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # 4.2.2
28+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # 4.2.2
2929

30-
- uses: actions/setup-python@8d9ed9ac5c53483de85588cdf95a591a75ab9f55 # 5.5.0
31-
with:
32-
python-version: '3.x'
33-
architecture: x64
30+
- uses: actions/setup-python@8d9ed9ac5c53483de85588cdf95a591a75ab9f55 # 5.5.0
31+
with:
32+
python-version: "3.x"
33+
architecture: x64
3434

35-
- name: Install Dependencies
36-
run: |
37-
pip install -U pip
38-
pip install -U build
35+
- name: Install Dependencies
36+
run: |
37+
pip install -U pip
38+
pip install -U build
3939
40-
- name: Build Package
41-
run: |
42-
python -m build
40+
- name: Build Package
41+
run: |
42+
python -m build
4343
44-
- name: Upload Artifacts
45-
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # 4.6.2
46-
with:
47-
name: dist
48-
path: ./dist/*
49-
if-no-files-found: error
50-
retention-days: 1
44+
- name: Upload Artifacts
45+
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # 4.6.2
46+
with:
47+
name: dist
48+
path: ./dist/*
49+
if-no-files-found: error
50+
retention-days: 1
5151

5252
publish:
5353
runs-on: ubuntu-latest
5454
environment: pypi
5555
permissions:
56-
id-token: write # IMPORTANT: this permission is mandatory for trusted publishing
56+
id-token: write # IMPORTANT: this permission is mandatory for trusted publishing
5757
attestations: write
5858
needs: [build]
5959
steps:
60-
- uses: actions/download-artifact@95815c38cf2ff2164869cbab79da8d1f422bc89e # 4.2.1
61-
with:
62-
name: dist
63-
path: ./dist/
60+
- uses: actions/download-artifact@95815c38cf2ff2164869cbab79da8d1f422bc89e # 4.2.1
61+
with:
62+
name: dist
63+
path: ./dist/
6464

65-
- name: Upload Package
66-
uses: pypa/gh-action-pypi-publish@76f52bc884231f62b9a034ebfe128415bbaabdfc # 1.12.4
65+
- name: Upload Package
66+
uses: pypa/gh-action-pypi-publish@76f52bc884231f62b9a034ebfe128415bbaabdfc # 1.12.4
6767

6868
docs:
69-
7069
runs-on: ubuntu-latest
7170
permissions:
7271
contents: write
7372
steps:
74-
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # 4.2.2
75-
- uses: actions/setup-python@8d9ed9ac5c53483de85588cdf95a591a75ab9f55 # 5.5.0
76-
with:
77-
python-version: '3.x'
78-
architecture: x64
79-
- name: Prepare git directory for docs build
80-
run: |
81-
git config --local user.name "github-actions[bot]"
82-
git config --local user.email "github-actions[bot]@users.noreply.github.com"
83-
git fetch origin gh-pages && \
84-
git worktree add --no-checkout -B gh-pages docs/_build origin/gh-pages
85-
- name: Install Dependencies
86-
run: |
87-
pip install -U pip
88-
pip install -U wheel setuptools tox
89-
- name: Generate docs
90-
run: tox -e docs
91-
- name: Publish docs
92-
run: |
93-
git add --all
94-
git commit --amend --no-edit --date=now
95-
git push -f
96-
working-directory: ./docs/_build
73+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # 4.2.2
74+
- uses: actions/setup-python@8d9ed9ac5c53483de85588cdf95a591a75ab9f55 # 5.5.0
75+
with:
76+
python-version: "3.x"
77+
architecture: x64
78+
- name: Prepare git directory for docs build
79+
run: |
80+
git config --local user.name "github-actions[bot]"
81+
git config --local user.email "github-actions[bot]@users.noreply.github.com"
82+
git fetch origin gh-pages && \
83+
git worktree add --no-checkout -B gh-pages docs/_build origin/gh-pages
84+
- name: Install Dependencies
85+
run: |
86+
pip install -U pip
87+
pip install -U wheel setuptools tox
88+
- name: Generate docs
89+
run: tox -e docs
90+
- name: Publish docs
91+
run: |
92+
git add --all
93+
git commit --amend --no-edit --date=now
94+
git push -f
95+
working-directory: ./docs/_build

.github/workflows/mega-linter.yml

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
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]

.github/workflows/tests.yml

Lines changed: 43 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ on:
1919
branches:
2020
- main
2121
tags-ignore:
22-
- '**'
22+
- "**"
2323
pull_request:
2424

2525
jobs:
@@ -64,63 +64,57 @@ jobs:
6464
fail-fast: False
6565
matrix:
6666
os: [ubuntu-latest, windows-latest]
67-
python:
68-
- version: "3.8"
69-
tox-prefix: py38
70-
- version: "3.9"
71-
tox-prefix: py39
72-
- version: "3.10"
73-
tox-prefix: py310
74-
- version: "3.11"
75-
tox-prefix: py311
76-
- version: "3.12"
77-
tox-prefix: py312
78-
- version: "3.13"
79-
tox-prefix: py313
80-
- version: "pypy3.10"
81-
tox-prefix: pypy310
67+
python:
68+
- version: "3.8"
69+
tox-prefix: py38
70+
- version: "3.9"
71+
tox-prefix: py39
72+
- version: "3.10"
73+
tox-prefix: py310
74+
- version: "3.11"
75+
tox-prefix: py311
76+
- version: "3.12"
77+
tox-prefix: py312
78+
- version: "3.13"
79+
tox-prefix: py313
80+
- version: "pypy3.10"
81+
tox-prefix: pypy310
8282

8383
runs-on: ${{ matrix.os }}
8484
timeout-minutes: 5
8585
permissions:
8686
contents: read
8787

8888
steps:
89-
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # 4.2.2
89+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # 4.2.2
9090

91-
- uses: actions/setup-python@8d9ed9ac5c53483de85588cdf95a591a75ab9f55 # 5.5.0
92-
with:
93-
python-version: ${{ matrix.python.version }}
94-
architecture: x64
91+
- uses: actions/setup-python@8d9ed9ac5c53483de85588cdf95a591a75ab9f55 # 5.5.0
92+
with:
93+
python-version: ${{ matrix.python.version }}
94+
architecture: x64
9595

96-
- name: Install Dependencies
97-
run: |
98-
pip install -U pip
99-
pip install -U wheel setuptools tox coverage
96+
- name: Install Dependencies
97+
run: |
98+
pip install -U pip
99+
pip install -U wheel setuptools tox coverage
100100
101-
- name: Test
102-
run: tox -vv -f ${{ matrix.python.tox-prefix }} -- --cov-report=xml
103-
env:
104-
TOX_DISCOVER: "patch-for-windows-pypy3"
101+
- name: Test
102+
run: tox -vv -f ${{ matrix.python.tox-prefix }} -- --cov-report=xml
103+
env:
104+
TOX_DISCOVER: "patch-for-windows-pypy3"
105105

106-
- name: Upload Coverage Artifacts
107-
if: runner.os == 'Linux'
108-
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # 4.6.2
109-
with:
110-
name: coverage-${{ github.job }}-${{ strategy.job-index }}
111-
path: ./**/.coverage.*
112-
include-hidden-files: true
113-
if-no-files-found: error
114-
retention-days: 1
106+
- name: Upload Coverage Artifacts
107+
if: runner.os == 'Linux'
108+
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # 4.6.2
109+
with:
110+
name: coverage-${{ github.job }}-${{ strategy.job-index }}
111+
path: ./**/.coverage.*
112+
include-hidden-files: true
113+
if-no-files-found: error
114+
retention-days: 1
115115

116-
- name: Lint
117-
run: tox -vv
118-
env:
119-
TOXENV: lint
120-
if: matrix.python.version == 3.9 && matrix.os == 'ubuntu-latest'
121-
122-
- name: Docs
123-
run: tox -vv
124-
env:
125-
TOXENV: docs
126-
if: matrix.python.version == 3.9 && matrix.os == 'ubuntu-latest'
116+
- name: Docs
117+
run: tox -vv
118+
env:
119+
TOXENV: docs
120+
if: matrix.python.version == 3.9 && matrix.os == 'ubuntu-latest'

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# Linter
2+
megalinter-reports/
3+
14
# Byte-compiled / optimized / DLL files
25
__pycache__/
36
*.py[cod]

.megalinter.yml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
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+
# Configuration file for Mega-Linter
16+
# See all available variables at https://oxsecurity.github.io/megalinter/configuration/ and in linters documentation
17+
18+
APPLY_FIXES: none # all, none, or list of linter keys
19+
DEFAULT_BRANCH: main # Usually master or main
20+
SHOW_ELAPSED_TIME: true
21+
FILEIO_REPORTER: false
22+
PRINT_ALPACA: false
23+
CLEAR_REPORT_FOLDER: true
24+
VALIDATE_ALL_CODEBASE: true
25+
IGNORE_GITIGNORED_FILES: true
26+
FAIL_IF_MISSING_LINTER_IN_FLAVOR: true
27+
28+
ENABLE_LINTERS: # If you use ENABLE_LINTERS variable, all other linters will be disabled by default
29+
- ACTION_ACTIONLINT
30+
- PYTHON_RUFF
31+
- PYTHON_RUFF_FORMAT
32+
- YAML_PRETTIER
33+
- YAML_V8R
34+
- YAML_YAMLLINT
35+
36+
PYTHON_DEFAULT_STYLE: ruff
37+
PYTHON_RUFF_CONFIG_FILE: pyproject.toml
38+
PYTHON_RUFF_FORMAT_CONFIG_FILE: pyproject.toml

CONTRIBUTING.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,9 @@ testing. The repository uses doctests in `src/ <src/>`__ and tests in
101101
You can run all of these tests, and verify that your code is formatted
102102
correctly by running:
103103

104-
``tox -epy,lint``
104+
``tox -e py``
105+
106+
``ruff format && ruff check --fix``
105107

106108
License
107109
-------

0 commit comments

Comments
 (0)