Feature/add extra version check for pull requests (#67) #5
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: | |
branches: | |
- master | |
jobs: | |
build-and-push: | |
runs-on: ubuntu-24.04 | |
strategy: | |
matrix: | |
target: ["beta", "stable"] | |
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 Version and Set Tag | |
id: extract_version | |
run: | | |
capitalize() { | |
echo "$1" | awk '{print toupper(substr($0,1,1)) tolower(substr($0,2))}' | |
} | |
CAPITALIZED_TARGET=$(capitalize "${{ matrix.target }}") | |
VERSION=$(yq '.version' "Omada ${CAPITALIZED_TARGET}/config.yaml") | |
DOCKER_IMAGE="${{ secrets.DOCKER_USER_NAME }}/home-assistant-omada" | |
echo "VERSION=$VERSION" >> $GITHUB_ENV | |
echo "DOCKER_IMAGE=$DOCKER_IMAGE" >> $GITHUB_ENV | |
echo "Target: ${{ matrix.target }}" | |
echo "Version: $VERSION" | |
echo "Docker Image: $DOCKER_IMAGE" | |
- name: Check Omada Version Availability | |
uses: ./.github/actions/version-checks | |
with: | |
version: "${{ env.VERSION }}" | |
- name: Check if Image Exists | |
id: check_image | |
run: | | |
if docker manifest inspect "${{ env.DOCKER_IMAGE }}-${{ matrix.target }}:${{ env.VERSION}}" > /dev/null 2>&1; then | |
echo "exists=true" >> $GITHUB_OUTPUT | |
else | |
echo "exists=false" >> $GITHUB_OUTPUT | |
fi | |
- name: Build and push | |
if: steps.check_image.outputs.exists == 'false' | |
uses: docker/build-push-action@v6 | |
with: | |
context: "Omada\ Dev" | |
build-args: INSTALL_VER=${{ env.VERSION }} | |
platforms: linux/amd64,linux/arm64 | |
push: true | |
tags: "${{ env.DOCKER_IMAGE }}-${{ matrix.target }}:${{ env.VERSION }}" | |
cache-from: type=registry,ref=${{ env.DOCKER_IMAGE }}-${{ matrix.target }}:cache | |
cache-to: type=registry,ref=${{ env.DOCKER_IMAGE }}-${{ matrix.target }}:cache,mode=max |