Skip to content

Commit

Permalink
Add git workflow to publish to dockerhub
Browse files Browse the repository at this point in the history
  • Loading branch information
Stéphane Senart committed Jan 10, 2025
1 parent f04f2b6 commit 086d962
Show file tree
Hide file tree
Showing 4 changed files with 104 additions and 15 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build-publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ jobs:
git config --global user.name github-actions
git config --global user.email github-actions@github.com
git add pyproject.toml addons/gazpar2haws/config.yaml addons/gazpar2haws/build.yaml
git commit -m "Upgrade version to ${PACKAGE_VERSION}"
git commit --allow-empty -m "Upgrade version to ${PACKAGE_VERSION}"
git push
#----------------------------------------------
Expand Down Expand Up @@ -190,7 +190,7 @@ jobs:
# Publish Docker image to DockerHub
publish-to-dockerhub:
name: Publish to DockerHub
needs: build
needs: [information, build]
runs-on: ubuntu-latest
permissions:
packages: write
Expand Down
90 changes: 90 additions & 0 deletions .github/workflows/publish-to-dockerhub.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
name: Publish to DockerHub

on:
workflow_dispatch:
inputs:
package-version:
description: "Package version"
required: false
default: ""
type: string

permissions:
contents: read # Readonly permissions

env:
DEFAULT_PYTHON_VERSION: "3.12"

jobs:
#----------------------------------------------
# Collect information
information:
name: Collect information
outputs:
package-version: ${{ steps.select-package-version.outputs.package-version }}
default_python_version: ${{ env.DEFAULT_PYTHON_VERSION }}
runs-on: ubuntu-latest
steps:
#----------------------------------------------
# Display Github environment variables
- name: Display Github environment variables
run: printenv | grep '^GITHUB_' | sort

#----------------------------------------------
# Check-out repo
- name: Check out repository
uses: actions/checkout@v4
with:
fetch-depth: 0

#----------------------------------------------
# Compute the version of the project based in the current checkout branch
- name: Compute version
id: compute-version
uses: ./.github/workflows/compute-version
if: ${{ inputs.package-version == '' }}

#----------------------------------------------
# Select package version
- name: Select package version
id: select-package-version
run: |
if [ -z "${{ inputs.package-version }}" ]; then
echo "package-version=${{ steps.compute-version.outputs.pep440-version }}" >> $GITHUB_OUTPUT
else
echo "package-version=${{ inputs.package-version }}" >> $GITHUB_OUTPUT
fi
#----------------------------------------------
# Send to Github Actions
- name: Display information
run: |
echo "package-version=${{ steps.select-package-version.outputs.package-version }}"
echo "default-python-version=${{ env.DEFAULT_PYTHON_VERSION }}"
#----------------------------------------------
# Publish Docker image to DockerHub
publish-to-dockerhub:
name: Publish to DockerHub
needs: information
runs-on: ubuntu-latest
permissions:
packages: write
contents: read
attestations: write
id-token: write
steps:
#----------------------------------------------
# Check-out repo
- name: Check out repository
uses: actions/checkout@v4

#----------------------------------------------
# Publish the Docker image
- name: Publish Docker image
uses: ./.github/workflows/publish-to-dockerhub
with:
image: ssenart/gazpar2haws
version: ${{ needs.information.outputs.package-version }}
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}
23 changes: 11 additions & 12 deletions .github/workflows/publish-to-dockerhub/action.yaml
Original file line number Diff line number Diff line change
@@ -1,34 +1,33 @@
name: 'publish-to-dockerhub'
description: 'Publish to DockerHub workflow'
name: "publish-to-dockerhub"
description: "Publish to DockerHub workflow"

inputs:
image:
description: 'Docker image name'
description: "Docker image name"
required: true
version:
description: 'Version of the image'
description: "Version of the image"
required: true
username:
description: 'DockerHub username'
description: "DockerHub username"
required: true
password:
description: 'DockerHub password'
description: "DockerHub password"
required: true

runs:
using: "composite"
steps:

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ inputs.image }}
tags: |
# Set latest tag for the default branch
type=raw,value=latest,enable={{is_default_branch}}
# Set the version tag for all branches
type=raw,value=${{ inputs.version }},enable=true
tags: |
# Set latest tag for the default branch
type=raw,value=latest,enable={{is_default_branch}}
# Set the version tag for all branches
type=raw,value=${{ inputs.version }}
- name: Log in to Docker Hub
uses: docker/login-action@v3
Expand Down
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Fixed

[#26]((https://github.com/ssenart/gazpar2haws/issues/26): Fix broken HA addons update.
[#26](https://github.com/ssenart/gazpar2haws/issues/26): Fix broken HA addons update.

## [0.1.8] - 2025-01-10

Expand Down

0 comments on commit 086d962

Please sign in to comment.