Skip to content

Commit e28c06a

Browse files
committed
ci: add GitHub Actions workflow for build, test, and publish
1 parent 480c4c7 commit e28c06a

1 file changed

Lines changed: 80 additions & 0 deletions

File tree

.github/workflows/publish.yml

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
name: Publish Docker image
2+
3+
permissions:
4+
contents: read
5+
packages: write
6+
7+
on:
8+
push:
9+
branches:
10+
- main
11+
- develop
12+
tags:
13+
- '*'
14+
pull_request:
15+
branches:
16+
- main
17+
- develop
18+
workflow_dispatch:
19+
20+
jobs:
21+
ci:
22+
runs-on: self-hosted
23+
steps:
24+
- name: Checkout
25+
uses: actions/checkout@v4
26+
27+
- name: Set up Go
28+
uses: actions/setup-go@v5
29+
with:
30+
go-version-file: go.mod
31+
cache: true
32+
33+
- name: Build
34+
run: go build ./...
35+
36+
- name: Test
37+
run: go test ./...
38+
39+
- name: Gear validate
40+
run: gear validate
41+
42+
build-and-push:
43+
runs-on: self-hosted
44+
needs: ci
45+
steps:
46+
- name: Checkout
47+
uses: actions/checkout@v4
48+
49+
- name: Set Docker Tags
50+
id: meta
51+
uses: docker/metadata-action@v5
52+
with:
53+
images: ghcr.io/${{ github.repository }}
54+
tags: |
55+
type=raw,value=latest,enable={{is_default_branch}}
56+
type=raw,value=develop,enable=${{ github.ref == 'refs/heads/develop' }}
57+
type=ref,event=pr
58+
type=semver,pattern={{version}}
59+
type=semver,pattern={{major}}.{{minor}}
60+
61+
- name: Set up Docker Buildx
62+
uses: docker/setup-buildx-action@v3
63+
64+
- name: Login to GitHub Container Registry
65+
if: github.event_name != 'pull_request'
66+
uses: docker/login-action@v3
67+
with:
68+
registry: ghcr.io
69+
username: ${{ github.actor }}
70+
password: ${{ secrets.GITHUB_TOKEN }}
71+
72+
- name: Build and push
73+
uses: docker/build-push-action@v6
74+
with:
75+
context: .
76+
push: ${{ github.event_name != 'pull_request' }}
77+
tags: ${{ steps.meta.outputs.tags }}
78+
labels: ${{ steps.meta.outputs.labels }}
79+
cache-from: type=gha
80+
cache-to: type=gha,mode=max

0 commit comments

Comments
 (0)