Build/Push Image to Docker Hub #20
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: "Build/Push Image to Docker Hub" | |
on: | |
workflow_run: | |
workflows: ["semantic_release"] | |
types: | |
- completed | |
jobs: | |
informations: | |
runs-on: [ ubuntu-latest ] | |
steps: | |
- uses: actions/checkout@v2 | |
- name: Get version | |
id: informations | |
run: | | |
version=$(cat src/__version__.py |grep VERSION| awk '{print $3}' | tr -d '"') | |
echo "version=${version}" >> "$GITHUB_OUTPUT" | |
release_type=$(cat src/__version__.py |grep VERSION| awk '{print $3}' | tr -d '"'| grep rc) | |
if [ "$release_type" == "" ]; then | |
# RELEASE | |
echo "release_type=release" >> "$GITHUB_OUTPUT" | |
else | |
# PRERELEASE | |
echo "release_type=prerelease" >> "$GITHUB_OUTPUT" | |
fi | |
outputs: | |
version: ${{ steps.informations.outputs.version }} | |
release_type: ${{ steps.informations.outputs.release_type }} | |
Begin: | |
needs: [informations] | |
name: Begin | |
runs-on: [ ubuntu-latest ] | |
steps: | |
- name: Discord notification building state | |
env: | |
DISCORD_WEBHOOK: ${{ secrets.DISCORD_WEBHOOK }} | |
uses: Ilshidur/action-discord@master | |
with: | |
args: '**MyElectricalData** : Version **${{ needs.informations.outputs.version }}** is in building state...' | |
################################################################################################################# | |
# BUILD & PUSH IMAGE | |
Build-And-Push-Image: | |
needs: [informations, Begin] | |
name: Build & Push | |
runs-on: [ ubuntu-latest ] | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v2 | |
################################################################################################################# | |
# SETUP DOCKER | |
- name: Set up QEMU | |
uses: docker/setup-qemu-action@v1 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v1 | |
- name: Login to DockerHub | |
uses: docker/login-action@v1 | |
with: | |
username: ${{ secrets.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_TOKEN }} | |
################################################################################################################# | |
# VERSION | |
- name: Build and push ${{ needs.informations.outputs.version }} | |
uses: docker/build-push-action@v5 | |
with: | |
file: Dockerfile | |
platforms: linux/amd64, linux/arm64, linux/arm/v6, linux/arm/v7 | |
context: . | |
push: true | |
tags: | | |
m4dm4rtig4n/enedisgateway2mqtt:${{ needs.informations.outputs.version }} | |
m4dm4rtig4n/enedisgateway2mqtt:latest-dev | |
m4dm4rtig4n/myelectricaldata:${{ needs.informations.outputs.version }} | |
m4dm4rtig4n/myelectricaldata:latest-dev | |
################################################################################################################## | |
# LATEST | |
- name: Build and push | |
uses: docker/build-push-action@v5 | |
if: ${{ needs.informations.outputs.release_type }} == "release" | |
with: | |
file: Dockerfile | |
context: . | |
platforms: linux/amd64, linux/arm64, linux/arm/v6, linux/arm/v7 | |
push: true | |
tags: | | |
m4dm4rtig4n/enedisgateway2mqtt:latest | |
m4dm4rtig4n/myelectricaldata:latest | |
- name: Discord notification ${{ needs.informations.outputs.version }} image version is up to date | |
env: | |
DISCORD_WEBHOOK: ${{ secrets.DISCORD_WEBHOOK }} | |
uses: Ilshidur/action-discord@master | |
with: | |
args: '**MyElectricalData** : **${{ needs.informations.outputs.version }}/latest** image version is up to date' | |
Finish: | |
needs: [informations, Build-And-Push-Image] | |
name: Finish | |
runs-on: [ ubuntu-latest ] | |
steps: | |
- name: Discord notification | |
env: | |
DISCORD_WEBHOOK: ${{ secrets.DISCORD_WEBHOOK }} | |
uses: Ilshidur/action-discord@master | |
with: | |
args: '**MyElectricalData** : New version available **${{ needs.informations.outputs.version }}**' |