Skip to content
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
261 changes: 110 additions & 151 deletions .github/workflows/ci-cd.yml
Original file line number Diff line number Diff line change
@@ -1,54 +1,78 @@
name: ci-cd
name: CI-CD

# only run on pushes to main or pull requests
on:
push:
# push to any branch *
branches: ["*"]
pull_request:
branches: [main]
branches: [main, development]


jobs:
Unit-Testing:
# Set up operating system
runs-on: ubuntu-latest
################################################################################################
# Unit-Tests: Run unit tests using pytest
################################################################################################
Unit-Tests:
runs-on: ${{ matrix.os }}
timeout-minutes: 15 # Consider increasing timeout
strategy:
matrix:
os: [ubuntu-latest, macos-latest, macos-14] # , windows-latest removed for now
env: ["py310", "py311", "py312"]

# Define job steps
steps:
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.9"

- name: Check-out repository
uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Install poetry
uses: snok/install-poetry@v1

- name: Install package
run: poetry install
- name: Install Pixi
uses: prefix-dev/setup-pixi@v0.8.1
with:
environments: ${{ matrix.env }}
pixi-version: v0.33.0
cache: true
locked: false # wont be the same because of the tag

- name: Test with pytest
# Github action runners now have 4 cores
run: poetry run pytest -s -v -n 4 tests/
- name: Run pytest
run: |
pixi run -e ${{ matrix.env }} test

# Commented out until we have a repo for coverage
# - name: Test with pytest
# run: poetry run pytest tests/ --cov=readii --cov-report=xml
- name: Upload coverage report artifact to be used by Codecov
# only upload if matrix.os is ubuntu-latest and matrix.python-version is 3.12
if: matrix.os == 'ubuntu-latest' && matrix.env == 'py312'
uses: actions/upload-artifact@v4
with:
name: coverage-report
path: coverage-report

################################################################################################
# Semantic-Release: Run semantic-release to automate versioning and publishing
################################################################################################
Semantic-Release:
permissions:
# Read releases read-all
contents: write
packages: write
issues: write
pull-requests: write

needs: [Unit-Tests]

# if pulling to main, deploy to PyPI
if: github.ref == 'refs/heads/main'

# - name: Use Codecov to track coverage
# uses: codecov/codecov-action@v3
# with:
# files: ./coverage.xml # coverage report
env:
PIXI_ENV: "publish"

Continuous-Deployment:
needs: Unit-Testing

# # Only run this job if new work is pushed to "main"
if: github.ref == 'refs/heads/main'
strategy:
matrix:
os: [ubuntu-latest]
python-version: ["3.12"]

# Set up operating system
runs-on: ubuntu-latest
runs-on: ${{ matrix.os }}

# Concurrency is for preventing multiple runs of the same workflow
concurrency: release

outputs:
released: ${{ steps.release.outputs.released }}
Expand All @@ -57,132 +81,67 @@ jobs:

# Define job steps
steps:
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.9"

- name: Check-out repository
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Install poetry
uses: snok/install-poetry@v1

- name: Install package
run: poetry install

# This action uses Python Semantic Release v8
- name: Python Semantic Release
id: release
uses: python-semantic-release/python-semantic-release@master
- name: Install Pixi
uses: prefix-dev/setup-pixi@v0.8.1
env:
RUNNER_DEBUG: true
with:
github_token: ${{ secrets.GITHUB_TOKEN }}

environments: ${{ env.PIXI_ENV }}
pixi-version: v0.33.0
cache: true
locked: false
# cache-key: pixi-ENV_${{ env.PIXI_ENV }}-

- name: Print Semver
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: pixi run semver

- name: Run semantic-release
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
id: release
run: pixi run release

- name: Test Outputs of semantic release step
run: |
echo "${{ steps.release.outputs.released }}"
echo "${{ steps.release.outputs.version }}"
echo "${{ steps.release.outputs.tag }}"

Publish-To-PyPI:
needs: Continuous-Deployment
if: ${{ needs.Continuous-Deployment.outputs.released == 'true' }}
runs-on: ubuntu-latest
steps:
- name: Checkout the code with tag ${{ needs.Continuous-Deployment.outputs.tag }}
uses: actions/checkout@v3
with:
ref: ${{ needs.Continuous-Deployment.outputs.tag }}

- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: "3.9"

- name: Install poetry
uses: snok/install-poetry@v1

- name: Install Package Building Tool
run: python3 -m pip install build twine

- name: Build Package
run: |
poetry version ${{ needs.Continuous-Deployment.outputs.version }}
python -m build --sdist --wheel --outdir dist/ .
ls dist/

- name: Publish to TestPyPI
if: steps.release.outputs.released == 'true'
uses: pypa/gh-action-pypi-publish@release/v1
with:
user: __token__
password: ${{ secrets.TEST_PYPI_API_TOKEN }}
repository-url: https://test.pypi.org/legacy/

- name: Test install from TestPyPI
run: |
pip install \
--index-url https://test.pypi.org/simple/ \
--extra-index-url https://pypi.org/simple \
readii

- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
verbose: true
user: __token__
password: ${{ secrets.PYPI_API_TOKEN }}

Build-Docker-Images:
needs: [ Continuous-Deployment, Publish-To-PyPI ]
if: ${{ needs.Continuous-Deployment.outputs.released == 'true' }}
runs-on: ubuntu-latest
steps:
- name: Checkout the code with tag ${{ needs.Continuous-Deployment.outputs.tag }}
uses: actions/checkout@v3
with:
ref: ${{ needs.Continuous-Deployment.outputs.tag }}

- name: Set up QEMU
uses: docker/setup-qemu-action@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.BHKLAB_DOCKERHUB_USERNAME }}
password: ${{ secrets.BHKLAB_DOCKERHUB_ACCESS_KEY }}

- name: Login to the GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v3
with:
images: |
bhklab/readii:${{ needs.Continuous-Deployment.outputs.tag }}
ghcr.io/${{ github.repository }}/readii:${{ needs.Continuous-Deployment.outputs.tag }}
- name: Build
uses: docker/build-push-action@v5
with:
context: .
# platforms: macos/amd64,linux/amd64, macos/arm64, linux/arm64
# slim-buster only supports linux/{amd64,arm64}
platforms: linux/amd64
file: ./Dockerfile
push: true
tags: |
bhklab/readii:${{ needs.Continuous-Deployment.outputs.tag }}
bhklab/readii:latest
ghcr.io/${{ github.repository }}/readii:${{ needs.Continuous-Deployment.outputs.tag }}
ghcr.io/${{ github.repository }}/readii:latest
labels: ${{ steps.meta.outputs.labels }}
################################################################################################
# Publish-To-PyPi & Test-PyPi-Installation: Publish to PyPI and test installation
################################################################################################
# Publish-To-PyPi:
# needs: Semantic-Release
# env:
# PIXI_ENV: "publish"
# # if: needs.Semantic-Release.outputs.released == 'true'
# strategy:
# matrix:
# os: [ubuntu-latest]

# runs-on: ${{ matrix.os }}
# steps:
# - name: Checkout the code with tag ${{ needs.Semantic-Release.outputs.tag }}
# uses: actions/checkout@v4
# with:
# ref: ${{ needs.Semantic-Release.outputs.tag }}

# - name: Install Pixi
# uses: prefix-dev/setup-pixi@v0.8.1
# with:
# environments: ${{ env.PIXI_ENV }}
# pixi-version: v0.33.0
# # cache-key: pixi-ENV_${{ env.PIXI_ENV }}-
# cache: true
# locked: false # wont be the same because of the tag

# - name: Test Build
# run: |
# pixi run -e ${{ env.PIXI_ENV }} build
Loading
Loading