-
-
Notifications
You must be signed in to change notification settings - Fork 244
146 lines (130 loc) · 5.53 KB
/
main.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
name: Build and Push Docker Images
on:
release:
types: [published]
jobs:
# build all the image variants
build:
runs-on: ubuntu-latest
steps:
# checkout repo
- name: Checkout
uses: actions/checkout@v4
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Get branch/tag name
id: get_branch
run: |
export BRANCH_NAME=$(echo "${{ github.ref }}" | sed -e "s/refs\/heads\///g" -e "s/refs\/tags\///g")
echo $BRANCH_NAME
echo "BRANCH_NAME=${BRANCH_NAME}" >> $GITHUB_OUTPUT
- name: Set image tag
id: image_tag
run: |
export IMAGE_TAG=$(if [[ "${{ steps.get_branch.outputs.BRANCH_NAME }}" =~ (latest|master|main) ]]; then echo "latest"; else echo "${{ steps.get_branch.outputs.BRANCH_NAME }}"; fi)
echo $IMAGE_TAG
echo "IMAGE_TAG=${IMAGE_TAG}" >> $GITHUB_OUTPUT
- name: Set alternate image tag
id: alt_image_tag
run: |
export ALT_IMAGE_TAG=$(if [[ "${{ steps.get_branch.outputs.BRANCH_NAME }}" =~ (latest|master|main) ]]; then echo "ubuntu"; else echo "${{ steps.get_branch.outputs.BRANCH_NAME }}-ubuntu"; fi)
echo $ALT_IMAGE_TAG
echo "ALT_IMAGE_TAG=${ALT_IMAGE_TAG}" >> $GITHUB_OUTPUT
- name: Set versioned image tag
id: versioned_image_tag
run: |
export FORMATED_DATE=`date +%Y-%m-%d`
export VERSION_IMAGE_TAG=$(if [[ "${{ steps.get_branch.outputs.BRANCH_NAME }}" =~ (latest|master|main) ]]; then echo ${FORMATED_DATE}; else echo "${{ steps.get_branch.outputs.BRANCH_NAME }}-${FORMATED_DATE}"; fi)
echo $VERSION_IMAGE_TAG
echo "VERSION_IMAGE_TAG=${VERSION_IMAGE_TAG}" >> $GITHUB_OUTPUT
- name: Set Package Versions
id: pkg_version
run: |
get_latest_release() {
curl --silent "https://api.github.com/repos/$1/releases/latest" | # Get latest release from GitHub api
grep '"tag_name":' | # Get tag line
sed -E 's/.*"([^"]+)".*/\1/' # Pluck JSON value
}
export HOMEBRIDGE_APT_PKG_VERSION=`get_latest_release "homebridge/homebridge-apt-pkg"`
export FFMPEG_VERSION=`get_latest_release "homebridge/ffmpeg-for-homebridge"`
echo "HOMEBRIDGE_APT_PKG_VERSION=${HOMEBRIDGE_APT_PKG_VERSION}" >> $GITHUB_OUTPUT
echo "FFMPEG_VERSION=${FFMPEG_VERSION}" >> $GITHUB_OUTPUT
- name: Log into GitHub Container registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and Push Image to GitHub Container Registry
uses: docker/build-push-action@v5
with:
context: .
file: ./Dockerfile
platforms: linux/amd64,linux/arm/v7,linux/arm64
push: true
build-args: |
HOMEBRIDGE_APT_PKG_VERSION=${{ steps.pkg_version.outputs.HOMEBRIDGE_APT_PKG_VERSION }}
FFMPEG_VERSION=${{ steps.pkg_version.outputs.FFMPEG_VERSION }}
tags: |
ghcr.io/homebridge/homebridge:latest
ghcr.io/homebridge/homebridge:ubuntu
ghcr.io/homebridge/homebridge:${{ steps.image_tag.outputs.IMAGE_TAG }}
- name: Log into Docker Hub
uses: docker/login-action@v3
if: github.repository == 'homebridge/docker-homebridge'
with:
registry: docker.io
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Build and Push Image to Docker Hub
uses: docker/build-push-action@v5
if: github.repository == 'homebridge/docker-homebridge'
with:
context: .
file: ./Dockerfile
platforms: linux/amd64,linux/arm/v7,linux/arm64
push: true
build-args: |
HOMEBRIDGE_APT_PKG_VERSION=${{ steps.pkg_version.outputs.HOMEBRIDGE_APT_PKG_VERSION }}
FFMPEG_VERSION=${{ steps.pkg_version.outputs.FFMPEG_VERSION }}
tags: |
homebridge/homebridge:latest
homebridge/homebridge:ubuntu
homebridge/homebridge:${{ steps.image_tag.outputs.IMAGE_TAG }}
tag:
name: Verify Release Tag
runs-on: ubuntu-latest
outputs:
version: ${{ steps.get_version.outputs.version }}
steps:
- name: Get Release Tag
id: get_version
uses: jannemattila/get-version-from-tag@v3
- name: Tag Info
run: |
echo "Release Tag: ${{github.ref}}"
echo "Latest Tag: ${{ steps.get_version.outputs.version }}"
- name: Tag Info Matches
if: endsWith(github.ref, steps.get_version.outputs.version )
run: |
echo Latest Tag matches Release tag
- name: Tag Info Doesn't Match
if: ${{ !endsWith(github.ref, steps.get_version.outputs.version ) }}
run: |
echo Latest Tag does not matches Release tag
exit 1
- name: Published
run: echo "::notice::GitHub Release - https://github.com/homebridge/docker-homebridge/releases/tag/${{ github.event.release.tag_name }}"
github-releases-to-discord:
name: Discord Webhooks
needs: build
uses: homebridge/.github/.github/workflows/discord-webhooks.yml@latest
with:
title: "Homebridge Docker Release"
description: |
Version `${{ github.event.release.tag_name }}`
url: "https://github.com/homebridge/docker-homebridge/releases/tag/${{ github.event.release.tag_name }}"
secrets:
DISCORD_WEBHOOK: ${{ secrets.DISCORD_WEBHOOK_URL_LATEST }}