Skip to content

Commit

Permalink
Add github checks
Browse files Browse the repository at this point in the history
  • Loading branch information
fk3 committed Feb 9, 2024
1 parent 829c747 commit bfd3178
Show file tree
Hide file tree
Showing 7 changed files with 205 additions and 0 deletions.
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* @fk3
28 changes: 28 additions & 0 deletions .github/Check-SemilinearHistory.ps1
Original file line number Diff line number Diff line change
@@ -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."
}
34 changes: 34 additions & 0 deletions .github/check_version_uniqueness.py
Original file line number Diff line number Diff line change
@@ -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)
26 changes: 26 additions & 0 deletions .github/workflows/check_version.yml
Original file line number Diff line number Diff line change
@@ -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
70 changes: 70 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -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
19 changes: 19 additions & 0 deletions .github/workflows/semilinear_history.yml
Original file line number Diff line number Diff line change
@@ -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 }}
27 changes: 27 additions & 0 deletions .github/workflows/tox.yml
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit bfd3178

Please sign in to comment.