Skip to content

Merge pull request #75 from DerOetzi/dependabot/pip/pip-aed9f6bbcd #552

Merge pull request #75 from DerOetzi/dependabot/pip/pip-aed9f6bbcd

Merge pull request #75 from DerOetzi/dependabot/pip/pip-aed9f6bbcd #552

Workflow file for this run

name: build-project
on:
push:
pull_request:
branches: main
release:
types: [published]
env:
REGISTRY_GITHUB: ghcr.io
IMAGE_NAME: ${{ github.repository }}
PACKAGE_BRANCHES: '["main", "forecast", "homeassistant-auto-discovery"]'
jobs:
variables:
outputs:
ref_name: ${{ steps.var.outputs.ref_name}}
runs-on: "ubuntu-latest"
steps:
- name: Setting global variables
uses: actions/github-script@v7
id: var
with:
script: |
core.setOutput('ref_name', '${{ github.ref_name }}'.toLowerCase().replaceAll(/[/.]/g, '-').trim('-'));
build-service:
runs-on: ubuntu-latest
needs: [variables]
env:
REF_NAME: ${{ needs.variables.outputs.ref_name }}
permissions:
id-token: write
contents: write
strategy:
matrix:
python-version:
- "3.10"
- "3.11"
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Cache Python packages
uses: actions/cache@v4
with:
path: |
~/.cache/pip
!~/.cache/pip/log
key: ${{ runner.os }}-python-${{ matrix.python-version }}-pip-${{ hashFiles('**/requirements.txt') }}
restore-keys: |
${{ runner.os }}-python-${{ matrix.python-version }}-pip-
${{ runner.os }}-python-${{ matrix.python-version }}-
${{ runner.os }}-python-
${{ runner.os }}-pip-
- name: Install build package
run: |
python -m pip install --upgrade pip
pip install build
- name: Build package
run: python -m build
- name: Save python artifacts
uses: actions/upload-artifact@v4
with:
name: python-artifacts-${{ matrix.python-version }}-${{ env.REF_NAME }}
path: |
dist
- name: Publish package to pypi
if: ${{github.event_name == 'release' && matrix.python-version == '3.11'}}
uses: pypa/gh-action-pypi-publish@release/v1
with:
packages-dir: dist/
- name: Publish assets to github
if: ${{github.event_name == 'release' && matrix.python-version == '3.11'}}
uses: svenstaro/upload-release-action@v2
with:
repo_token: ${{ github.token }}
file: dist/*
tag: ${{ github.ref }}
overwrite: true
file_glob: true
build-docker:
runs-on: ubuntu-latest
needs: [variables, build-service]
env:
REF_NAME: ${{ needs.variables.outputs.ref_name }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Generate static _version.py
run: python freeze_version.py
- name: Set up QEMU
uses: docker/setup-qemu-action@master
with:
platforms: linux/amd64,linux/arm64,linux/arm/v7
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@master
- name: Log in to the Docker github container registry
if: ${{github.event_name == 'release' || (github.event_name == 'push' && contains(fromJSON(env.PACKAGE_BRANCHES), github.ref_name))}}
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY_GITHUB }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Log in to the Docker container registry
if: ${{github.event_name == 'release'}}
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Extract metadata (tags, labels) for Docker (No Release)
id: meta
if: ${{github.event_name != 'release'}}
uses: docker/metadata-action@v5
with:
images: |
${{ env.REGISTRY_GITHUB }}/${{ env.IMAGE_NAME }}
- name: Extract metadata (tags, labels) for Docker (Release)
id: meta_release
if: ${{github.event_name == 'release'}}
uses: docker/metadata-action@v5
with:
images: |
${{ env.IMAGE_NAME }}
${{ env.REGISTRY_GITHUB }}/${{ env.IMAGE_NAME }}
- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
builder: ${{ steps.buildx.outputs.name }}
context: .
platforms: linux/amd64,linux/arm64,linux/arm/v7
push: ${{github.event_name == 'release' || (github.event_name == 'push' && contains(fromJSON(env.PACKAGE_BRANCHES), github.ref_name))}}
tags: ${{github.event_name == 'release' && steps.meta_release.outputs.tags || steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max