Merge pull request #15 from capitec/feature/fix-default-value #39
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Build and Release | |
on: | |
push: | |
branches: | |
- main | |
- dev | |
- release/* | |
env: | |
DOCKER_IMAGE_NAME: sjnarmstrong/spockflow | |
jobs: | |
get-version: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Install dependencies | |
run: | | |
python -m pip install --upgrade pip | |
pip install versioneer setuptools | |
- name: Get version | |
id: get-package-version | |
run: | | |
version=$(python setup.py --version) | |
echo "PACKAGE_VERSION=$(python setup.py --version)" >> $GITHUB_OUTPUT | |
outputs: | |
PACKAGE_VERSION: ${{ steps.get-package-version.outputs.PACKAGE_VERSION }} | |
build-package: | |
needs: ["get-version"] | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Set up Python | |
uses: actions/setup-python@v5 | |
with: | |
python-version: '3.12.4' | |
- name: Tag Release | |
env: | |
PACKAGE_VERSION: ${{needs.get-version.outputs.PACKAGE_VERSION}} | |
run: | | |
git config --global user.email "[email protected]" | |
git config --global user.name "Sholto Armstrong" | |
git tag -a v${PACKAGE_VERSION} -m "Release v${PACKAGE_VERSION}" | |
- name: Install dependencies | |
run: | | |
python -m pip install --upgrade pip | |
pip install -r requirements/dev.txt | |
pip install -r requirements/all.txt | |
- name: Format code with Black | |
run: black --check . | |
- name: Run tests | |
run: pytest | |
- name: Build Python package | |
run: python -m build | |
- name: Upload Python package | |
uses: actions/upload-artifact@v4 | |
with: | |
name: python-package | |
path: dist/* | |
build-docs: | |
needs: ["get-version"] | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Set up Python | |
uses: actions/setup-python@v5 | |
with: | |
python-version: '3.12.4' | |
- name: Tag Release | |
env: | |
PACKAGE_VERSION: ${{needs.get-version.outputs.PACKAGE_VERSION}} | |
run: | | |
git config --global user.email "[email protected]" | |
git config --global user.name "Sholto Armstrong" | |
git tag -a v${PACKAGE_VERSION} -m "Release v${PACKAGE_VERSION}" | |
- name: Install documentation dependencies | |
run: | | |
python -m pip install --upgrade pip | |
pip install -r requirements/all.txt | |
pip install . | |
- name: Build documentation | |
run: | | |
cd docs | |
make html | |
- name: Archive artifact | |
shell: sh | |
run: | | |
echo ::group::Archive artifact | |
tar \ | |
--dereference --hard-dereference \ | |
--directory "$INPUT_PATH" \ | |
-cvf "$RUNNER_TEMP/artifact.tar" \ | |
--exclude=.git \ | |
--exclude=.github \ | |
. | |
echo ::endgroup:: | |
env: | |
INPUT_PATH: docs/_build/html/ | |
- name: Upload docs | |
uses: actions/upload-artifact@v4 | |
with: | |
name: 'github-pages' | |
path: ${{ runner.temp }}/artifact.tar | |
if-no-files-found: error | |
release: | |
needs: ["build-docs", "build-package", "get-version"] | |
runs-on: ubuntu-latest | |
environment: | |
name: pypi | |
url: https://pypi.org/p/spockflow | |
permissions: | |
id-token: write | |
pages: write | |
contents: write | |
pull-requests: write | |
repository-projects: write | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Tag Release | |
env: | |
PACKAGE_VERSION: ${{needs.get-version.outputs.PACKAGE_VERSION}} | |
run: | | |
git config --global user.email "[email protected]" | |
git config --global user.name "Github Bot" | |
git tag -a v${PACKAGE_VERSION} -m "Release v${PACKAGE_VERSION}" | |
- name: Set up Python | |
uses: actions/setup-python@v5 | |
with: | |
python-version: "3.12.4" | |
- 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.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_TOKEN }} | |
- name: Install dependencies | |
run: | | |
python -m pip install --upgrade pip | |
pip install versioneer setuptools | |
- name: Get version | |
run: | | |
version=$(python setup.py --version) | |
echo "PACKAGE_VERSION=$(python setup.py --version)" >> $GITHUB_ENV | |
- name: Download Python Artifact | |
uses: actions/download-artifact@v4 | |
with: | |
name: python-package | |
path: dist | |
- name: Build Docker image | |
uses: docker/build-push-action@v3 | |
with: | |
context: . | |
push: true | |
tags: ${{ env.DOCKER_IMAGE_NAME }}:${{ env.PACKAGE_VERSION }} | |
file: docker/Dockerfile | |
- name: Upload Latest Docker image | |
uses: docker/build-push-action@v3 | |
if: github.ref == 'refs/heads/main' | |
with: | |
context: . | |
push: true | |
tags: ${{ env.DOCKER_IMAGE_NAME }}:latest | |
file: docker/Dockerfile | |
- name: Publish distribution 📦 to PyPI | |
uses: pypa/gh-action-pypi-publish@release/v1 | |
with: | |
skip-existing: true | |
- name: Deploy documentation to GitHub Pages | |
if: github.ref == 'refs/heads/main' | |
uses: actions/deploy-pages@v4 | |
- name: Push Tag | |
env: | |
PACKAGE_VERSION: ${{needs.get-version.outputs.PACKAGE_VERSION}} | |
run: | | |
git push origin tag v${PACKAGE_VERSION} | |
- name: Create Release | |
if: github.ref == 'refs/heads/main' | |
id: release-snapshot | |
uses: actions/create-release@latest | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
tag_name: v${{needs.get-version.outputs.PACKAGE_VERSION}} | |
release_name: Release ${{needs.get-version.outputs.PACKAGE_VERSION}} | |
draft: false | |
prerelease: false | |