diff --git a/.github/workflows/format.yml b/.github/workflows/format.yml deleted file mode 100644 index 535f185..0000000 --- a/.github/workflows/format.yml +++ /dev/null @@ -1,61 +0,0 @@ -name: Format -permissions: - contents: write - pull-requests: write -on: - push: - branches: - - main - workflow_dispatch: -jobs: - format: - runs-on: ubuntu-24.04 - steps: - - name: Checks-out repository - uses: actions/checkout@v4 - - name: Set up Python 3.12 - uses: actions/setup-python@v5 - with: - python-version: "3.12" - - name: Install black - run: | - python -m pip install --upgrade pip - python -m pip install black - - name: Reformat with black - run: | - shopt -s globstar - black . > black_output.txt 2>&1 - - name: Check if there are changes - run: | - git diff --exit-code || touch git_diff_exists - if [ -f git_diff_exists ]; then echo "Changes need to be commited"; else echo "No changes to commit"; fi - - name: Create commit message - if: hashFiles('git_diff_exists') != '' - run: | - echo "Reformatted python code using Black formatter" >> commit_message.txt - echo "" >> commit_message.txt - echo "Output from black:" >> commit_message.txt - echo "" >> commit_message.txt - echo '```' >> commit_message.txt - cat black_output.txt >> commit_message.txt - echo '```' >> commit_message.txt - - id: commit-message-from-file - name: Parse commit message from file into variable - if: hashFiles('git_diff_exists') != '' - run: | - body=$(cat commit_message.txt) - body="${body//$'\n'/'%0A'}" - echo ::set-output name=body::$body - - name: Create Pull Request - if: hashFiles('git_diff_exists') != '' - uses: cfengine/create-pull-request@158a28c1bf5c08c846b8e7d26d13becbd4136eda # v7.0.7a - with: - title: Reformatted python code using Black formatter - commit-message: Reformatted python code using Black formatter - sign-commits: true - body: ${{ steps.commit-message-from-file.outputs.body }} - reviewers: | - olehermanse - larsewi - vpodzime - branch: formatting-action diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml deleted file mode 100644 index 1d53a79..0000000 --- a/.github/workflows/lint.yml +++ /dev/null @@ -1,49 +0,0 @@ -# This workflow will install Python dependencies, run tests and lint with a variety of Python versions -# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions - -name: Lint -on: - push: - branches: [main] - pull_request: - branches: [main] -permissions: - contents: read -jobs: - lint: - runs-on: ubuntu-24.04 - strategy: - fail-fast: false - matrix: - python-version: ["3.12"] - steps: - - uses: actions/checkout@v4 - - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v5 - with: - python-version: ${{ matrix.python-version }} - - name: Install dependencies - run: | - python -m pip install --upgrade pip - python -m pip install uv - sudo apt-get install npm - npm install --global prettier - - name: Setup - run: | - uv venv - uv sync - - name: Check formatting with black - run: | - uv tool run black --check . - - name: Check formatting with prettier - run: | - prettier . --check - - name: Run flake8 - run: | - uv tool run flake8 src/ --ignore=E203,W503,E722,E731 --max-complexity=100 --max-line-length=160 - - name: Run pyflakes - run: | - uv tool run pyflakes src/ - - name: Run pyright - run: | - uv tool run pyright src/ diff --git a/.github/workflows/make-check.yml b/.github/workflows/make-check.yml new file mode 100644 index 0000000..f67e6fc --- /dev/null +++ b/.github/workflows/make-check.yml @@ -0,0 +1,45 @@ +# This workflow installs the necessary dependencies, runs make check, and +# checks if there are any edits. It should be very similar to what developers +# are expected to do locally. We want to ensure that all tests pass (make +# check succeeds) and that there is no additional formatting / untracked +# files generated. +# +# Note that make check is a bit special in this repo, it has some things you +# might not expect: +# 1. It doesn't only run tests, it also runs formatters and linters +# 2. It installs the CFEngine CLI, so that shell tests will work + +name: Run make check +on: + push: + branches: [main] + pull_request: + branches: [main] +permissions: + contents: read +jobs: + check: + runs-on: ubuntu-24.04 + strategy: + fail-fast: false + matrix: + python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"] + steps: + - uses: actions/checkout@v4 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v5 + with: + python-version: ${{ matrix.python-version }} + - name: Install dependencies + run: | + python -m pip install --upgrade pip + python -m pip install uv + sudo apt-get install npm + npm install --global prettier + - name: Run make check + run: | + make check + - name: See if there are changes + run: | + git diff --exit-code + git ls-files --other --directory --exclude-standard | sed q1 diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml deleted file mode 100644 index 17144e5..0000000 --- a/.github/workflows/test.yml +++ /dev/null @@ -1,53 +0,0 @@ -# This workflow will install Python dependencies, run tests and lint with a variety of Python versions -# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions -name: Test -on: - push: - branches: [main] - pull_request: - branches: [main] - workflow_call: -permissions: - contents: read -jobs: - test: - runs-on: ubuntu-24.04 - strategy: - fail-fast: true - matrix: - python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"] - steps: - - uses: actions/checkout@v3 - with: - fetch-depth: 0 - - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v5 - with: - python-version: ${{ matrix.python-version }} - - name: Set up - run: | - git fetch --all --tags - pip install uv - - name: Python unit tests - run: | - uv lock --check - uv run pytest - - name: Run build - run: | - uv build - - name: Install - run: | - uv sync --frozen - uv pip install . - - name: Shell tests - run: | - source .venv/bin/activate - bash tests/run-shell-tests.sh - - name: Format tests - run: | - source .venv/bin/activate - bash tests/run-format-tests.sh - - name: Lint tests - run: | - source .venv/bin/activate - bash tests/run-lint-tests.sh diff --git a/Makefile b/Makefile index 0086515..04ac477 100644 --- a/Makefile +++ b/Makefile @@ -1,12 +1,16 @@ -.PHONY: default format lint install check +.PHONY: default format lint install check venv default: check -format: +venv: + uv venv --clear + uv sync + +format: venv uv tool run black . prettier . --write -lint: +lint: venv uv tool run black --check . uv tool run flake8 src/ --ignore=E203,W503,E722,E731 --max-complexity=100 --max-line-length=160 uv tool run pyflakes src/ @@ -15,7 +19,7 @@ lint: install: pipx install --force --editable . -check: format lint install +check: venv format lint install uv run pytest bash tests/run-lint-tests.sh bash tests/run-format-tests.sh