forked from minekube/gate
-
Notifications
You must be signed in to change notification settings - Fork 0
144 lines (129 loc) · 4.45 KB
/
ci.yml
File metadata and controls
144 lines (129 loc) · 4.45 KB
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
name: ci
on:
push:
pull_request:
types: [opened, reopened]
env:
REGISTRY: ghcr.io
jobs:
lint:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version-file: go.mod
- name: golangci-lint
uses: golangci/golangci-lint-action@v6
with:
version: latest
args: --timeout 3m0s
test:
strategy:
fail-fast: false
matrix:
platform: [ubuntu-latest, macos-latest, windows-latest]
runs-on: ${{ matrix.platform }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Go with cache
uses: actions/setup-go@v5
with:
cache: true
go-version-file: go.mod
- name: Test
run: make test
build:
if: ( github.event_name == 'push' && ( github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags/') ) )
needs:
- lint
- test
runs-on: ubuntu-latest
outputs:
image: ${{ steps.image-ref.outputs.image }}
image_latest: ${{ steps.image-ref.outputs.image_latest }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up docker buildx
uses: docker/setup-buildx-action@v3
- name: Login to Container registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Create image ref and version
id: image-ref
run: |
REF=$(git rev-parse --short $GITHUB_SHA)
# Get version from git tags or use commit-based version
VERSION=$(git describe --tags --always --dirty 2>/dev/null || echo "dev-${REF}")
IMAGE=${{ env.REGISTRY }}/${{ github.repository }}:${REF}
IMAGE_LATEST=${{ env.REGISTRY }}/${{ github.repository }}:latest
IMAGE_JRE=${{ env.REGISTRY }}/${{ github.repository }}/jre:${REF}
IMAGE_JRE_LATEST=${{ env.REGISTRY }}/${{ github.repository }}/jre:latest
echo "image=${IMAGE}" >> $GITHUB_OUTPUT
echo "image_latest=${IMAGE_LATEST}" >> $GITHUB_OUTPUT
echo "image_jre=${IMAGE_JRE}" >> $GITHUB_OUTPUT
echo "image_jre_latest=${IMAGE_JRE_LATEST}" >> $GITHUB_OUTPUT
echo "version=${VERSION}" >> $GITHUB_OUTPUT
echo "Building images:" >> $GITHUB_STEP_SUMMARY
echo "- ${IMAGE}" >> $GITHUB_STEP_SUMMARY
echo "- ${IMAGE_JRE}" >> $GITHUB_STEP_SUMMARY
echo "Version: ${VERSION}" >> $GITHUB_STEP_SUMMARY
- name: Build and push docker image
uses: docker/build-push-action@v6
with:
context: .
file: ./Dockerfile
push: true
platforms: linux/amd64,linux/arm64,windows/amd64,windows/arm64,darwin/amd64,darwin/arm64,linux/arm/v7,linux/arm/v8,linux/s390x
cache-from: type=registry,ref=${{ steps.image-ref.outputs.image_latest }}
cache-to: type=inline
build-args: |
VERSION=${{ steps.image-ref.outputs.version }}
target: gate
tags: |
${{ steps.image-ref.outputs.image }}
${{ steps.image-ref.outputs.image_latest }}
- name: Build and push docker image (jre variant)
uses: docker/build-push-action@v6
with:
context: .
file: ./Dockerfile
push: true
platforms: linux/amd64,linux/arm64,windows/amd64,windows/arm64,darwin/amd64,darwin/arm64,linux/arm/v7,linux/arm/v8,linux/s390x
cache-from: type=registry,ref=${{ steps.image-ref.outputs.image_jre_latest }}
cache-to: type=inline
build-args: |
VERSION=${{ steps.image-ref.outputs.version }}
target: jre
tags: |
${{ steps.image-ref.outputs.image_jre }}
${{ steps.image-ref.outputs.image_jre_latest }}
releaser:
if: startsWith(github.ref, 'refs/tags/')
needs:
- build
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup Go
uses: actions/setup-go@v5
with:
cache: true
go-version-file: go.mod
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v6
with:
version: latest
args: release --clean
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}