From 93928e275760d0212044793cd962d3effc6a103e Mon Sep 17 00:00:00 2001 From: Victor Moene Date: Fri, 20 Dec 2024 12:12:17 +0100 Subject: [PATCH 1/2] Added black yml files Ticket: ENT-12541 Signed-off-by: Victor Moene --- .github/workflows/black-format.yml | 67 ++++++++++++++++++++++++++++++ .github/workflows/black.yml | 34 +++++++++++++++ 2 files changed, 101 insertions(+) create mode 100644 .github/workflows/black-format.yml create mode 100644 .github/workflows/black.yml diff --git a/.github/workflows/black-format.yml b/.github/workflows/black-format.yml new file mode 100644 index 0000000..0105f68 --- /dev/null +++ b/.github/workflows/black-format.yml @@ -0,0 +1,67 @@ +name: Automatically format with Black and submit PR + +on: + push: + branches: + - master + + workflow_dispatch: + +jobs: + format: + runs-on: ubuntu-20.04 + steps: + - name: Checks-out repository + uses: actions/checkout@v4 + - name: Set up Python 3.6cf_remote + uses: actions/setup-python@v5 + with: + python-version: "3.6" + - name: Install black + run: | + python -m pip install --upgrade pip + python -m pip install black + - name: Reformat with black + run: | + shopt -s globstar + black cf_remote/*.py cf_remote/**/*.py tests/*.py tests/**/*.py > 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 + - name: Commit changes + if: hashFiles('git_diff_exists') != '' + run: | + git config user.name 'GitHub' + git config user.email '' + shopt -s globstar + git add cf_remote/*.py cf_remote/**/*.py tests/*.py tests/**/*.py + git commit -F 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@v6 + with: + title: Reformatted python code using Black formatter + body: ${{ steps.commit-message-from-file.outputs.body }} + reviewers: | + olehermanse + larsewi + vpodzime + branch: formatting-action diff --git a/.github/workflows/black.yml b/.github/workflows/black.yml new file mode 100644 index 0000000..142591a --- /dev/null +++ b/.github/workflows/black.yml @@ -0,0 +1,34 @@ +# 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: Black + +on: + push: + branches: [ master ] + pull_request: + branches: [ master ] + +jobs: + check: + runs-on: ubuntu-20.04 + strategy: + fail-fast: false + matrix: + python-version: [3.6] + + 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 black + if [ -f requirements.txt ]; then pip install -r requirements.txt; fi + - name: Check formatting with black + run: | + shopt -s globstar + black --check cf_remote/*.py cf_remote/**/*.py tests/*.py tests/**/*.py From 97b761ad448f104c6cd6222a609c739a5ccbced4 Mon Sep 17 00:00:00 2001 From: Victor Moene Date: Fri, 20 Dec 2024 13:12:14 +0100 Subject: [PATCH 2/2] Reformatted test_spawn.py Signed-off-by: Victor Moene --- tests/test_spawn.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/test_spawn.py b/tests/test_spawn.py index c8a08f4..13d905d 100644 --- a/tests/test_spawn.py +++ b/tests/test_spawn.py @@ -1,5 +1,6 @@ from cf_remote.spawn import _get_image_criteria + def test_get_image_criteria(): criteria = _get_image_criteria("ubuntu-22-04-x86") assert criteria["version"] == "22.04"