-
Notifications
You must be signed in to change notification settings - Fork 0
155 lines (132 loc) · 3.9 KB
/
ci.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
name: Build & Release
on:
push:
paths:
- internal/**
- cmd/**
- go.*
- Makefile
- Dockerfile
- .dockerignore
- .github/workflows/ci.yml
pull_request:
paths:
- internal/**
- cmd/**
- go.*
- Makefile
- Dockerfile
- .dockerignore
- .github/workflows/ci.yml
env:
APP_NAME: traceneck
BIN_TAR: bin.tgz
REGISTRY: ghcr.io
jobs:
build:
name: Build
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Build binaries
run: |
if [[ $GITHUB_REF == refs/tags/v* ]]; then
docker build --target bin --build-arg VERSION=${GITHUB_REF_NAME} -t ${APP_NAME}:bin .
else
docker build --target bin -t ${APP_NAME}:bin .
fi
ID=$(docker create ${APP_NAME}:bin)
docker cp ${ID}:/bf/${BIN_TAR} .
docker rm ${ID}
- name: Upload binaries
uses: actions/upload-artifact@v4
with:
name: binary
path: ${{ env.BIN_TAR }}
release:
name: Release
runs-on: ubuntu-latest
permissions:
contents: write
needs: build
if: startsWith(github.ref, 'refs/tags/v')
steps:
- name: Downloads binaries
uses: actions/download-artifact@v4
with:
name: binary
- name: Set BASE_NAME
run: |
echo "BASE_NAME=${APP_NAME}_${GITHUB_REF_NAME}" >> $GITHUB_ENV
- name: Package binaries
run: |
tar xvzf ${BIN_TAR} && rm ${BIN_TAR}
for arch in amd64 arm64; do
tar xvzf ${arch}.tgz &&
tar cvzf ${BASE_NAME}_${arch}.tar.gz -C bin ${APP_NAME} &&
tar cvzf ${BASE_NAME}_netrics_${arch}.tar.gz -C bin netrics-${APP_NAME} &&
rm -rf ${arch}.tgz bin
done
- name: Generate checksums
run: |
CHECKSUM_FILE=${BASE_NAME}_checksums.txt
for file in *.tar.gz; do
sha256sum $file >> $CHECKSUM_FILE
done
- name: Release binaries
uses: svenstaro/upload-release-action@v2
with:
file: ${{ env.BASE_NAME }}*
file_glob: true
docker:
name: Docker
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
needs: build
if: startsWith(github.ref, 'refs/tags/v')
steps:
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
with:
platforms: arm64
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
with:
platforms: linux/amd64,linux/arm64
- name: Login to GHCR
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Checkout
uses: actions/checkout@v4
with:
sparse-checkout: Dockerfile
sparse-checkout-cone-mode: false
- name: Downloads binaries
uses: actions/download-artifact@v4
with:
name: binary
- name: Set version tags
run: |
VERSION=${GITHUB_REF_NAME#v}
echo "VERSION=${VERSION}" >> $GITHUB_ENV
echo "MAJOR=$(echo $VERSION | cut -d. -f1)" >> $GITHUB_ENV
echo "MINOR=$(echo $VERSION | cut -d. -f1-2)" >> $GITHUB_ENV
echo "PATCH=$(echo $VERSION | cut -d. -f1-3)" >> $GITHUB_ENV
- name: Build image
uses: docker/build-push-action@v6
with:
context: .
target: buildx
platforms: linux/amd64,linux/arm64
push: true
tags: |
${{ env.REGISTRY }}/${{ github.repository }}:latest
${{ env.REGISTRY }}/${{ github.repository }}:${{ env.MAJOR }}
${{ env.REGISTRY }}/${{ github.repository }}:${{ env.MINOR }}
${{ env.REGISTRY }}/${{ github.repository }}:${{ env.PATCH }}