diff --git a/.github/actions/set-up-legacy-python/action.yml b/.github/actions/set-up-legacy-python/action.yml new file mode 100644 index 0000000..791c7db --- /dev/null +++ b/.github/actions/set-up-legacy-python/action.yml @@ -0,0 +1,27 @@ +name: "Set up legacy Python" +description: "Sets up a specified Python version in a virtual environment using `pyenv`, installs dependencies, and caches the environment" +inputs: + python-version: + required: true + description: "The Python version to set up" + +runs: + using: "composite" + steps: + - uses: actions/cache@v4 + id: pyenv-cache + with: + path: | + /opt/hostedtoolcache/pyenv_root/2.4.20/x64/versions/${{ inputs.python-version }} + key: ${{ inputs.python-version }}-${{ hashFiles('requirements.txt') }} + - name: Set up Python ${{ inputs.python-version }} using pyenv + uses: gabrielfalcao/pyenv-action@32ef4d2c861170ce17ded56d10329d83f4c8f797 + if: steps.pyenv-cache.outputs.cache-hit != 'true' + with: + default: "${{ inputs.python-version }}" + command: pip install -U pip + - name: Install dependencies + run: | + python -m pip install flake8 pytest setuptools wheel + if [ -f requirements.txt ]; then pip install -r requirements.txt; fi + shell: bash diff --git a/.github/workflows/black-format.yml b/.github/workflows/black-format.yml index f3777e4..ff604f8 100644 --- a/.github/workflows/black-format.yml +++ b/.github/workflows/black-format.yml @@ -1,67 +1,67 @@ name: Automatically format with Black and submit PR on: - push: - branches: - - master + push: + branches: + - master - workflow_dispatch: + workflow_dispatch: jobs: format: - runs-on: ubuntu-20.04 + 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 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 + - 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 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 index e09df15..93ab65c 100644 --- a/.github/workflows/black.yml +++ b/.github/workflows/black.yml @@ -5,30 +5,30 @@ name: Black on: push: - branches: [ master ] + branches: [master] pull_request: - branches: [ master ] + branches: [master] jobs: check: - runs-on: ubuntu-20.04 + runs-on: ubuntu-24.04 strategy: fail-fast: false matrix: - python-version: [3.12] + 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 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 + - 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 diff --git a/.github/workflows/python-publish.yml b/.github/workflows/python-publish.yml index 454832d..e3ca5b2 100644 --- a/.github/workflows/python-publish.yml +++ b/.github/workflows/python-publish.yml @@ -13,20 +13,20 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 - - name: Set up Python - uses: actions/setup-python@v5 - with: - python-version: '3.x' - - name: Install dependencies - run: | - python -m pip install --upgrade pip - pip install setuptools wheel twine - - name: Build and publish - env: - TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }} - TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }} - run: | - git fetch --all --tags - python setup.py sdist bdist_wheel - twine upload dist/* + - uses: actions/checkout@v4 + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: '3.x' + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install setuptools wheel twine + - name: Build and publish + env: + TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }} + TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }} + run: | + git fetch --all --tags + python setup.py sdist bdist_wheel + twine upload dist/* diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 291d17a..96d83a6 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -5,52 +5,88 @@ name: Tests on: push: - branches: [ master ] + branches: [master] pull_request: - branches: [ master ] + branches: [master] jobs: - python_version: - runs-on: ubuntu-20.04 + test: + runs-on: ubuntu-24.04 + strategy: + fail-fast: false + matrix: + python-version: ["3.8", "3.9", "3.10", "3.11", "3.12", "3.13"] + + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + - 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 flake8 pytest setuptools wheel + if [ -f requirements.txt ]; then pip install -r requirements.txt; fi + - name: Lint with flake8 + run: | + # stop the build if there are Python syntax errors or undefined names + flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics + # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide + flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics + - name: Test with pytest + run: | + pytest + - name: Install + run: | + python setup.py sdist bdist_wheel + pip install dist/cf_remote-*.whl + - name: Sanity check + run: cf-remote -V + - name: Run docker test + run: | + bash tests/docker/0*.sh + - name: Run unsafe tests + run: | + bash tests/unsafe/0*.sh + test-legacy: + runs-on: ubuntu-24.04 env: # Temporary workaround for Python 3.5 failures - May 2024, see CFE-4395 PIP_TRUSTED_HOST: "pypi.python.org pypi.org files.pythonhosted.org" strategy: fail-fast: false matrix: - python-version: [3.5, 3.6, 3.7, 3.8, 3.9] + python-version: ["3.5.10", "3.6.15", "3.7.10"] 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: Install dependencies - run: | - python -m pip install --upgrade pip - python -m pip install flake8 pytest setuptools wheel - if [ -f requirements.txt ]; then pip install -r requirements.txt; fi - - name: Lint with flake8 - run: | - # stop the build if there are Python syntax errors or undefined names - flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics - # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide - flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics - - name: Test with pytest - run: | - pytest - - name: Install - run: | - python setup.py sdist bdist_wheel - pip install dist/cf_remote-*.whl - - name: Sanity check - run: cf-remote -V - - name: Run docker test - run: | - bash tests/docker/0*.sh - - name: Run unsafe tests - run: | - bash tests/unsafe/0*.sh + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + - name: Set up legacy Python ${{ matrix.python-version }} + uses: ./.github/actions/set-up-legacy-python + with: + python-version: ${{ matrix.python-version }} + - name: Lint with flake8 + run: | + # stop the build if there are Python syntax errors or undefined names + flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics + # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide + flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics + - name: Test with pytest + run: | + pytest + - name: Install + run: | + python setup.py sdist bdist_wheel + pip install dist/cf_remote-*.whl + - name: Sanity check + run: cf-remote -V + - name: Run docker test + run: | + bash tests/docker/0*.sh + - name: Run unsafe tests + run: | + bash tests/unsafe/0*.sh