Skip to content

Build

Build #78

Workflow file for this run

name: Build
on:
pull_request:
merge_group:
push:
branches:
- develop
tags:
- '*'
env:
DOCKER_IMAGE_NAME: tools4homeautomation/varta-exporter
jobs:
Build:
name: Build and Test on ${{ matrix.python }} and ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: ['macos-latest', 'ubuntu-latest']
python: ['pypy3.9', 'pypy3.10', '3.9', '3.10', '3.11', '3.12']
steps:
- uses: actions/checkout@v6
- name: Set up Python ${{ matrix.python }}
uses: actions/setup-python@v6
with:
python-version: ${{ matrix.python }}
- name: Install dependencies
id: install-deps
run: |
cd app
pip3 install -r requirements.txt
- name: Write version vars
id: version-vars
run: |
BUILD_DATE=`date -u +"%Y-%m-%dT%H:%M:%SZ"`
BRANCH=${GITHUB_REF_NAME#v}
APP_VERSION=$(cat config.json | grep version| head -1 | awk -F: '{ print $2 }' | sed 's/[",]//g')
echo Version: $APP_VERSION
echo "VERSION=$APP_VERSION" >> $GITHUB_ENV
echo "APP_VERSION=$APP_VERSION" >> $GITHUB_ENV
echo "BUILD_DATE=$BUILD_DATE" >> $GITHUB_ENV
Container:
name: Build Container Image
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- name: Write version vars
id: version-vars
run: |
BUILD_DATE=`date -u +"%Y-%m-%dT%H:%M:%SZ"`
BRANCH=${GITHUB_REF_NAME#v}
APP_VERSION=$(cat config.json | grep version| head -1 | awk -F: '{ print $2 }' | sed 's/[",]//g' | sed 's/ //g')
echo Version: $APP_VERSION
/bin/cat <<EOM >>$GITHUB_ENV
VERSION=$APP_VERSION
APP_VERSION=$APP_VERSION
BUILD_DATE=$BUILD_DATE
EOM
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v4
- name: Login to Docker Hub
uses: docker/login-action@v4
with:
username: ${{ vars.DOCKER_HUB_USER }}
password: ${{ secrets.DOCKER_HUB_TOKEN }}
- name: Build Docker image
id: build-image
uses: docker/build-push-action@v7
with:
context: .
file: ./Dockerfile
push: false
tags: |
${{env.DOCKER_IMAGE_NAME}}:next
build-args: |
BUILD_DATE=${{env.BUILD_DATE}}
APP_VERSION=${{env.APP_VERSION}}
platforms: linux/amd64,linux/arm64,linux/arm/v7
- name: Push To Docker Hub
id: push-to-dockerhub-preview
uses: docker/build-push-action@v7
with:
context: .
file: ./Dockerfile
push: true
tags: |
${{env.DOCKER_IMAGE_NAME}}:next
${{env.DOCKER_IMAGE_NAME}}:${{env.APP_VERSION}}_rc
build-args: |
BUILD_DATE=${{env.BUILD_DATE}}
APP_VERSION=${{env.APP_VERSION}}
platforms: linux/amd64,linux/arm64,linux/arm/v7
if: github.ref == 'refs/heads/develop'
- name: Push To Docker Hub
id: push-to-dockerhub-tagged
uses: docker/build-push-action@v7
with:
context: .
file: ./Dockerfile
push: true
tags: |
${{env.DOCKER_IMAGE_NAME}}:latest
${{env.DOCKER_IMAGE_NAME}}:${{env.BRANCH}}
build-args: |
BUILD_DATE=${{env.BUILD_DATE}}
APP_VERSION=${{env.BRANCH}}
platforms: linux/amd64,linux/arm64,linux/arm/v7
if: github.ref_type == 'tag' || github.tag != ''
Build-results:
name: Build results
if: ${{ always() }}
runs-on: ubuntu-latest
needs:
- Build
- Container
steps:
- run: exit 1
# see https://stackoverflow.com/a/67532120/4907315
if: >-
${{
contains(needs.*.result, 'failure')
|| contains(needs.*.result, 'cancelled')
|| contains(needs.*.result, 'skipped')
}}