2021-11-28 13:38:46 +01:00
|
|
|
name: 'Build CraftBeerPi4'
|
2021-11-27 16:14:14 +01:00
|
|
|
|
|
|
|
on:
|
|
|
|
push:
|
|
|
|
branches:
|
|
|
|
- main
|
|
|
|
- master
|
|
|
|
- development
|
2021-11-27 21:34:22 +01:00
|
|
|
pull_request:
|
2021-11-27 16:14:14 +01:00
|
|
|
|
2023-03-07 06:45:33 +01:00
|
|
|
env:
|
2023-03-07 07:50:52 +01:00
|
|
|
IMAGE_NAME: ghcr.io/${{ github.repository_owner }}/craftbeerpi4
|
2021-11-27 16:14:14 +01:00
|
|
|
|
|
|
|
jobs:
|
2021-11-27 21:17:00 +01:00
|
|
|
build:
|
|
|
|
runs-on: ubuntu-latest
|
2023-03-07 14:07:01 +01:00
|
|
|
permissions:
|
|
|
|
packages: write
|
2021-11-28 13:38:46 +01:00
|
|
|
name: Builds the source distribution package
|
2021-11-27 21:17:00 +01:00
|
|
|
steps:
|
2023-03-07 07:08:47 +01:00
|
|
|
|
2021-11-27 21:17:00 +01:00
|
|
|
- name: Checkout source
|
2024-12-07 15:19:27 +01:00
|
|
|
uses: actions/checkout@v4
|
2021-11-27 21:17:00 +01:00
|
|
|
|
|
|
|
- name: Setup python environment
|
2024-12-07 15:19:27 +01:00
|
|
|
uses: actions/setup-python@v4
|
2021-11-27 21:17:00 +01:00
|
|
|
with:
|
2024-05-02 18:07:57 +02:00
|
|
|
python-version: '3.11'
|
|
|
|
|
|
|
|
- name: Install packages
|
|
|
|
run: sudo apt install -y libsystemd-dev
|
2021-11-27 21:17:00 +01:00
|
|
|
|
|
|
|
- name: Clean
|
|
|
|
run: python setup.py clean --all
|
|
|
|
|
2022-02-20 12:07:13 +01:00
|
|
|
- name: Install Requirements
|
|
|
|
run: pip3 install -r requirements.txt
|
|
|
|
|
|
|
|
- name: Run tests
|
|
|
|
run: coverage run --source cbpi -m pytest tests
|
2021-11-27 21:17:00 +01:00
|
|
|
|
|
|
|
- name: Build source distribution package for CraftBeerPi
|
|
|
|
run: python setup.py sdist
|
|
|
|
|
|
|
|
- name: Upload CraftBeerPi package to be used in next step
|
2024-12-07 15:19:27 +01:00
|
|
|
uses: actions/upload-artifact@v4
|
2021-11-27 21:17:00 +01:00
|
|
|
with:
|
|
|
|
name: craftbeerpi4
|
2022-05-11 07:47:06 +02:00
|
|
|
path: dist/cbpi4-*.tar.gz
|
2021-11-27 21:17:00 +01:00
|
|
|
if-no-files-found: error
|
|
|
|
|
2021-11-27 16:14:14 +01:00
|
|
|
docker:
|
|
|
|
runs-on: ubuntu-latest
|
2021-11-28 13:38:46 +01:00
|
|
|
name: Builds the docker image(s)
|
2021-11-27 16:14:14 +01:00
|
|
|
steps:
|
|
|
|
- name: Checkout
|
2024-12-07 15:19:27 +01:00
|
|
|
uses: actions/checkout@v4
|
2021-11-27 16:14:14 +01:00
|
|
|
|
|
|
|
- name: Prepare docker image and tag names
|
|
|
|
id: prep
|
|
|
|
run: |
|
|
|
|
|
2023-03-07 07:50:52 +01:00
|
|
|
IMAGE_NAME_LOWERCASE=${IMAGE_NAME,,}
|
|
|
|
echo "Using image name $IMAGE_NAME_LOWERCASE"
|
|
|
|
|
2021-11-27 21:34:22 +01:00
|
|
|
PUBLISH_IMAGE=false
|
2023-03-07 07:50:52 +01:00
|
|
|
TAGS="$IMAGE_NAME_LOWERCASE:dev"
|
2021-11-27 21:34:22 +01:00
|
|
|
|
2021-12-04 12:23:56 +01:00
|
|
|
# Define the image that will be used as a cached image
|
|
|
|
# to speed up the build process
|
|
|
|
BUILD_CACHE_IMAGE_NAME=${TAGS}
|
|
|
|
|
2021-11-27 16:14:14 +01:00
|
|
|
if [[ $GITHUB_REF_NAME == master ]] || [[ $GITHUB_REF_NAME == main ]]; then
|
|
|
|
# when building master/main use :latest tag and the version number
|
|
|
|
# from the cbpi/__init__.py file
|
2022-03-15 08:13:00 +01:00
|
|
|
VERSION=$(grep -o -E "(([0-9]{1,2}[.]?){2,3}[0-9]+)" cbpi/__init__.py)
|
2023-03-07 07:50:52 +01:00
|
|
|
LATEST_IMAGE=$IMAGE_NAME_LOWERCASE:latest
|
2021-12-04 12:23:56 +01:00
|
|
|
BUILD_CACHE_IMAGE_NAME=${LATEST_IMAGE}
|
2023-03-07 07:50:52 +01:00
|
|
|
TAGS="${LATEST_IMAGE},$IMAGE_NAME_LOWERCASE:v${VERSION}"
|
|
|
|
PUBLISH_IMAGE="true"
|
2021-11-27 21:34:22 +01:00
|
|
|
elif [[ $GITHUB_REF_NAME == development ]]; then
|
2023-03-07 07:50:52 +01:00
|
|
|
PUBLISH_IMAGE="true"
|
2021-11-27 16:14:14 +01:00
|
|
|
fi
|
|
|
|
|
2023-03-07 07:50:52 +01:00
|
|
|
|
|
|
|
echo "tags: $TAGS"
|
|
|
|
echo "publish_image: $PUBLISH_IMAGE"
|
|
|
|
echo "cache_name: $BUILD_CACHE_IMAGE_NAME"
|
|
|
|
echo "tags=$TAGS" >> $GITHUB_OUTPUT
|
|
|
|
echo "publish_image=$PUBLISH_IMAGE" >> $GITHUB_OUTPUT
|
|
|
|
echo "cache_name=$BUILD_CACHE_IMAGE_NAME" >> $GITHUB_OUTPUT
|
2021-11-27 16:14:14 +01:00
|
|
|
|
|
|
|
- name: Set up QEMU
|
|
|
|
uses: docker/setup-qemu-action@master
|
|
|
|
with:
|
|
|
|
platforms: all
|
|
|
|
|
|
|
|
- name: Set up Docker Buildx
|
|
|
|
id: buildx
|
|
|
|
uses: docker/setup-buildx-action@master
|
|
|
|
|
|
|
|
- name: Login to GitHub Container Registry
|
2023-03-07 07:50:52 +01:00
|
|
|
uses: docker/login-action@v2
|
2021-11-27 16:14:14 +01:00
|
|
|
with:
|
|
|
|
registry: ghcr.io
|
|
|
|
username: ${{ github.repository_owner }}
|
|
|
|
password: ${{ secrets.GITHUB_TOKEN }}
|
|
|
|
|
|
|
|
- name: Build
|
2023-03-07 07:50:52 +01:00
|
|
|
uses: docker/build-push-action@v4
|
2021-11-27 16:14:14 +01:00
|
|
|
with:
|
|
|
|
builder: ${{ steps.buildx.outputs.name }}
|
|
|
|
context: .
|
|
|
|
file: ./Dockerfile
|
|
|
|
platforms: linux/amd64,linux/arm64
|
2021-12-04 12:09:46 +01:00
|
|
|
target: deploy
|
2023-03-07 07:50:52 +01:00
|
|
|
push: ${{ steps.prep.outputs.publish_image == 'true' }}
|
2021-11-27 16:14:14 +01:00
|
|
|
tags: ${{ steps.prep.outputs.tags }}
|
2023-03-07 07:50:52 +01:00
|
|
|
cache-from: type=registry,ref=${{ steps.prep.outputs.cache_name }}
|
2021-12-04 12:26:48 +01:00
|
|
|
cache-to: type=inline
|
2021-11-27 16:14:14 +01:00
|
|
|
labels: |
|
|
|
|
org.opencontainers.image.title=${{ github.event.repository.name }}
|
|
|
|
org.opencontainers.image.description=${{ github.event.repository.description }}
|
|
|
|
org.opencontainers.image.url=${{ github.event.repository.html_url }}
|
|
|
|
org.opencontainers.image.revision=${{ github.sha }}
|