Skip to content

Commit a939bdf

Browse files
committed
Add Release Workflow
1 parent 88b9fd3 commit a939bdf

3 files changed

Lines changed: 190 additions & 91 deletions

File tree

.github/workflows/build.yml

Lines changed: 0 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -43,94 +43,3 @@ jobs:
4343
with:
4444
name: homedash-${{ matrix.goos }}-${{ matrix.goarch }}
4545
path: homedash-${{ matrix.goos }}-${{ matrix.goarch }}
46-
47-
docker:
48-
runs-on: ubuntu-latest
49-
needs: build
50-
permissions:
51-
contents: read
52-
packages: write
53-
54-
strategy:
55-
matrix:
56-
platform:
57-
- linux/amd64
58-
- linux/arm64/v8
59-
- linux/arm/v7
60-
61-
steps:
62-
- uses: actions/checkout@v4
63-
64-
- name: Set up QEMU
65-
uses: docker/setup-qemu-action@v3
66-
67-
- name: Set up Docker Buildx
68-
uses: docker/setup-buildx-action@v3
69-
70-
- name: Log in to GitHub Container Registry
71-
uses: docker/login-action@v3
72-
with:
73-
registry: ghcr.io
74-
username: ${{ github.actor }}
75-
password: ${{ secrets.GITHUB_TOKEN }}
76-
77-
- name: Extract metadata
78-
id: meta
79-
uses: docker/metadata-action@v5
80-
with:
81-
images: ghcr.io/${{ github.repository }}
82-
tags: |
83-
type=ref,event=branch
84-
type=ref,event=pr
85-
type=sha,prefix={{branch}}-
86-
type=raw,value=latest,enable={{is_default_branch}}
87-
flavor: |
88-
suffix=-${{ matrix.platform }}
89-
90-
- name: Build and push Docker image
91-
uses: docker/build-push-action@v5
92-
with:
93-
context: .
94-
platforms: ${{ matrix.platform }}
95-
push: true
96-
tags: ${{ steps.meta.outputs.tags }}
97-
labels: ${{ steps.meta.outputs.labels }}
98-
cache-from: type=gha,scope=${{ matrix.platform }}
99-
cache-to: type=gha,mode=max,scope=${{ matrix.platform }}
100-
provenance: false
101-
102-
docker-manifest:
103-
runs-on: ubuntu-latest
104-
needs: docker
105-
permissions:
106-
contents: read
107-
packages: write
108-
109-
steps:
110-
- name: Log in to GitHub Container Registry
111-
uses: docker/login-action@v3
112-
with:
113-
registry: ghcr.io
114-
username: ${{ github.actor }}
115-
password: ${{ secrets.GITHUB_TOKEN }}
116-
117-
- name: Extract metadata
118-
id: meta
119-
uses: docker/metadata-action@v5
120-
with:
121-
images: ghcr.io/${{ github.repository }}
122-
tags: |
123-
type=ref,event=branch
124-
type=ref,event=pr
125-
type=sha,prefix={{branch}}-
126-
type=raw,value=latest,enable={{is_default_branch}}
127-
128-
- name: Create and push multi-arch manifest
129-
run: |
130-
TAGS="${{ steps.meta.outputs.tags }}"
131-
for TAG in $TAGS; do
132-
docker buildx imagetools create -t $TAG \
133-
${TAG}-linux-amd64 \
134-
${TAG}-linux-arm64-v8 \
135-
${TAG}-linux-arm-v7
136-
done

.github/workflows/release.yml

Lines changed: 189 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,189 @@
1+
name: Release
2+
3+
on:
4+
push:
5+
branches: [main]
6+
7+
permissions:
8+
contents: write
9+
packages: write
10+
11+
jobs:
12+
release:
13+
runs-on: ubuntu-latest
14+
outputs:
15+
tag: ${{ steps.version.outputs.tag }}
16+
should_release: ${{ steps.version.outputs.should_release }}
17+
steps:
18+
- uses: actions/checkout@v4
19+
with:
20+
fetch-depth: 0
21+
22+
- name: Read version
23+
id: version
24+
run: |
25+
if ! git diff --name-only ${{ github.event.before }} ${{ github.sha }} | grep -q "^VERSION$"; then
26+
echo "should_release=false" >> $GITHUB_OUTPUT
27+
exit 0
28+
fi
29+
30+
VERSION=$(tr -d '\n' < VERSION)
31+
if [ -z "$VERSION" ]; then
32+
echo "VERSION file is empty"
33+
exit 1
34+
fi
35+
36+
TAG="v$VERSION"
37+
if git rev-parse "$TAG" >/dev/null 2>&1; then
38+
echo "Tag $TAG already exists"
39+
exit 1
40+
fi
41+
42+
echo "tag=$TAG" >> $GITHUB_OUTPUT
43+
echo "should_release=true" >> $GITHUB_OUTPUT
44+
45+
- name: Create GitHub release
46+
if: steps.version.outputs.should_release == 'true'
47+
env:
48+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
49+
run: |
50+
gh release create "${{ steps.version.outputs.tag }}" \
51+
--title "${{ steps.version.outputs.tag }}" \
52+
--notes "Release ${{ steps.version.outputs.tag }}"
53+
54+
build-binaries:
55+
runs-on: ubuntu-latest
56+
needs: release
57+
if: needs.release.outputs.should_release == 'true'
58+
strategy:
59+
matrix:
60+
include:
61+
- goos: linux
62+
goarch: amd64
63+
- goos: linux
64+
goarch: arm64
65+
- goos: darwin
66+
goarch: amd64
67+
- goos: darwin
68+
goarch: arm64
69+
- goos: windows
70+
goarch: amd64
71+
steps:
72+
- uses: actions/checkout@v4
73+
74+
- name: Set up Go
75+
uses: actions/setup-go@v5
76+
with:
77+
go-version: '1.21'
78+
79+
- name: Build
80+
env:
81+
GOOS: ${{ matrix.goos }}
82+
GOARCH: ${{ matrix.goarch }}
83+
CGO_ENABLED: 0
84+
run: |
85+
EXT=""
86+
if [ "${{ matrix.goos }}" = "windows" ]; then
87+
EXT=".exe"
88+
fi
89+
go build -ldflags="-s -w" -o homedash-${{ matrix.goos }}-${{ matrix.goarch }}${EXT} .
90+
91+
- name: Upload release asset
92+
env:
93+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
94+
run: |
95+
EXT=""
96+
if [ "${{ matrix.goos }}" = "windows" ]; then
97+
EXT=".exe"
98+
fi
99+
gh release upload "${{ needs.release.outputs.tag }}" \
100+
"homedash-${{ matrix.goos }}-${{ matrix.goarch }}${EXT}"
101+
102+
docker:
103+
runs-on: ubuntu-latest
104+
needs: release
105+
if: needs.release.outputs.should_release == 'true'
106+
permissions:
107+
contents: read
108+
packages: write
109+
110+
strategy:
111+
matrix:
112+
platform:
113+
- linux/amd64
114+
- linux/arm64/v8
115+
- linux/arm/v7
116+
117+
steps:
118+
- uses: actions/checkout@v4
119+
120+
- name: Set up QEMU
121+
uses: docker/setup-qemu-action@v3
122+
123+
- name: Set up Docker Buildx
124+
uses: docker/setup-buildx-action@v3
125+
126+
- name: Log in to GitHub Container Registry
127+
uses: docker/login-action@v3
128+
with:
129+
registry: ghcr.io
130+
username: ${{ github.actor }}
131+
password: ${{ secrets.GITHUB_TOKEN }}
132+
133+
- name: Extract metadata
134+
id: meta
135+
uses: docker/metadata-action@v5
136+
with:
137+
images: ghcr.io/${{ github.repository }}
138+
tags: |
139+
type=raw,value=latest
140+
type=raw,value=${{ needs.release.outputs.tag }}
141+
flavor: |
142+
suffix=-${{ matrix.platform }}
143+
144+
- name: Build and push Docker image
145+
uses: docker/build-push-action@v5
146+
with:
147+
context: .
148+
platforms: ${{ matrix.platform }}
149+
push: true
150+
tags: ${{ steps.meta.outputs.tags }}
151+
labels: ${{ steps.meta.outputs.labels }}
152+
cache-from: type=gha,scope=${{ matrix.platform }}
153+
cache-to: type=gha,mode=max,scope=${{ matrix.platform }}
154+
provenance: false
155+
156+
docker-manifest:
157+
runs-on: ubuntu-latest
158+
needs: docker
159+
if: needs.release.outputs.should_release == 'true'
160+
permissions:
161+
contents: read
162+
packages: write
163+
164+
steps:
165+
- name: Log in to GitHub Container Registry
166+
uses: docker/login-action@v3
167+
with:
168+
registry: ghcr.io
169+
username: ${{ github.actor }}
170+
password: ${{ secrets.GITHUB_TOKEN }}
171+
172+
- name: Extract metadata
173+
id: meta
174+
uses: docker/metadata-action@v5
175+
with:
176+
images: ghcr.io/${{ github.repository }}
177+
tags: |
178+
type=raw,value=latest
179+
type=raw,value=${{ needs.release.outputs.tag }}
180+
181+
- name: Create and push multi-arch manifest
182+
run: |
183+
TAGS="${{ steps.meta.outputs.tags }}"
184+
for TAG in $TAGS; do
185+
docker buildx imagetools create -t $TAG \
186+
${TAG}-linux-amd64 \
187+
${TAG}-linux-arm64-v8 \
188+
${TAG}-linux-arm-v7
189+
done

VERSION

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
1.0.0

0 commit comments

Comments
 (0)