Deploy hass-addon-sunsynk-multi to ghcr.io #88
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: Deploy hass-addon-sunsynk-multi to ghcr.io | |
# yamllint disable-line rule:truthy | |
on: | |
# On publish this job will start immediately | |
release: | |
types: | |
- published | |
workflow_run: | |
workflows: ["CI"] | |
branches: [main] | |
types: | |
- completed | |
workflow_dispatch: {} | |
jobs: | |
# https://github.com/hassio-addons/workflows/blob/main/.github/workflows/addon-deploy.yaml | |
# https://github.com/frenck/action-addon-information | |
information: | |
name: Gather add-on information | |
runs-on: ubuntu-latest | |
outputs: | |
architectures: ${{ steps.information.outputs.architectures }} | |
build: ${{ steps.information.outputs.build }} | |
description: ${{ steps.information.outputs.description }} | |
environment: ${{ steps.release.outputs.environment }} | |
name: ${{ steps.information.outputs.name }} | |
slug: ${{ steps.information.outputs.slug }} | |
target: ${{ steps.information.outputs.target }} | |
version: ${{ steps.release.outputs.version }} | |
steps: | |
- name: ⤵️ Check out code from GitHub | |
uses: actions/checkout@v4 | |
- name: 🚀 Run add-on information | |
id: information | |
uses: frenck/action-addon-information@v1.4 | |
with: | |
path: ./hass-addon-sunsynk-multi | |
- name: ℹ️ Gather version and environment | |
id: release | |
run: | | |
sha="${{ github.sha }}" | |
environment="edge" | |
version="${sha:0:7}" | |
if [[ "${{ github.event_name }}" = "release" ]]; then | |
version="${{ github.event.release.tag_name }}" | |
version="${version,,}" | |
version="${version#v}" | |
environment="stable" | |
if [[ "${{ github.event.release.prerelease }}" = "true" ]]; then | |
environment="beta" | |
fi | |
fi | |
echo "environment=${environment}" >> "$GITHUB_OUTPUT" | |
echo "version=${version}" >> "$GITHUB_OUTPUT" | |
cat "$GITHUB_OUTPUT" | |
cat "$GITHUB_OUTPUT" >> $GITHUB_STEP_SUMMARY | |
deploy: | |
name: 👷 Build & Deploy ${{ matrix.architecture }} ${{ needs.information.outputs.environment }}/${{ needs.information.outputs.version }} | |
needs: information | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
architecture: ${{ fromJson(needs.information.outputs.architectures) }} | |
steps: | |
- name: ⤵️ Check out code from GitHub | |
uses: actions/checkout@v4 | |
- name: Local copy of sunsynk | |
run: | | |
ls | |
echo $GITHUB_WORKSPACE | |
mkdir -p hass-addon-sunsynk-multi/sunsynk | |
cp -r src hass-addon-sunsynk-multi/sunsynk/ | |
cp setup.* README.md hass-addon-sunsynk-multi/sunsynk/ | |
- name: 🏗 Set up build cache | |
id: cache | |
uses: actions/cache@v3.3.1 | |
with: | |
path: /tmp/.docker-cache | |
key: docker-${{ matrix.architecture }}-${{ github.sha }} | |
restore-keys: | | |
docker-${{ matrix.architecture }} | |
- name: 🏗 Set up QEMU | |
uses: docker/setup-qemu-action@v2.2.0 | |
- name: 🏗 Set up Docker Buildx | |
uses: docker/setup-buildx-action@v2.10.0 | |
# - name: 🏗 Set up Codenotary Community Attestation Service (CAS) | |
# uses: frenck/action-setup-cas@v0.1.1 | |
# with: | |
# version: v1.0.3 | |
- name: ℹ️ Compose build flags | |
id: flags | |
run: | | |
echo "date=$(date +"%Y-%m-%dT%H:%M:%SZ")" >> "$GITHUB_OUTPUT" | |
from=$(yq --no-colors eval ".build_from.${{ matrix.architecture }}" "${{ needs.information.outputs.build }}") | |
echo "from=${from}" >> "$GITHUB_OUTPUT" | |
if [[ "${{ matrix.architecture}}" = "amd64" ]]; then | |
echo "platform=linux/amd64" >> "$GITHUB_OUTPUT" | |
elif [[ "${{ matrix.architecture }}" = "i386" ]]; then | |
echo "platform=linux/386" >> "$GITHUB_OUTPUT" | |
elif [[ "${{ matrix.architecture }}" = "armhf" ]]; then | |
echo "platform=linux/arm/v6" >> "$GITHUB_OUTPUT" | |
elif [[ "${{ matrix.architecture }}" = "armv7" ]]; then | |
echo "platform=linux/arm/v7" >> "$GITHUB_OUTPUT" | |
elif [[ "${{ matrix.architecture }}" = "aarch64" ]]; then | |
echo "platform=linux/arm64/v8" >> "$GITHUB_OUTPUT" | |
else | |
echo "::error ::Could not determine platform for architecture ${{ matrix.architecture }}" | |
exit 1 | |
fi | |
- name: 🏗 Login to GitHub Container Registry | |
uses: docker/login-action@v2.2.0 | |
with: | |
registry: ghcr.io | |
username: ${{ github.repository_owner }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: ⤵️ Download base image | |
if: steps.flags.outputs.from != 'null' | |
run: docker pull "${{ steps.flags.outputs.from }}" | |
- name: 🚀 Build | |
uses: docker/build-push-action@v4.1.1 | |
with: | |
load: true | |
# yamllint disable rule:line-length | |
tags: | | |
ghcr.io/${{ github.repository_owner }}/${{ needs.information.outputs.slug }}/${{ matrix.architecture }}:${{ needs.information.outputs.environment }} | |
ghcr.io/${{ github.repository_owner }}/${{ needs.information.outputs.slug }}/${{ matrix.architecture }}:${{ needs.information.outputs.version }} | |
# yamllint enable rule:line-length | |
context: ${{ needs.information.outputs.target }} | |
file: ${{ needs.information.outputs.target }}/Dockerfile | |
cache-from: | | |
type=local,src=/tmp/.docker-cache | |
ghcr.io/${{ github.repository_owner }}/${{ needs.information.outputs.slug }}/${{ matrix.architecture }}:edge | |
cache-to: type=local,mode=max,dest=/tmp/.docker-cache-new | |
platforms: ${{ steps.flags.outputs.platform }} | |
build-args: | | |
BUILD_ARCH=${{ matrix.architecture }} | |
BUILD_DATE=${{ steps.flags.outputs.date }} | |
BUILD_DESCRIPTION=${{ needs.information.outputs.description }} | |
BUILD_FROM=${{ steps.flags.outputs.from }} | |
BUILD_NAME=${{ needs.information.outputs.name }} | |
BUILD_REF=${{ github.sha }} | |
BUILD_REPOSITORY=${{ github.repository }} | |
BUILD_VERSION=${{ needs.information.outputs.version }} | |
# This ugly bit is necessary, or our cache will grow forever... | |
# Well until we hit GitHub's limit of 5GB :) | |
# https://github.com/docker/build-push-action/issues/252 | |
# https://github.com/moby/buildkit/issues/1896 | |
- name: 🚚 Swap build cache | |
run: | | |
rm -rf /tmp/.docker-cache | |
mv /tmp/.docker-cache-new /tmp/.docker-cache | |
- name: 🚀 Push | |
run: | | |
docker push \ | |
"ghcr.io/${{ github.repository_owner }}/${{ needs.information.outputs.slug }}/${{ matrix.architecture }}:${{ needs.information.outputs.environment }}" | |
docker push \ | |
"ghcr.io/${{ github.repository_owner }}/${{ needs.information.outputs.slug }}/${{ matrix.architecture }}:${{ needs.information.outputs.version }}" | |
publish_addon: | |
name: 🆕 Update addon version to ${{ needs.information.outputs.version }} | |
needs: [information, deploy] | |
permissions: | |
contents: write | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Point edge to the new ref | |
run: | | |
sed -i 's/version:.*/version: "${{ needs.information.outputs.version }}"/g' hass-addon-sunsynk-edge/config.yaml | |
- name: Point multi to the new ref | |
if: "${{ needs.information.outputs.environment == 'stable'}}" | |
run: | | |
sed -i 's/version:.*/version: "${{ needs.information.outputs.version }}"/g' hass-addon-sunsynk-multi/config.yaml | |
- uses: stefanzweifel/git-auto-commit-action@v4 | |
with: | |
branch: main | |
commit_user_email: kellerza@gmail.com | |
commit_message: Update addon version to ${{ needs.information.outputs.version }} [no ci] |