-
Notifications
You must be signed in to change notification settings - Fork 22
199 lines (168 loc) · 5.57 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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
name: ci
on:
workflow_dispatch:
push:
branches:
- 'main'
tags:
- 'v*'
pull_request:
paths-ignore:
- 'README.md'
- 'docs/**'
- 'LICENSE'
- 'getting_started.md'
env:
go-version: '1.21.5'
python-version: 'pypy3.10'
cmd-name: 'greenmask'
docker-registry: greenmask/greenmask
jobs:
unit-tests:
runs-on: ubuntu-22.04
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: ${{ env.go-version }}
- name: Echo Go version
run: go version
- name: Run tests
run: make tests
integration-tests:
runs-on: ubuntu-22.04
needs:
- unit-tests
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Run integration tests
run: |
docker-compose -f docker-compose-integration.yml -p greenmask up \
--renew-anon-volumes --force-recreate --build --exit-code-from greenmask \
--abort-on-container-exit greenmask
build-binaries:
runs-on: ubuntu-22.04
needs:
- unit-tests
- integration-tests
strategy:
matrix:
platforms:
- 'windows/arm64'
- 'windows/amd64'
- 'darwin/amd64'
- 'darwin/arm64'
- 'linux/amd64'
- 'linux/arm64'
- 'linux/arm/v6'
- 'linux/arm/v7'
- 'linux/ppc64le'
- 'linux/riscv64'
- 'linux/s390x'
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: ${{ env.go-version }}
- name: Build with different arch
run: |
export GOOS=$(echo ${{ matrix.platforms }} | cut -d '/' -f 1)
export GOARCH=$(echo ${{ matrix.platforms }} | cut -d '/' -f 2)
export GOARM=$(echo ${{ matrix.platforms }} | cut -d '/' -f 3 | cut -d 'v' -f 2)
if [[ "$GOOS" == "windows" ]]; then
make build CMD_NAME="builds/${{ env.cmd-name }}.exe"
else
make build CMD_NAME="builds/${{ env.cmd-name }}"
fi
- name: Create checksum
if: startsWith(github.ref, 'refs/tags/v')
working-directory: builds
run: |
find . -type f -exec shasum -a 256 -b {} + | sed 's# \*\./# *#' | while read sum file; do echo "$sum $file" > "${file#\*}".sha256; done
- name: Create archive
if: startsWith(github.ref, 'refs/tags/v')
run: |
export GOOS=$(echo ${{ matrix.platforms }} | cut -d '/' -f 1)
export GOARCH=$(echo ${{ matrix.platforms }} | cut -d '/' -f 2)
export GOARM=$(echo ${{ matrix.platforms }} | cut -d '/' -f 3 | cut -d 'v' -f 2)
export ARCHIVE_NAME=$(echo "${{ env.cmd-name }}-${GOOS}-${GOARCH}$(if [ -n "${GOARM}" ]; then echo v${GOARM}; fi).$(if [ "${GOOS}" = "windows" ]; then echo "zip"; else echo "tar.gz"; fi)")
cp LICENSE builds/
cd builds
if [[ "$GOOS" == "windows" ]]; then
zip "${ARCHIVE_NAME}" *
else
tar -czvf "${ARCHIVE_NAME}" *
fi
find . -maxdepth 1 -type f ! -name ${ARCHIVE_NAME} -exec rm -f {} +
- name: GitHub Release
if: startsWith(github.ref, 'refs/tags/v')
uses: softprops/action-gh-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
draft: true
files: builds/*
build-docker-images-and-push:
runs-on: ubuntu-22.04
needs:
- build-binaries
if: startsWith(github.ref, 'refs/tags/v')
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Get Git tag
id: git_tag
run: echo "TAG=$(git tag --points-at HEAD)" >> $GITHUB_ENV
- name: Build and push
uses: docker/build-push-action@v5
with:
file: docker/greenmask/Dockerfile
context: .
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ env.docker-registry }}:${{ env.TAG }},${{ env.docker-registry }}:latest
deploy-docs:
runs-on: self-hosted
needs:
- build-binaries
- build-docker-images-and-push
if: startsWith(github.ref, 'refs/tags/v')
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Setup python
uses: actions/setup-python@v5
with:
python-version: ${{ env.python-version }}
- name: Install dependicies
run: pip install -r requirements.txt
- name: Build docs
run: mkdocs build
- name: Create docs directory
run: sudo mkdir -p ${{ secrets.DOCS_DEPLOY_DIR }}
- name: Move html files to docs directory
run: sudo mv site ${{ secrets.DOCS_DEPLOY_DIR }}/html-${{ github.ref_name}}
- name: Remove old symlink
run: sudo unlink ${{ secrets.DOCS_DEPLOY_DIR }}/html
- name: Create new symlink
run: sudo ln -s ${{ secrets.DOCS_DEPLOY_DIR }}/html-${{ github.ref_name}} ${{ secrets.DOCS_DEPLOY_DIR }}/html
- name: Restart web service
run: sudo systemctl restart nginx