From bfd31782afd562dbfb90b71a42f9a9e420c4db3a Mon Sep 17 00:00:00 2001 From: Felix Kaschura Date: Fri, 9 Feb 2024 12:18:26 +0100 Subject: [PATCH] Add github checks --- .github/CODEOWNERS | 1 + .github/Check-SemilinearHistory.ps1 | 28 ++++++++++ .github/check_version_uniqueness.py | 34 ++++++++++++ .github/workflows/check_version.yml | 26 +++++++++ .github/workflows/publish.yml | 70 ++++++++++++++++++++++++ .github/workflows/semilinear_history.yml | 19 +++++++ .github/workflows/tox.yml | 27 +++++++++ 7 files changed, 205 insertions(+) create mode 100644 .github/CODEOWNERS create mode 100644 .github/Check-SemilinearHistory.ps1 create mode 100644 .github/check_version_uniqueness.py create mode 100644 .github/workflows/check_version.yml create mode 100644 .github/workflows/publish.yml create mode 100644 .github/workflows/semilinear_history.yml create mode 100644 .github/workflows/tox.yml diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS new file mode 100644 index 0000000..35cba4a --- /dev/null +++ b/.github/CODEOWNERS @@ -0,0 +1 @@ +* @fk3 diff --git a/.github/Check-SemilinearHistory.ps1 b/.github/Check-SemilinearHistory.ps1 new file mode 100644 index 0000000..f7b55e9 --- /dev/null +++ b/.github/Check-SemilinearHistory.ps1 @@ -0,0 +1,28 @@ +Param( + [Parameter(Mandatory)] + [string]$targetBranch, + [Parameter(Mandatory)] + [string]$sourceBranch +) + +$ErrorActionPreference = 'Stop' + +git fetch origin $targetBranch +$commitTarget = git rev-parse "origin/$targetBranch" +git fetch origin $sourceBranch +$commitSource = git rev-parse "origin/$sourceBranch" + +# verify that source branch originates from the latest commit of the target branch +# (i.e. a fast-forward merge could be performed) +git merge-base --is-ancestor $commitTarget $commitSource +if ($LASTEXITCODE -ne "0") +{ + throw "Merge would create a non-semilinear history. Please rebase." +} + +# the target branch should only contain simple commits and no merges +$numberOfMergeCommits = git rev-list --min-parents=2 --count "${commitTarget}..${commitSource}" +if ($numberOfMergeCommits -ne "0") +{ + Throw "Source Branch contains non-linear history. Please rebase." +} diff --git a/.github/check_version_uniqueness.py b/.github/check_version_uniqueness.py new file mode 100644 index 0000000..03f42eb --- /dev/null +++ b/.github/check_version_uniqueness.py @@ -0,0 +1,34 @@ +"""Make sure that the version number has been increased and does not exist on PyPI yet.""" + +import importlib.metadata +import subprocess + +lib = "interface-proxy" + +lib_version = importlib.metadata.version(lib) + +not_found = False + +try: + subprocess.check_call( + [ # noqa: S603, S607 + "python", + "-m", + "pip", + "install", + "--no-deps", + "--ignore-installed", + "--dry-run", + f"{lib}=={lib_version}", + ], + ) +except subprocess.SubprocessError: + not_found = True + +if not_found is False: + exc_msg = ( + f"Version {lib_version} seems to be published already. " + f"Did you forget to increase the version number in interface_proxy/__init__.py?" + ) + print(f"::error::{exc_msg}") # noqa: T201 + raise ValueError(exc_msg) diff --git a/.github/workflows/check_version.yml b/.github/workflows/check_version.yml new file mode 100644 index 0000000..797a8c2 --- /dev/null +++ b/.github/workflows/check_version.yml @@ -0,0 +1,26 @@ +name: Check Version + +on: + pull_request: + branches: main + +permissions: + contents: read + +jobs: + check_version: + name: Check Version + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - name: Set up Python 3.9 + uses: actions/setup-python@v3 + with: + python-version: "3.9" + - name: Install environment + run: | + python -m pip install --upgrade pip + pip install --no-deps . + - name: Run version check + run: | + python .github/check_version_uniqueness.py diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 0000000..05ff5f2 --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,70 @@ +name: Publish + +on: + workflow_dispatch: + inputs: + targetenv: + description: 'Target Environment' + required: true + default: 'testpypi' + type: choice + options: + - testpypi + - pypi + +permissions: + contents: write + +jobs: + overview: + name: Overview + runs-on: ubuntu-latest + steps: + - name: Job Summary + run: | + if [[ "${{ github.ref_name }}" != "main" && "${{ inputs.targetenv || 'testpypi' }}" == "pypi" ]] + then + { + echo "::error::Publishing to PyPI is only allowed from the main branch"; + exit 1; + } + fi; + echo "### Job Summary" >> $GITHUB_STEP_SUMMARY + echo "Publish to ${{ inputs.targetenv || 'testpypi' }} environment from ${{ github.ref_name }} branch." >> $GITHUB_STEP_SUMMARY + publish: + name: Publish + runs-on: windows-2022 + needs: overview + environment: ${{ inputs.targetenv || 'testpypi' }} + env: + TWINE_USERNAME: '__token__' + TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }} + steps: + - uses: actions/checkout@v3 + - name: Set up Python 3.9 + uses: actions/setup-python@v3 + with: + python-version: "3.9" + - name: Install build tools + run: | + python -m pip install --upgrade pip + pip install build~=1.0.3 twine~=4.0.2 + - name: Build + run: | + python -m build --wheel + - name: Publish distribution + run: | + twine upload --repository-url ${{ vars.PYPI_API_ENDPOINT }} dist/* + - name: Tag commit + if: ${{ (github.ref_name == 'main') || ((inputs.targetenv || 'testpypi') == 'pypi') }} + run: | + pip install --no-index --no-deps --find-links=dist/ interface-proxy + $LibVersion = python -c "import importlib.metadata; print(importlib.metadata.version('interface-proxy'))" + if ( -not (Get-ChildItem -Path dist -Filter "*${$LibVersion}*.whl")) + { + Throw "Inspected version $LibVersion could not be found in any wheels in the dist folder." + } + $TagName = "Release-${$LibVersion}_(${{ inputs.targetenv || 'testpypi' }})" + git tag $TagName + git push origin $TagName + shell: pwsh diff --git a/.github/workflows/semilinear_history.yml b/.github/workflows/semilinear_history.yml new file mode 100644 index 0000000..d339be5 --- /dev/null +++ b/.github/workflows/semilinear_history.yml @@ -0,0 +1,19 @@ +name: Check Semilinear History + +on: + pull_request: + branches: main + +permissions: + contents: read + +jobs: + semilinear_history: + name: Check Semilinear History + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - name: Check Semilinear History + shell: pwsh + run: | + .\.github\Check-SemilinearHistory.ps1 -targetBranch ${{ github.base_ref }} -sourceBranch ${{ github.head_ref }} diff --git a/.github/workflows/tox.yml b/.github/workflows/tox.yml new file mode 100644 index 0000000..d6990cd --- /dev/null +++ b/.github/workflows/tox.yml @@ -0,0 +1,27 @@ +name: Run Checks + +on: + pull_request: + branches: main + +permissions: + contents: read + +jobs: + checks: + name: Run Checks + runs-on: windows-2022 + + steps: + - uses: actions/checkout@v3 + - name: Set up Python 3.9 + uses: actions/setup-python@v3 + with: + python-version: "3.9" + - name: Install tox + run: | + python -m pip install --upgrade pip + pip install tox~=4.12.1 + - name: Run tox + run: | + tox run-parallel