-
-
Notifications
You must be signed in to change notification settings - Fork 73
178 lines (143 loc) · 4.8 KB
/
publish.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
name: Publish
on:
push:
branches:
- master
tags:
- '*'
jobs:
test_api:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
submodules: recursive
- name: Test
run: docker-compose -f $GITHUB_WORKSPACE/zoonavigator-api/docker-compose.test.yml up --exit-code-from=sut
test_web:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
submodules: recursive
- name: Test
run: docker-compose -f $GITHUB_WORKSPACE/zoonavigator-web/docker-compose.test.yml up --exit-code-from=sut
setup_env:
runs-on: ubuntu-latest
needs:
- test_api
- test_web
outputs:
app_version: ${{ steps.set_vars.outputs.app_version }}
docker_tag: ${{ steps.set_vars.outputs.docker_tag }}
docker_image: ${{ steps.set_vars.outputs.docker_image }}
snap_channel: ${{ steps.set_vars.outputs.snap_channel }}
docs_url: ${{ steps.set_vars.outputs.docs_url }}
vcs_ref: ${{ steps.set_vars.outputs.vcs_ref }}
build_date: ${{ steps.set_vars.outputs.build_date }}
steps:
- id: set_vars
name: Set variables
run: |
tag="${GITHUB_REF_NAME#v}"
# is this a semver release?
if [[ "${tag}" =~ ^[0-9]+(\.[0-9]+){2,3}$ ]];
then
app_version="${tag}"
snap_channel="stable"
docker_tag="${tag}"
docs_url="https://zoonavigator.elkozmon.com/en/${tag}"
else
app_version="latest-${GITHUB_SHA::12}"
snap_channel="beta"
docker_tag="unstable"
docs_url="https://zoonavigator.elkozmon.com/en/latest"
fi
# set image name
docker_image="elkozmon/zoonavigator"
echo "app_version=${app_version}" >> "$GITHUB_OUTPUT"
echo "docker_tag=${docker_tag}" >> "$GITHUB_OUTPUT"
echo "docker_image=${docker_image}" >> "$GITHUB_OUTPUT"
echo "snap_channel=${snap_channel}" >> "$GITHUB_OUTPUT"
echo "docs_url=${docs_url}" >> "$GITHUB_OUTPUT"
echo "vcs_ref=${GITHUB_SHA::7}" >> "$GITHUB_OUTPUT"
echo "build_date=$(date -u +"%Y-%m-%dT%H:%M:%SZ")" >> "$GITHUB_OUTPUT"
build_docker:
runs-on: ubuntu-latest
needs:
- setup_env
steps:
- name: Checkout
uses: actions/checkout@v4
with:
submodules: recursive
- 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.DOCKERIO_USERNAME }}
password: ${{ secrets.DOCKERIO_PASSWORD }}
- name: Build and push Docker image
uses: docker/build-push-action@v6
with:
context: .
file: ${{ github.workspace }}/build/docker/Dockerfile
platforms: linux/amd64,linux/arm64
push: true
outputs: type=local,dest=out
tags: ${{ needs.setup_env.outputs.docker_image }}:${{ needs.setup_env.outputs.docker_tag }}
build-args: APP_VERSION=${{ needs.setup_env.outputs.app_version }},DOCS_URL=${{ needs.setup_env.outputs.docs_url }},VCS_REF=${{ needs.setup_env.outputs.vcs_ref }},BUILD_DATE=${{ needs.setup_env.outputs.build_date }}
- name: Package jars
run: tar -cvzf jars.tar.gz -C out/linux_amd64/app lib extra
- name: Upload jars
uses: actions/upload-artifact@v4
with:
name: jars
path: jars.tar.gz
build_snap:
runs-on: ubuntu-latest
needs:
- setup_env
- build_docker
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Download jars
uses: actions/download-artifact@v4
with:
name: jars
- name: Prepare source
run: |
echo "${{ needs.setup_env.outputs.app_version }}" \
> ${GITHUB_WORKSPACE}/build/snap/local/version
tar \
-xvf ${GITHUB_WORKSPACE}/jars/jars.tar.gz \
-C ${GITHUB_WORKSPACE}/build/snap/local
- id: build_snap
name: Build Snap
uses: snapcore/action-build@v1
with:
path: build/
- name: Publish Snap
uses: snapcore/action-publish@v1
env:
SNAPCRAFT_STORE_CREDENTIALS: ${{ secrets.SNAPCRAFT_CREDENTIALS }}
with:
snap: ${{ steps.build_snap.outputs.snap }}
release: ${{ needs.setup_env.outputs.snap_channel }}
cleanup:
runs-on: ubuntu-latest
needs:
- build_docker
- build_snap
if: ${{ always() }}
steps:
- name: Delete artifacts
uses: geekyeggo/delete-artifact@v5
with:
name: jars