Merge pull request #56 from Jeruntu/jjo/implement_mbentley_as_submodu… #1
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 and Push Multi-Platform Docker Image | |
on: | |
push: | |
tags: | |
- 'v*-stable' | |
- 'v*-beta' | |
branches: | |
- '**' | |
jobs: | |
build-and-push: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout the code | |
uses: actions/checkout@v4 | |
with: | |
submodules: true | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Log in to Docker Hub | |
uses: docker/login-action@v3 | |
with: | |
username: ${{ secrets.DOCKER_USER_NAME }} | |
password: ${{ secrets.DOCKER_ACCESS_TOKEN }} | |
- name: Extract Docker tag or branch | |
id: version | |
run: | | |
if [[ "${GITHUB_REF}" == refs/tags/* ]]; then | |
DOCKER_TAG="${GITHUB_REF_NAME#v}" | |
DOCKER_TAG="${DOCKER_TAG%-*}" | |
else | |
DOCKER_TAG="latest" | |
fi | |
if [[ -z "$DOCKER_TAG" ]]; then | |
echo "Error: DOCKER_TAG is empty!" >&2 | |
exit 1 | |
fi | |
echo "DOCKER_TAG=$DOCKER_TAG" >> $GITHUB_ENV | |
- name: Set image name and config file | |
id: image_name | |
run: | | |
if [[ "${GITHUB_REF_NAME}" == *-beta ]]; then | |
echo "IMAGE_NAME=${{ secrets.DOCKER_USER_NAME }}/home-assistant-omada-beta" >> $GITHUB_ENV | |
echo "CONFIG_FILE=Omada Beta/config.yaml" >> $GITHUB_ENV | |
elif [[ "${GITHUB_REF_NAME}" == *-stable ]]; then | |
echo "IMAGE_NAME=${{ secrets.DOCKER_USER_NAME }}/home-assistant-omada-stable" >> $GITHUB_ENV | |
echo "CONFIG_FILE=Omada Stable/config.yaml" >> $GITHUB_ENV | |
else | |
echo "IMAGE_NAME=${{ secrets.DOCKER_USER_NAME }}/home-assistant-omada-dev" >> $GITHUB_ENV | |
echo "CONFIG_FILE=Omada Dev/config.yaml" >> $GITHUB_ENV | |
fi | |
- name: Set INSTALL_VER from config.yaml | |
run: | | |
EXPECTED_TAG=$(yq '.version' "${CONFIG_FILE}") | |
echo "INSTALL_VER=$EXPECTED_TAG" >> $GITHUB_ENV | |
- name: Log key variables | |
run: | | |
echo "Docker Image Name: ${{ env.IMAGE_NAME }}" | |
echo "Docker Tag: ${{ env.DOCKER_TAG }}" | |
echo "Install Version: ${{ env.INSTALL_VER }}" | |
- name: Verify Docker tag matches config.yaml | |
if: startsWith(github.ref, 'refs/tags/') | |
run: | | |
if [[ "${INSTALL_VER}" != "${DOCKER_TAG}" ]]; then | |
echo "Error: Docker tag (${DOCKER_TAG}) does not match expected tag (${INSTALL_VER}) in ${CONFIG_FILE}." | |
exit 1 | |
fi | |
- name: Build Docker image for test builds | |
if: "!startsWith(github.ref, 'refs/tags/')" | |
run: | | |
docker buildx build \ | |
--platform linux/amd64 \ | |
--file "./Omada Dev/Dockerfile" \ | |
--build-arg INSTALL_VER=${{ env.INSTALL_VER }} \ | |
--tag ${{ env.IMAGE_NAME }}:${{ env.DOCKER_TAG }} \ | |
--cache-from=type=registry,ref=${{ env.IMAGE_NAME }}:cache \ | |
--cache-to=type=registry,ref=${{ env.IMAGE_NAME }}:cache,mode=max \ | |
--load \ | |
"./Omada Dev" | |
- name: Build and push Docker image for release builds | |
if: startsWith(github.ref, 'refs/tags/') | |
uses: docker/build-push-action@v6 | |
with: | |
push: true | |
tags: | | |
${{ env.IMAGE_NAME }}:${{ env.DOCKER_TAG }} | |
platforms: linux/amd64,linux/arm64 | |
file: ./Omada Dev/Dockerfile | |
context: ./Omada Dev | |
cache-from: type=registry,ref=${{ env.IMAGE_NAME }}:cache | |
cache-to: type=registry,ref=${{ env.IMAGE_NAME }}:cache,mode=max | |
build-args: | | |
INSTALL_VER=${{ env.INSTALL_VER }} |