Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build: add semantic release to CI/CD #26

Merged
merged 5 commits into from
Dec 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 29 additions & 13 deletions .github/workflows/cd.yaml
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
name: Continuous Delivery of Python package

on:
push:
branches:
- main
workflow_dispatch:
inputs:
run_checks:
description: "Run checks?"
type: boolean
required: true
default: true
production_release:
description: "Production release?"
type: boolean
Expand All @@ -19,13 +21,8 @@ permissions:
packages: read

jobs:
ci-check-python:
name: Check Python
uses: ./.github/workflows/check-python.yaml

release:
name: Release Library
needs: ci-check-python
runs-on: ubuntu-latest
permissions:
# IMPORTANT: this permission is mandatory for trusted publishing
Expand All @@ -49,7 +46,16 @@ jobs:
cache: "poetry"

- name: Install dependencies
run: poetry install --no-interaction --no-root
run: poetry install --no-interaction --with cicd

- name: pre-commit and pytest
if: inputs.run_checks
run: |
set -o pipefail
source $(poetry env info --path)/bin/activate
pre-commit run --all-files && git diff --exit-code
algokit localnet start
pytest

- name: Get branch name
shell: bash
Expand All @@ -59,11 +65,21 @@ jobs:
- name: Set Git user as GitHub actions
run: git config --global user.email "[email protected]" && git config --global user.name "github-actions"

- name: Create Continuous Deployment - Production
- name: Update release - Production
if: steps.get_branch.outputs.branch == 'main' && inputs.production_release
run: |
poetry build --format wheel
run: semantic-release version

- name: Update release - Prerelease
if: steps.get_branch.outputs.branch == 'main' && !inputs.production_release
run: semantic-release version --prerelease

- name: Create Wheel
run: poetry build --format wheel

- name: Publish to GitHub
if: steps.get_branch.outputs.branch == 'main'
run: semantic-release publish

- name: Publish package distributions to PyPI
- name: Publish to PyPI
if: steps.get_branch.outputs.branch == 'main' && inputs.production_release
uses: pypa/gh-action-pypi-publish@release/v1
13 changes: 3 additions & 10 deletions .github/workflows/check-python.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,30 +24,23 @@ jobs:
cache: "poetry"

- name: Install dependencies
run: poetry install --no-interaction
run: poetry install --no-interaction --with cicd

- name: Check pre-commits
run: |
set -o pipefail
poetry run pre-commit run --all-files && git diff --exit-code

- name: Install algokit
run: pipx install algokit

- name: Start LocalNet
run: algokit localnet start
run: poetry run algokit localnet start

- name: pytest + coverage
shell: bash
run: |
set -o pipefail
poetry run pytest --junitxml=pytest-junit.xml --cov | tee pytest-coverage.txt

- name: Stop LocalNet
run: algokit localnet stop

- name: pytest coverage comment - using Python 3.12 on ubuntu-latest
if: matrix.python == '3.12' && matrix.os == 'ubuntu-latest'
- name: pytest coverage comment
continue-on-error: true # forks fail to add a comment, so continue any way
uses: MishaKav/pytest-coverage-comment@main
with:
Expand Down
Loading
Loading