-
-
Notifications
You must be signed in to change notification settings - Fork 1
170 lines (145 loc) · 6.2 KB
/
release.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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
name: release
on:
push:
tags:
- "v[0-9]+.[0-9]+.[0-9]+.[0-9]+"
env:
DOTNETVERSION: "7.0.x"
APP: "HomeAutio.Mqtt.Ecobee"
SOLUTION: "./src/HomeAutio.Mqtt.Ecobee.sln"
BUILDOUTPUTPATH: "./src/HomeAutio.Mqtt.Ecobee/bin/Release/net7.0"
REGISTRY: ghcr.io
DOCKER_NAME: "i8beef/homeautio.mqtt.ecobee"
jobs:
release:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
ref: master
fetch-depth: 0
- name: Setup .NET Core SDK ${{ env.DOTNETVERSION }}
uses: actions/setup-dotnet@v3
with:
dotnet-version: ${{ env.DOTNETVERSION }}
- name: Get version
id: version
run: echo "version-without-v=${GITHUB_REF#refs/tags/v}" >> $GITHUB_OUTPUT
- name: Get previous release tag
id: previousTag
run: |
PREV_REV=$(git rev-list --tags --max-count=1 --skip=1 --no-walk)
PREV_TAG=$(git describe --tags ${PREV_REV})
echo "tag=${PREV_TAG}" >> $GITHUB_OUTPUT
- name: Install dependencies
run: dotnet restore ${{ env.SOLUTION }}
- name: Build
run: dotnet build ${{ env.SOLUTION }} --configuration Release --no-restore /p:Version=${{ steps.version.outputs.version-without-v }}
- name: Test
run: dotnet test ${{ env.SOLUTION }} --no-restore --verbosity normal --logger trx --results-directory "TestResults"
- name: Upload app build artifact
uses: actions/upload-artifact@v3
with:
name: ${{ env.APP }}-${{ steps.version.outputs.version-without-v }}
path: ${{ env.BUILDOUTPUTPATH }}
- name: Upload TestResults build artifact
uses: actions/upload-artifact@v3
with:
name: TestResults
path: TestResults
- name: ZIP release artifact
run: zip -r ${{ env.APP }}-${{ steps.version.outputs.version-without-v }}.zip ${{ env.BUILDOUTPUTPATH }}
- name: GitHub release
id: release
run: gh release create ${{ github.ref }} "${{ env.APP }}-${{ steps.version.outputs.version-without-v }}.zip" -t "${{ steps.version.outputs.version-without-v }}" --generate-notes --notes-start-tag ${{ steps.previousTag.outputs.tag }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
docker-build:
needs: release
strategy:
matrix:
include:
-
docker-file: "./src/Dockerfile"
docker-tag: "amd64"
-
docker-file: "./src/Dockerfile.arm64"
docker-tag: "arm64"
-
docker-file: "./src/Dockerfile.arm32"
docker-tag: "arm32"
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
ref: master
fetch-depth: 0
- name: Get version
id: version
run: echo "version-without-v=${GITHUB_REF#refs/tags/v}" >> $GITHUB_OUTPUT
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Setup Docker metadata
id: meta
uses: docker/metadata-action@v4
with:
images: ${{ env.REGISTRY }}/${{ env.DOCKER_NAME }}
tags: |
type=raw,value=${{ steps.version.outputs.version-without-v }}-${{ matrix.docker-tag }}
type=raw,value=latest-${{ matrix.docker-tag }}
- name: Log into registry ${{ env.REGISTRY }}
uses: docker/login-action@v2
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build Docker image
uses: docker/build-push-action@v3
with:
context: ./src
file: ${{ matrix.docker-file }}
build-args: VERSION=${{ steps.version.outputs.version-without-v }}
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
docker-publish:
needs: docker-build
runs-on: ubuntu-latest
steps:
- name: Get version
id: version
run: echo "version-without-v=${GITHUB_REF#refs/tags/v}" >> $GITHUB_OUTPUT
- name: Log into registry ${{ env.REGISTRY }}
uses: docker/login-action@v2
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Pull Docker images
run: |
docker pull ${{ env.REGISTRY }}/${{ env.DOCKER_NAME }}:${{ steps.version.outputs.version-without-v }}-amd64
docker pull ${{ env.REGISTRY }}/${{ env.DOCKER_NAME }}:${{ steps.version.outputs.version-without-v }}-arm32
docker pull ${{ env.REGISTRY }}/${{ env.DOCKER_NAME }}:${{ steps.version.outputs.version-without-v }}-arm64
docker pull ${{ env.REGISTRY }}/${{ env.DOCKER_NAME }}:latest-amd64
docker pull ${{ env.REGISTRY }}/${{ env.DOCKER_NAME }}:latest-arm32
docker pull ${{ env.REGISTRY }}/${{ env.DOCKER_NAME }}:latest-arm64
- name: Build Docker latest image manifest
run: |
docker manifest create \
${{ env.REGISTRY }}/${{ env.DOCKER_NAME }}:${{ steps.version.outputs.version-without-v }} \
--amend ${{ env.REGISTRY }}/${{ env.DOCKER_NAME }}:${{ steps.version.outputs.version-without-v }}-amd64 \
--amend ${{ env.REGISTRY }}/${{ env.DOCKER_NAME }}:${{ steps.version.outputs.version-without-v }}-arm32 \
--amend ${{ env.REGISTRY }}/${{ env.DOCKER_NAME }}:${{ steps.version.outputs.version-without-v }}-arm64
- name: Push Docker version image manifest
run: docker manifest push --purge ${{ env.REGISTRY }}/${{ env.DOCKER_NAME }}:${{ steps.version.outputs.version-without-v }}
- name: Build Docker latest image manifest
run: |
docker manifest create \
${{ env.REGISTRY }}/${{ env.DOCKER_NAME }}:latest \
--amend ${{ env.REGISTRY }}/${{ env.DOCKER_NAME }}:latest-amd64 \
--amend ${{ env.REGISTRY }}/${{ env.DOCKER_NAME }}:latest-arm32 \
--amend ${{ env.REGISTRY }}/${{ env.DOCKER_NAME }}:latest-arm64
- name: Push Docker latest image manifest
run: docker manifest push --purge ${{ env.REGISTRY }}/${{ env.DOCKER_NAME }}:latest