-
Notifications
You must be signed in to change notification settings - Fork 0
171 lines (147 loc) · 7.16 KB
/
test-build-deploy.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
name: Test, Build and Deploy ResMon
on:
push:
branches: []
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Set environment variables
run: |
echo "GOPATH=$GITHUB_WORKSPACE/.go-path" >> $GITHUB_ENV
echo "GOCACHE=$GITHUB_WORKSPACE/.go-cache" >> $GITHUB_ENV
- name: Install C dependencies
uses: awalsh128/cache-apt-pkgs-action@v1
with:
packages: >
gcc libc6-dev gcc-arm-linux-gnueabihf
gcc-aarch64-linux-gnu
- name: Checkout code
uses: actions/checkout@v4
- name: Cache go dependencies
uses: actions/cache@v4
with:
path: |
.go-path
.go-cache
key: go_dependencies-${{ hashFiles('go.sum', 'go.work.sum') }}
restore-keys: |
go_dependencies-${{ hashFiles('go.sum', 'go.work.sum') }}
go_dependencies-
- name: Cache node modules
uses: actions/cache@v4
with:
path: node_modules
key: node_modules-${{hashFiles('package-lock.json')}}
restore-keys: |
node_modules-${{hashFiles('package-lock.json')}}
node_modules-
- name: Cache elm dependencies
uses: actions/cache@v4
with:
path: |
~/.elm
elm-stuff
key: "elm-dependencies-\
${{hashFiles('elm.json', 'review/elm.json')}}"
restore-keys: |
elm-dependencies-${{hashFiles('elm.json', 'review/elm.json')}}
elm-dependencies-
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: "1.22"
cache: false
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: 21.x
cache: "npm"
- name: Create empty file in webroot
run: mkdir -p webroot && touch webroot/empty
- name: Install go dependencies
run: go install
- name: Install npm dependencies
run: npm ci
- name: Log in to Docker Hub
uses: docker/login-action@e92390c5fb421da1463c202d546fed0ec5c39f20
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Log in to GitHub Packages
uses: docker/login-action@e92390c5fb421da1463c202d546fed0ec5c39f20
with:
username: ${{ secrets.GH_PACKAGES_USERNAME }}
password: ${{ secrets.GH_PACKAGES_PASSWORD }}
registry: ghcr.io
- name: Run tests
run: npm run test
- name: Build project
run: npm run build
- name: Build for multiple platforms
run: |
GOOS=linux GOARCH=amd64 CGO_ENABLED=1 CC=gcc go build -tags 'netgo sqlite_stat4 sqlite_fts5 sqlite_math_functions sqlite_vtable' -ldflags '-extldflags "-static"' -o res-mon-linux-amd64
GOOS=linux GOARCH=arm64 CGO_ENABLED=1 CC=aarch64-linux-gnu-gcc go build -tags 'netgo sqlite_stat4 sqlite_fts5 sqlite_math_functions sqlite_vtable' -ldflags '-extldflags "-static"' -o res-mon-linux-arm64
GOOS=linux GOARCH=arm GOARM=7 CGO_ENABLED=1 CC=arm-linux-gnueabihf-gcc go build -tags 'netgo sqlite_stat4 sqlite_fts5 sqlite_math_functions sqlite_vtable' -ldflags '-extldflags "-static"' -o res-mon-linux-armv7
- name: Upload build results
uses: actions/upload-artifact@v4
with:
name: ResMon
path: |
res-mon-linux-amd64
res-mon-linux-arm64
res-mon-linux-armv7
retention-days: 30
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Cache Docker layers
uses: actions/cache@v4
with:
path: /tmp/.buildx-cache
key: buildx-${{hashFiles('ResMon')}}
restore-keys: |
buildx-${{hashFiles('ResMon')}}
buildx-
- name: Prepare docker tags
run: |
BRANCH_NAME=$(echo ${GITHUB_REF#refs/heads/} | sed 's/[^a-zA-Z0-9]/-/g')
SHORT_SHA=$(echo $GITHUB_SHA | cut -c1-7)
echo "BRANCH_DOCKER_TAG=yertools/res-mon:$BRANCH_NAME" >> $GITHUB_ENV
echo "BRANCH_PACKAGE_TAG=ghcr.io/res-mon/res-mon:$BRANCH_NAME" >> $GITHUB_ENV
echo "COMMIT_DOCKER_TAG=yertools/res-mon:$BRANCH_NAME-$SHORT_SHA" >> $GITHUB_ENV
echo "COMMIT_PACKAGE_TAG=ghcr.io/res-mon/res-mon:$BRANCH_NAME-$SHORT_SHA" >> $GITHUB_ENV
if [[ "$GITHUB_REF" == refs/heads/main ]]; then
echo "LATEST_DOCKER_TAG=yertools/res-mon:latest" >> $GITHUB_ENV
echo "LATEST_PACKAGE_TAG=ghcr.io/res-mon/res-mon:latest" >> $GITHUB_ENV
else
echo "LATEST_DOCKER_TAG=" >> $GITHUB_ENV
echo "LATEST_PACKAGE_TAG=" >> $GITHUB_ENV
fi
- name: Extract git tag name
if: startsWith(github.ref, 'refs/tags/')
run: |
SHORT_SHA=$(echo $GITHUB_SHA | cut -c1-7)
echo "DOCKER_GIT_TAG_NAME=yertools/res-mon:${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV
echo "PACKAGE_GIT_TAG_NAME=ghcr.io/res-mon/res-mon:${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV
echo "DOCKER_GIT_TAG_NAME_SHA=yertools/res-mon:${GITHUB_REF#refs/tags/}-$SHORT_SHA" >> $GITHUB_ENV
echo "PACKAGE_GIT_TAG_NAME_SHA=ghcr.io/res-mon/res-mon:${GITHUB_REF#refs/tags/}-$SHORT_SHA" >> $GITHUB_ENV
- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: .
file: ./docker/Release.Dockerfile
push: true
tags: "${{ env.COMMIT_DOCKER_TAG }},\
${{ env.BRANCH_DOCKER_TAG }},\
${{ env.LATEST_DOCKER_TAG }},\
${{ env.DOCKER_GIT_TAG_NAME }},\
${{ env.DOCKER_GIT_TAG_NAME_SHA }},\
${{ env.PACKAGE_GIT_TAG_NAME_SHA }},\
${{ env.COMMIT_PACKAGE_TAG }},\
${{ env.BRANCH_PACKAGE_TAG }},\
${{ env.LATEST_PACKAGE_TAG }},\
${{ env.PACKAGE_GIT_TAG_NAME }}"
builder: ${{ steps.buildx.outputs.name }}
platforms: linux/amd64,linux/arm/v7,linux/arm64/v8
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache