diff --git a/.github/workflows/codecov.yml b/.github/workflows/codecov.yml index 73a39b0..e6590f5 100644 --- a/.github/workflows/codecov.yml +++ b/.github/workflows/codecov.yml @@ -1,11 +1,13 @@ --- -name: Codecov Coverage Report +name: "Codecov Coverage Report" -on: # yamllint disable-line rule:truthy - push: - branches: [ main ] - pull_request: - branches: [ main ] +on: # yamllint disable-line rule:truthy + # Makes it reusable; called by other workflows + workflow_call: + secrets: + CODECOV_TOKEN: + description: "CODECOV Auth Token" + required: true jobs: run: @@ -15,27 +17,28 @@ jobs: timeout-minutes: 10 strategy: matrix: - os: [ubuntu-latest] + os: ["ubuntu-latest"] python-version: ["3.12"] steps: - - uses: actions/checkout@main - - name: Setup Python - uses: actions/setup-python@main + - uses: "actions/checkout@main" + - name: "Setup Python" + uses: "actions/setup-python@main" with: python-version: ${{ matrix.python-version }} - name: "Cache PIP Dependencies" uses: "actions/cache@v4" with: path: ~/.cache/pip - key: ${{ runner.os }}-pip-${{ matrix.python-version }}-${{ hashFiles('requirements.txt') }} + key: | + ${{ runner.os }}-pip-${{ matrix.python-version }}-${{ hashFiles('requirements.txt') }} restore-keys: | ${{ runner.os }}-pip-${{ matrix.python-version }}- ${{ runner.os }}-pip- - - name: Install prerequisites + - name: "Install prerequisites" run: | python -m pip install --upgrade pip setuptools wheel pip install -r requirements.txt - - name: Install pytest, pytest-cov + - name: "Install pytest, pytest-cov" run: | pip install pytest pip install pytest-cov @@ -44,12 +47,12 @@ jobs: run: | python -c "import os; print(os.getcwd())" python -m pytest . --ignore=solutions --log-cli-level=INFO -v --cov-report term-missing --cov --cov-branch --cov-report=xml - - name: List test files + - name: "List test files" run: | ls *.xml # yamllint enable rule:line-length - - name: Upload coverage to Codecov - uses: codecov/codecov-action@v5.5.1 + - name: "Upload coverage to Codecov" + uses: "codecov/codecov-action@v5.5.1" with: token: ${{ secrets.CODECOV_TOKEN }} files: coverage.xml diff --git a/.github/workflows/flake8.yml b/.github/workflows/flake8.yml index bd102b3..176cefb 100644 --- a/.github/workflows/flake8.yml +++ b/.github/workflows/flake8.yml @@ -1,19 +1,9 @@ --- -name: "Flake8" +name: "Flake8 Workflow" -on: # yamllint disable-line rule:truthy - push: - branches: [ main ] - paths: - - '**/*.py' - - 'requirements.txt' - - '.pylintrc' - pull_request: - branches: [ main ] - paths: - - '**/*.py' - - 'requirements.txt' - - '.pylintrc' +on: # yamllint disable-line rule:truthy + # Makes it reusable; called by other workflows + workflow_call: permissions: contents: "read" @@ -33,21 +23,23 @@ jobs: - name: Set up Python ${{ matrix.python-version }} # This is the version of the action for setting up Python, # not the Python version. - uses: actions/setup-python@v6 + uses: "actions/setup-python@v6" with: python-version: ${{ matrix.python-version }} - name: "Cache PIP Dependencies" uses: "actions/cache@v4" with: path: ~/.cache/pip - key: ${{ runner.os }}-pip-${{ matrix.python-version }}-${{ hashFiles('requirements.txt') }} + key: | + ${{ runner.os }}-pip-${{ matrix.python-version }}-${{ hashFiles('requirements.txt') }} restore-keys: | ${{ runner.os }}-pip-${{ matrix.python-version }}- ${{ runner.os }}-pip- # You can test your matrix by printing the current # Python version - name: "Display Python Version" - run: python -c "import sys; print(sys.version)" + run: | + python -c "import sys; print(sys.version)" - name: "Install Dependencies" run: | python -m pip install --upgrade pip diff --git a/.github/workflows/lint_test_report.yml b/.github/workflows/lint_test_report.yml new file mode 100644 index 0000000..8e0813c --- /dev/null +++ b/.github/workflows/lint_test_report.yml @@ -0,0 +1,83 @@ +--- +name: "Main Pipeline" + +on: # yamllint disable-line rule:truthy + push: + branches: [ main ] + pull_request: + branches: [ main ] + +permissions: + contents: "read" + pull-requests: "read" + +jobs: + changed-files: + runs-on: "ubuntu-latest" + outputs: + python_changed: ${{ steps.python-files.outputs.any_changed }} + yaml_changed: ${{ steps.yaml-files.outputs.any_changed }} + steps: + - uses: "actions/checkout@v5" + - name: "Get changed Python files" + id: python-files + uses: "tj-actions/changed-files@v47" + with: + files: | + **/*.py + requirements.txt + .pylintrc + - name: "Get changed YAML files" + id: yaml-files + uses: "tj-actions/changed-files@v47" + with: + files: | + **/*.yml + **/*.yaml + + yamllint: + name: "YAML Lint Workflow" + needs: + - "changed-files" + if: needs.changed-files.outputs.yaml_changed == 'true' + uses: "./.github/workflows/yamllint.yml" + + ruff: + name: "Ruff Lint and Format" + needs: + - "changed-files" + - "yamllint" + if: needs.changed-files.outputs.python_changed == 'true' + uses: "./.github/workflows/ruff.yml" + + pylint: + name: "Pylint Workflow" + needs: + - "changed-files" + - "yamllint" + if: needs.changed-files.outputs.python_changed == 'true' + uses: "./.github/workflows/pylint.yml" + + flake8: + name: "Flake8 Workflow" + needs: + - "changed-files" + - "yamllint" + if: needs.changed-files.outputs.python_changed == 'true' + uses: "./.github/workflows/flake8.yml" + + pytest: + name: "Pytest Workflow" + needs: + - "ruff" + - "pylint" + - "flake8" + uses: "./.github/workflows/pytest.yml" + + codecov: + name: "Codecov Coverage Report" + needs: + - "pytest" + uses: "./.github/workflows/codecov.yml" + secrets: + CODECOV_TOKEN: "${{ secrets.CODECOV_TOKEN }}" diff --git a/.github/workflows/pylint.yml b/.github/workflows/pylint.yml index 0ae436f..ff25eb1 100644 --- a/.github/workflows/pylint.yml +++ b/.github/workflows/pylint.yml @@ -1,19 +1,9 @@ --- -name: "Pylint" +name: "Pylint Workflow" -on: - push: - branches: [ main ] - paths: - - '**/*.py' - - 'requirements.txt' - - '.pylintrc' - pull_request: - branches: [ main ] - paths: - - '**/*.py' - - 'requirements.txt' - - '.pylintrc' +on: # yamllint disable-line rule:truthy + # Makes it reusable; called by other workflows + workflow_call: jobs: build: @@ -25,25 +15,25 @@ jobs: matrix: python-version: ["3.12"] steps: - - uses: "actions/checkout@v5" - - name: Set up Python ${{ matrix.python-version }} - uses: "actions/setup-python@v6" - with: - python-version: ${{ matrix.python-version }} - - name: "Cache PIP Dependencies" - uses: "actions/cache@v4" - with: - path: ~/.cache/pip - key: | - ${{ runner.os }}-pip-${{ matrix.python-version }}-${{ hashFiles('requirements.txt') }} - restore-keys: | - ${{ runner.os }}-pip-${{ matrix.python-version }}- - ${{ runner.os }}-pip- - - name: "Install dependencies" - run: | - python -m pip install --upgrade pip - pip install pylint - pip install -r requirements.txt - - name: "Analysing the code with pylint" - run: | - python -m pylint --verbose $(find . -name "*.py" ! -path "*/.venv/*" ! -path "*/venv/*") --rcfile=.pylintrc \ No newline at end of file + - uses: "actions/checkout@v5" + - name: Set up Python ${{ matrix.python-version }} + uses: "actions/setup-python@v6" + with: + python-version: ${{ matrix.python-version }} + - name: "Cache PIP Dependencies" + uses: "actions/cache@v4" + with: + path: ~/.cache/pip + key: | + ${{ runner.os }}-pip-${{ matrix.python-version }}-${{ hashFiles('requirements.txt') }} + restore-keys: | + ${{ runner.os }}-pip-${{ matrix.python-version }}- + ${{ runner.os }}-pip- + - name: "Install dependencies" + run: | + python -m pip install --upgrade pip + pip install pylint + pip install -r requirements.txt + - name: "Analysing the code with pylint" + run: | + python -m pylint --verbose $(find . -name "*.py" ! -path "*/.venv/*" ! -path "*/venv/*") --rcfile=.pylintrc diff --git a/.github/workflows/pytest.yml b/.github/workflows/pytest.yml index fb740ab..7737a16 100644 --- a/.github/workflows/pytest.yml +++ b/.github/workflows/pytest.yml @@ -1,11 +1,9 @@ --- name: "Pytest Workflow" -on: - push: - branches: [ main ] - pull_request: - branches: [ main ] +on: # yamllint disable-line rule:truthy + # Makes it reusable; called by other workflows + workflow_call: jobs: test: @@ -14,26 +12,26 @@ jobs: # indefinitely if something goes wrong timeout-minutes: 10 steps: - - name: "Checkout code" - uses: "actions/checkout@v5" - - name: "Set up Python 3.12" - uses: "actions/setup-python@v6" - with: - python-version: "3.12" - - name: "Cache PIP Dependencies" - uses: "actions/cache@v4" - with: - path: ~/.cache/pip - key: | - ${{ runner.os }}-pip-${{ matrix.python-version }}-${{ hashFiles('requirements.txt') }} - restore-keys: | - ${{ runner.os }}-pip-${{ matrix.python-version }}- - ${{ runner.os }}-pip- - - name: "Install dependencies" - run: | - python -m pip install --upgrade pip - pip install -r requirements.txt - pip install pytest - - name: "Run pytest" - run: | - pytest . --verbose --ignore=solutions --log-cli-level=INFO \ No newline at end of file + - name: "Checkout code" + uses: "actions/checkout@v5" + - name: "Set up Python 3.12" + uses: "actions/setup-python@v6" + with: + python-version: "3.12" + - name: "Cache PIP Dependencies" + uses: "actions/cache@v4" + with: + path: ~/.cache/pip + key: | + ${{ runner.os }}-pip-${{ matrix.python-version }}-${{ hashFiles('requirements.txt') }} + restore-keys: | + ${{ runner.os }}-pip-${{ matrix.python-version }}- + ${{ runner.os }}-pip- + - name: "Install dependencies" + run: | + python -m pip install --upgrade pip + pip install -r requirements.txt + pip install pytest + - name: "Run pytest" + run: | + pytest . --verbose --ignore=solutions --log-cli-level=INFO diff --git a/.github/workflows/ruff.yml b/.github/workflows/ruff.yml index 7666f2e..7e4659c 100644 --- a/.github/workflows/ruff.yml +++ b/.github/workflows/ruff.yml @@ -1,19 +1,9 @@ --- name: "Ruff Lint and Format" -on: - push: - branches: [ main ] - paths: - - '**/*.py' - - 'requirements.txt' - - '.pylintrc' - pull_request: - branches: [ main ] - paths: - - '**/*.py' - - 'requirements.txt' - - '.pylintrc' +on: # yamllint disable-line rule:truthy + # Makes it reusable; called by other workflows + workflow_call: jobs: ruff: @@ -31,7 +21,8 @@ jobs: uses: "actions/cache@v4" with: path: ~/.cache/pip - key: ${{ runner.os }}-pip-${{ matrix.python-version }}-${{ hashFiles('requirements.txt') }} + key: | + ${{ runner.os }}-pip-${{ matrix.python-version }}-${{ hashFiles('requirements.txt') }} restore-keys: | ${{ runner.os }}-pip-${{ matrix.python-version }}- ${{ runner.os }}-pip- @@ -44,4 +35,4 @@ jobs: ruff check --output-format=github . - name: "Run Ruff format check" run: | - ruff format --check . \ No newline at end of file + ruff format --check . diff --git a/.github/workflows/yamllint.yml b/.github/workflows/yamllint.yml new file mode 100644 index 0000000..1d797de --- /dev/null +++ b/.github/workflows/yamllint.yml @@ -0,0 +1,38 @@ +--- +name: "YAML Lint Workflow" + +on: # yamllint disable-line rule:truthy + # Makes it reusable; called by other workflows + workflow_call: + +jobs: + yamllint: + runs-on: "ubuntu-latest" + # Adding 'timeout-minutes: 10' would prevent jobs from running + # indefinitely if something goes wrong + timeout-minutes: 10 + steps: + - uses: "actions/checkout@v5" + - name: "Set up Python 3.12" + uses: "actions/setup-python@v6" + with: + python-version: "3.12" + - name: "Cache PIP Dependencies" + uses: "actions/cache@v4" + with: + path: ~/.cache/pip + key: | + ${{ runner.os }}-pip-3.12-${{ hashFiles('requirements.txt') }} + restore-keys: | + ${{ runner.os }}-pip-3.12- + ${{ runner.os }}-pip- + - name: "Install yamllint" + run: | + python -m pip install --upgrade pip + pip install yamllint + - name: "Check yamllint Version" + run: | + yamllint --version + - name: "Lint with yamllint" + run: | + yamllint . diff --git a/.yamllint.yml b/.yamllint.yml new file mode 100644 index 0000000..0c01e2b --- /dev/null +++ b/.yamllint.yml @@ -0,0 +1,3 @@ +--- +rules: + line-length: disable diff --git a/Dockerfile b/Dockerfile index 8a235c6..54894c4 100644 --- a/Dockerfile +++ b/Dockerfile @@ -38,7 +38,8 @@ RUN pip install --no-cache-dir \ flake8 \ pylint \ pytest \ - pytest-cov + pytest-cov \ + yamllint # Copy the rest of the code (including .pylintrc if present) COPY . . diff --git a/README.md b/README.md index 2877080..c3cd5c0 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,6 @@ # [Exercism Python Track](https://exercism.io/tracks/python) -[](https://github.com/ikostan/python/actions/workflows/pytest.yml) -[](https://github.com/ikostan/python/actions/workflows/pylint.yml) -[](https://github.com/ikostan/python/actions/workflows/ruff.yml) -[](https://github.com/ikostan/python/actions/workflows/flake8.yml) +[](https://github.com/ikostan/python/actions/workflows/lint_test_report.yml) [](https://codecov.io/github/ikostan/python)