Skip to content

Commit

Permalink
also build docker on release
Browse files Browse the repository at this point in the history
  • Loading branch information
steinbach committed May 28, 2021
1 parent 35c6007 commit 3055334
Show file tree
Hide file tree
Showing 2 changed files with 102 additions and 54 deletions.
102 changes: 102 additions & 0 deletions .github/workflows/python-docker-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
name: Upload Python Package and Docker Image

on:
push:
tags:
- "v*"
workflow_dispatch:
inputs:
version:
description: 'Version'
required: true
default: '0.0.0'

jobs:
python-deploy:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2.3.4
- name: Set up Python
uses: actions/setup-python@v2.2.2
with:
python-version: "3.x"
- name: Version from input
if: github.event_name != 'push'
run: |
echo "version=${{ github.event.inputs.version }}" >> $GITHUB_ENV
- name: Version from pushed tag
if: github.event_name == 'push'
run: |
# from refs/tags/v1.2.3 get 1.2.3
echo "version=$(echo $GITHUB_REF | sed 's#.*/v##')" >> $GITHUB_ENV
- name: Autobump version
run: |
PLACEHOLDER="__version__ = 'develop'"
REPLACEMENT="__version__ = '${{ env.version }}'"
VERSION_FILE="weconnect_mqtt/__version.py"
# ensure the placeholder is there. If grep doesn't find the placeholder
# it exits with exit code 1 and github actions aborts the build.
grep "$PLACEHOLDER" "$VERSION_FILE"
sed -i "s/$PLACEHOLDER/$REPLACEMENT/g" "$VERSION_FILE"
grep "$REPLACEMENT" "$VERSION_FILE"
shell: bash
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install setuptools wheel twine
- name: Build and publish
env:
TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }}
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
run: |
python setup.py sdist bdist_wheel
twine upload dist/*
docker-deploy:
needs: [python-deploy]
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2.3.4
- name: Docker meta
id: meta
uses: crazy-max/ghaction-docker-meta@v3.1.0
with:
images: |
tillsteinbach/weconnect-mqtt
ghcr.io/tillsteinbach/weconnect-mqtt
tags: |
type=semver,pattern={{version}}
- name: Set up QEMU
uses: docker/setup-qemu-action@v1.1.0
- name: Setup Docker Buildx
uses: docker/setup-buildx-action@v1.3.0
- name: Setup Cache for buildx
uses: actions/cache@v2.1.5
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-weconnect-mqtt-${{ github.sha }}
- name: Login to DockerHub
if: (github.event_name == 'push' && (contains(github.ref, '/heads/master') || contains(github.ref, '/tags/v')))
uses: docker/login-action@v1.9.0
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Login to GitHub Container Registry
if: (github.event_name == 'push' && (contains(github.ref, '/heads/master') || contains(github.ref, '/tags/v')))
uses: docker/login-action@v1.9.0
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push
id: docker_build
uses: docker/build-push-action@v2.4.0
with:
push: (github.event_name == 'push' && (contains(github.ref, '/heads/master') || contains(github.ref, '/tags/v')))
platforms: linux/amd64,linux/arm/v7,linux/arm64
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache
54 changes: 0 additions & 54 deletions .github/workflows/python-publish.yml

This file was deleted.

0 comments on commit 3055334

Please sign in to comment.