Skip to content

Commit

Permalink
Merge pull request #11 from bergsalex/task/update-cicd-for-consistency
Browse files Browse the repository at this point in the history
Adding same cicd defs as in rest of gw suite
  • Loading branch information
bergsalex authored Nov 15, 2023
2 parents 4e08770 + dd21eb0 commit bf19f31
Show file tree
Hide file tree
Showing 7 changed files with 138 additions and 41 deletions.
65 changes: 65 additions & 0 deletions .github/workflows/_check-coverage-action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
name: 'Test Coverage Definition'
on:
workflow_call:
inputs:
coverage-module:
description: "Module to test coverage for"
type: string
required: true
python-version:
description: Python version to set up'
default: '3.11'
type: string
runner-os:
description: 'Runner OS'
default: 'ubuntu-latest'
type: string
upload-coverage:
description: 'Upload coverage results'
default: true
type: boolean
required-coverage:
description: 'Required coverage percentage'
default: 100
type: string
show-test-traceback:
description: "Show traceback for failed tests"
type: string
default: "no"
jobs:
run-tests:
runs-on: ${{ inputs.runner-os }}
steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ inputs.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ inputs.python-version }}
- name: Install Poetry
run: |
curl -sSL https://install.python-poetry.org | python3 -
if [[ "$RUNNER_OS" == "macOS" ]]; then
echo "/Users/runner/.local/bin:$PATH" >> $GITHUB_PATH
fi
- name: Configure Poetry
run: poetry config virtualenvs.create false
- name: Install dependencies with Poetry
run: poetry install
- name: Test with pytest
run: |
poetry run pytest tests \
--tb=${{ inputs.show-test-traceback }} \
--cov=${{ inputs.coverage-module }} \
--cov-report=term \
--cov-report=html \
--cov-fail-under=${{ inputs.required-coverage }} > coverage_report.txt
- name: Upload coverage report
uses: actions/upload-artifact@v3
with:
name: coverage-report
path: coverage_report.txt
- name: Upload coverage report
uses: actions/upload-artifact@v3
with:
name: coverage-report-html
path: htmlcov
2 changes: 1 addition & 1 deletion .github/workflows/_format-lint-action.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: 'Lint Code'
name: 'Lint Code Definition'
on:
workflow_call:
inputs:
Expand Down
16 changes: 6 additions & 10 deletions .github/workflows/_run-tests-action.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: 'Run Python Tests'
name: 'Python Tests Definition'
on:
workflow_call:
inputs:
Expand All @@ -16,6 +16,10 @@ on:
description: 'Upload coverage results'
default: true
type: boolean
required-coverage:
description: 'Required coverage percentage'
default: 75
type: string
jobs:
run-tests:
runs-on: ${{ inputs.runner-os }}
Expand All @@ -37,12 +41,4 @@ jobs:
run: poetry install
- name: Test with pytest
run: |
poetry run pytest tests \
--cov=geneweaver.tools.boolean_algebra \
--cov-report=term \
--cov-fail-under=100 > coverage_report.txt
- name: Upload coverage report
uses: actions/upload-artifact@v3
with:
name: coverage-report
path: coverage_report.txt
poetry run pytest tests
27 changes: 11 additions & 16 deletions .github/workflows/run-tests.yml → .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
@@ -1,24 +1,19 @@
name: Lint Code and Run Tests
name: Coverage
on:
pull_request:
branches: [ main ]
branches:
- 'main'
push:
branches:
- 'main'
jobs:
format-lint:
uses: ./.github/workflows/_format-lint-action.yml
check-coverage:
uses: ./.github/workflows/_check-coverage-action.yml
with:
python-version: '3.9'
test:
needs: format-lint
strategy:
matrix:
os: [ubuntu-latest, macos-latest]
python-version: ['3.9', '3.10', '3.11']
uses: ./.github/workflows/_run-tests-action.yml
with:
runner-os: ${{ matrix.os }}
python-version: ${{ matrix.python-version }}
required-coverage: 100
coverage-module: "geneweaver.tools.boolean_algebra"
comment-coverage-report:
needs: [ test ]
needs: [ check-coverage ]
runs-on: ubuntu-latest
if: github.event_name == 'pull_request'
permissions:
Expand Down
37 changes: 23 additions & 14 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
name: Release to PyPI on Version Change
name: Release to PyPI

on:
push:
branches: [ main ]
paths: ['pyproject.toml']
branches:
- 'main'
paths:
- 'pyproject.toml'

permissions:
contents: write
Expand All @@ -20,6 +22,7 @@ jobs:
python-version: '3.9'
runner-os: 'ubuntu-latest'
upload-coverage: false
required-coverage: ${{ vars.REQUIRED_COVERAGE }}
release:
needs: test
runs-on: ubuntu-latest
Expand All @@ -42,15 +45,15 @@ jobs:
# Extract version from pyproject.toml
version=$(python -c "import toml; print(toml.load('pyproject.toml')['tool']['poetry']['version'])")
echo "Version=$version"
echo "{version}={$version}" >> $GITHUB_OUTPUT
echo "version=$version" >> $GITHUB_OUTPUT
# Check if this version tag already exists
if git rev-parse "v$version" >/dev/null 2>&1; then
echo "Version already released"
echo "{should_release}={true}" >> $GITHUB_OUTPUT
echo "should_release=true" >> $GITHUB_OUTPUT
else
echo "New version detected"
echo "{should_release}={false}" >> $GITHUB_OUTPUT
echo "should_release=false" >> $GITHUB_OUTPUT
fi
- name: Determine Release Type
Expand All @@ -59,38 +62,44 @@ jobs:
version=$(python -c "import toml; print(toml.load('pyproject.toml')['tool']['poetry']['version'])")
if [[ $version =~ [a-zA-Z] ]]; then
echo "Pre-release version detected"
echo "{prerelease}={true}" >> $GITHUB_OUTPUT
echo "prerelease=true" >> $GITHUB_OUTPUT
else
echo "Full release version detected"
echo "{prerelease}={false}" >> $GITHUB_OUTPUT
echo "prerelease=false" >> $GITHUB_OUTPUT
fi
- name: Install Poetry
if: steps.version_check.outputs.should_release == 'true'
if: ${{ steps.version_check.outputs.should_release }} == 'true'
run: |
curl -sSL https://install.python-poetry.org | python3 -
- name: Build and Publish to PyPI
if: steps.version_check.outputs.should_release == 'true'
if: ${{ steps.version_check.outputs.should_release }} == 'true'
env:
POETRY_PYPI_TOKEN_PYPI: ${{ secrets.PYPI_API_TOKEN }}
run: |
echo "Should Release: ${{ steps.version_check.outputs.should_release }}"
echo "Is Pre-release: ${{ steps.release_type.outputs.prerelease }}"
echo "v${{ steps.version_check.outputs.version }}"
echo "$PATH"
echo "$(python --version)"
poetry build
poetry publish
- name: Create GitHub Release
uses: actions/create-release@v1
if: steps.version_check.outputs.should_release == 'true'
uses: softprops/action-gh-release@v1
if: ${{ steps.version_check.outputs.should_release }} == 'true'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: v${{ steps.version_check.outputs.version }}
release_name: Release v${{ steps.version_check.outputs.version }}
name: Release v${{ steps.version_check.outputs.version }}
draft: false
prerelease: ${{ steps.release_type.outputs.prerelease }}
body: |
Release v${{ steps.version_check.outputs.version }}
PyPI: https://pypi.org/project/geneweaver-boolean-algebra/${{ steps.version_check.outputs.version }}/
files: |
dist/*
LICENSE
README.md
13 changes: 13 additions & 0 deletions .github/workflows/style.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
name: Style
on:
pull_request:
branches:
- 'main'
push:
branches:
- 'main'
jobs:
format-lint:
uses: ./.github/workflows/_format-lint-action.yml
with:
python-version: '3.9'
19 changes: 19 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: Tests
on:
pull_request:
branches:
- 'main'
push:
branches:
- 'main'
jobs:
test:
strategy:
matrix:
os: [ubuntu-latest, macos-latest]
python-version: ['3.9', '3.10', '3.11']
uses: ./.github/workflows/_run-tests-action.yml
with:
runner-os: ${{ matrix.os }}
python-version: ${{ matrix.python-version }}
required-coverage: ${{ vars.REQUIRED_COVERAGE }}

0 comments on commit bf19f31

Please sign in to comment.