-
-
Notifications
You must be signed in to change notification settings - Fork 28
148 lines (143 loc) · 3.93 KB
/
image.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
name: image
concurrency:
group: image-${{ github.ref }}
cancel-in-progress: true
on:
schedule:
- cron: '0 8 */6 * *' # every 6 days to keep cache
push:
branches:
- 'master'
tags:
- 'v*'
paths-ignore:
- '**.md'
pull_request:
paths-ignore:
- '**.md'
env:
DOCKERHUB_SLUG: crazymax/xgo
GHCR_SLUG: ghcr.io/crazy-max/xgo
PLATFORMS: linux/amd64,linux/arm64
LATEST_CURRENT: 1.22.1
LATEST_PREVIOUS: 1.21.8
jobs:
prepare:
runs-on: ubuntu-latest
steps:
-
name: Checkout
uses: actions/checkout@v4
-
name: Remove dotnet
run: sudo rm -rf /usr/share/dotnet
-
name: Set up QEMU
uses: docker/setup-qemu-action@v3
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
-
name: Build base (cache only)
uses: docker/bake-action@v5
with:
targets: base
set: |
*.platform=${{ env.PLATFORMS }}
*.cache-from=type=gha,scope=base
*.cache-to=type=gha,scope=base,mode=max
build:
needs: prepare
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
go_version:
- 1.21.0
- 1.21.1
- 1.21.2
- 1.21.3
- 1.21.4
- 1.21.5
- 1.21.6
- 1.21.7
- 1.21.8
- 1.22.0
- 1.22.1
steps:
-
name: Checkout
uses: actions/checkout@v4
-
name: Remove dotnet
run: sudo rm -rf /usr/share/dotnet
-
name: Set up QEMU
uses: docker/setup-qemu-action@v3
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
-
name: Tags
id: tags
uses: actions/github-script@v7
with:
result-encoding: string
script: |
const os = require('os');
const majorMinor = "${{ matrix.go_version }}".match(/[0-9]+\.[0-9]+/g)[0];
const tags = ["${{ matrix.go_version }}"];
switch ("${{ matrix.go_version }}") {
case "${{ env.LATEST_CURRENT }}": {
tags.push(`${majorMinor}.x`, majorMinor, "latest");
break;
}
case "${{ env.LATEST_PREVIOUS }}": {
tags.push(`${majorMinor}.x`, majorMinor);
break;
}
}
return tags.join(os.EOL);
-
name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: |
${{ env.DOCKERHUB_SLUG }}
${{ env.GHCR_SLUG }}
tags: ${{ steps.tags.outputs.result }}
labels: |
org.opencontainers.image.title=xgo (go-${{ matrix.go_version }})
org.opencontainers.image.description=Go CGO cross compiler
org.opencontainers.image.vendor=CrazyMax
-
name: Login to DockerHub
if: startsWith(github.ref, 'refs/tags/v')
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
-
name: Login to GHCR
if: startsWith(github.ref, 'refs/tags/v')
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
-
name: Build
uses: docker/bake-action@v5
with:
files: |
./docker-bake.hcl
${{ steps.meta.outputs.bake-file }}
targets: image
set: |
*.platform=${{ env.PLATFORMS }}
*.args.GO_VERSION=${{ matrix.go_version }}
*.cache-from=type=gha,scope=go-${{ matrix.go_version }}
*.cache-from=type=gha,scope=base
*.cache-to=type=gha,scope=go-${{ matrix.go_version }}
push: ${{ startsWith(github.ref, 'refs/tags/v') }}