2024-10-25 14:03:43 +02:00
|
|
|
on:
|
2024-11-03 19:12:28 +01:00
|
|
|
push:
|
2024-10-28 18:33:23 +01:00
|
|
|
workflow_dispatch:
|
2024-11-03 19:12:28 +01:00
|
|
|
inputs:
|
2024-11-03 19:26:43 +01:00
|
|
|
verbose:
|
|
|
|
description: "Verbose"
|
|
|
|
required: false
|
|
|
|
default: false
|
|
|
|
type: boolean
|
2024-11-03 19:12:28 +01:00
|
|
|
build:
|
|
|
|
description: "Build container"
|
|
|
|
required: true
|
2024-11-03 19:34:33 +01:00
|
|
|
default: false
|
2024-11-03 19:12:28 +01:00
|
|
|
type: boolean
|
2024-10-26 00:33:57 +02:00
|
|
|
|
2024-10-25 14:03:43 +02:00
|
|
|
jobs:
|
2024-11-03 19:26:43 +01:00
|
|
|
test:
|
|
|
|
runs-on: container
|
|
|
|
container:
|
2024-12-06 03:05:43 +01:00
|
|
|
image: code.philo.ydns.eu/philorg/treetrail-backend-ci
|
2024-11-03 19:26:43 +01:00
|
|
|
volumes:
|
|
|
|
- "uv_cache:/root/.cache/uv"
|
|
|
|
- "ca-cert:/etc/containers/certs.d"
|
|
|
|
services:
|
|
|
|
treetrail-database:
|
2024-12-06 03:05:43 +01:00
|
|
|
image: code.philo.ydns.eu/philorg/treetrail-database
|
2024-11-03 19:26:43 +01:00
|
|
|
steps:
|
|
|
|
- name: Echo env
|
|
|
|
if: ${{ inputs.verbose }}
|
|
|
|
run: |
|
|
|
|
echo '${{ toJSON(env) }}'
|
|
|
|
|
|
|
|
- uses: actions/checkout@v4
|
|
|
|
|
|
|
|
- name: Install app with 'uv pip install'
|
|
|
|
run: uv pip install --python=$UV_PROJECT_ENVIRONMENT --no-deps .
|
|
|
|
|
|
|
|
- name: Run tests (API call)
|
|
|
|
run: pytest -s tests/basic.py
|
|
|
|
|
2024-11-03 02:18:01 +01:00
|
|
|
build:
|
|
|
|
runs-on: container
|
2024-11-03 19:26:43 +01:00
|
|
|
needs: test
|
2024-11-03 02:18:01 +01:00
|
|
|
steps:
|
|
|
|
- uses: actions/checkout@v4
|
2024-11-03 19:12:28 +01:00
|
|
|
with:
|
|
|
|
fetch-depth: 0
|
2024-11-03 02:18:01 +01:00
|
|
|
|
|
|
|
- name: Get the version from git
|
|
|
|
id: version
|
|
|
|
run: echo "version=$(git describe --dirty --tags)" >> $GITHUB_OUTPUT
|
|
|
|
|
2024-11-03 19:12:28 +01:00
|
|
|
- name: Check if the container should be built
|
|
|
|
id: builder
|
|
|
|
env:
|
|
|
|
RUN: ${{ toJSON(inputs.build || !contains(steps.version.outputs.version, '-')) }}
|
|
|
|
run: |
|
|
|
|
echo "run=$RUN" >> $GITHUB_OUTPUT
|
|
|
|
echo "Run build: $RUN"
|
|
|
|
|
2024-12-06 03:05:43 +01:00
|
|
|
- name: Info - version and test if the git version is clean (then python package and image container should be built)
|
2024-11-03 19:12:28 +01:00
|
|
|
env:
|
|
|
|
VERSION: ${{ steps.version.outputs.version }}
|
|
|
|
RUN: ${{ steps.builder.outputs.run }}
|
|
|
|
FORCE: ${{ toJSON(inputs.build) }}
|
|
|
|
run: |
|
|
|
|
echo "Version $VERSION, force (manual input): $FORCE, run the build: $RUN"
|
|
|
|
|
2024-12-06 03:05:43 +01:00
|
|
|
- name: Set the version in pyproject.toml (workaround for uv not supporting dynamic version)
|
|
|
|
if: fromJSON(steps.builder.outputs.run)
|
|
|
|
env:
|
|
|
|
VERSION: ${{ steps.version.outputs.version }}
|
|
|
|
run: sed "s/0.0.0/${VERSION}/" -i pyproject.toml
|
|
|
|
|
2024-10-29 04:07:43 +01:00
|
|
|
- name: Workaround for bug of podman-login
|
2024-11-03 19:12:28 +01:00
|
|
|
if: fromJSON(steps.builder.outputs.run)
|
2024-10-29 04:09:46 +01:00
|
|
|
run: |
|
2024-11-01 13:59:33 +01:00
|
|
|
mkdir -p $HOME/.docker
|
2024-10-29 04:09:46 +01:00
|
|
|
echo "{ \"auths\": {} }" > $HOME/.docker/config.json
|
2024-10-29 04:07:43 +01:00
|
|
|
|
2024-11-02 05:30:27 +01:00
|
|
|
- name: Log in to the container registry (with another workaround)
|
2024-11-03 19:12:28 +01:00
|
|
|
if: fromJSON(steps.builder.outputs.run)
|
2024-10-28 18:28:13 +01:00
|
|
|
uses: actions/podman-login@v1
|
2024-10-28 18:11:26 +01:00
|
|
|
with:
|
2024-10-28 18:40:34 +01:00
|
|
|
registry: ${{ vars.REGISTRY }}
|
2024-10-28 18:11:26 +01:00
|
|
|
username: ${{ secrets.REGISTRY_USER }}
|
|
|
|
password: ${{ secrets.REGISTRY_PASSWORD }}
|
2024-10-29 03:54:33 +01:00
|
|
|
auth_file_path: /tmp/auth.json
|
2024-10-28 18:11:26 +01:00
|
|
|
|
2024-11-03 04:11:35 +01:00
|
|
|
- name: Build the container image
|
2024-11-03 19:12:28 +01:00
|
|
|
if: fromJSON(steps.builder.outputs.run)
|
2024-11-03 04:11:35 +01:00
|
|
|
uses: actions/buildah-build@v1
|
|
|
|
with:
|
|
|
|
image: treetrail-backend
|
|
|
|
oci: true
|
|
|
|
labels: treetrail-backend
|
|
|
|
tags: ${{ steps.version.outputs.version }}
|
|
|
|
containerfiles: |
|
|
|
|
./Containerfile
|
2024-11-04 04:17:55 +01:00
|
|
|
build-args: |
|
2024-11-04 23:15:01 +01:00
|
|
|
APP_VERSION=${{ steps.version.outputs.version }}
|
2024-11-03 04:11:35 +01:00
|
|
|
|
2024-12-06 20:07:13 +01:00
|
|
|
- name: Push the image to the registry (version tag)
|
2024-11-03 19:12:28 +01:00
|
|
|
if: fromJSON(steps.builder.outputs.run)
|
2024-11-02 05:30:27 +01:00
|
|
|
uses: actions/push-to-registry@v2
|
2024-10-25 14:03:43 +02:00
|
|
|
with:
|
2024-12-05 18:59:55 +01:00
|
|
|
registry: "docker://${{ vars.REGISTRY }}/${{ vars.ORGANISATION }}"
|
2024-10-27 02:09:13 +02:00
|
|
|
image: treetrail-backend
|
2024-11-03 02:18:01 +01:00
|
|
|
tags: ${{ steps.version.outputs.version }}
|
2024-12-06 05:04:39 +01:00
|
|
|
|
2024-12-06 20:07:13 +01:00
|
|
|
- name: Push the image to the registry (latest tag)
|
|
|
|
if: fromJSON(steps.builder.outputs.run)
|
|
|
|
uses: actions/push-to-registry@v2
|
|
|
|
with:
|
|
|
|
registry: "docker://${{ vars.REGISTRY }}/${{ vars.ORGANISATION }}"
|
|
|
|
image: treetrail-backend
|
|
|
|
tags: latest
|
|
|
|
|
2024-12-06 05:04:39 +01:00
|
|
|
- name: Install uv
|
2024-12-06 05:08:05 +01:00
|
|
|
uses: astral-sh/setup-uv@v4
|
2024-12-06 05:04:39 +01:00
|
|
|
with:
|
|
|
|
version: "0.5.5"
|
|
|
|
|
|
|
|
- name: Build python package
|
|
|
|
if: fromJSON(steps.builder.outputs.run)
|
|
|
|
run: uv build --wheel
|
|
|
|
|
|
|
|
- name: Publish Python package (home)
|
|
|
|
if: fromJSON(steps.builder.outputs.run)
|
|
|
|
env:
|
|
|
|
LOCAL_PYPI_TOKEN: ${{ secrets.LOCAL_PYPI_TOKEN }}
|
|
|
|
run: uv publish --publish-url https://code.philo.ydns.eu/api/packages/philorg/pypi --token $LOCAL_PYPI_TOKEN
|