-
Notifications
You must be signed in to change notification settings - Fork 3
232 lines (230 loc) · 8.7 KB
/
stable_build.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
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
name: Stable Build
on:
schedule:
- cron: 0 12 * * *
repository_dispatch:
workflow_dispatch:
jobs:
workflowvars:
name: Setup Workflow Vars
runs-on: ubuntu-latest
outputs:
dockermissing: ${{ steps.check_docker_credentials.outputs.missingsecrets }}
rollbarmissing: ${{ steps.check_rollbar_credentials.outputs.missingsecrets }}
branch: ${{ steps.build_env.outputs.branch }}
version: ${{ steps.build_env.outputs.version }}
revision: ${{ steps.build_env.outputs.revision }}
ispublished: ${{ steps.check_published.outputs.ispublished }}
steps:
- name: Get Revision Variables
id: build_env
run: |
LATEST=$(curl --header 'authorization: Bearer ${{ secrets.GITHUB_TOKEN }}' --silent "https://api.github.com/repos/PhantomBot/PhantomBot/releases/latest")
echo "::group::Curl Result"
echo ${LATEST}
echo
echo
echo $(echo $LATEST | grep '"tag_name":')
echo "::endgroup::"
BRANCH=$(echo $LATEST | grep '"tag_name":' | sed -E 's/.*"tag_name":\s*"([^"]+)".*/\1/')
SHA=$(curl --header 'authorization: Bearer ${{ secrets.GITHUB_TOKEN }}' --silent "https://api.github.com/repos/PhantomBot/PhantomBot/commits/${BRANCH}" | grep '"sha":' | sed -E 's/.*"sha":\s*"([^"]+)".*/\1/')
echo ${BRANCH}
echo "branch=${BRANCH}" >> $GITHUB_OUTPUT
echo ${BRANCH:1}
echo "version=${BRANCH:1}" >> $GITHUB_OUTPUT
echo ${SHA:0:7}
echo "revision=${SHA:0:7}" >> $GITHUB_OUTPUT
- name: Check Docker Credentials
id: check_docker_credentials
env:
DOCKER_USER: ${{ secrets.DOCKER_USER }}
DOCKER_CLITOKEN: ${{ secrets.DOCKER_CLITOKEN }}
DOCKER_REPO_STABLE: ${{ secrets.DOCKER_REPO_STABLE }}
run: |
if [ "${DOCKER_USER}" == "" ]; then
echo "Missing User"
echo "missingsecrets=yes" >> $GITHUB_OUTPUT
elif [ "${DOCKER_CLITOKEN}" == "" ]; then
echo "Missing Cli Token"
echo "missingsecrets=yes" >> $GITHUB_OUTPUT
elif [ "${DOCKER_REPO_STABLE}" == "" ]; then
echo "Missing Repo"
echo "missingsecrets=yes" >> $GITHUB_OUTPUT
else
echo "All secrets present"
echo "missingsecrets=no" >> $GITHUB_OUTPUT
fi
- name: Check Rollbar Credentials
id: check_rollbar_credentials
env:
ROLLBAR_ACCESS_TOKEN: ${{ secrets.ROLLBAR_WRITE_TOKEN }}
run: |
if [ "${ROLLBAR_ACCESS_TOKEN}" == "" ]; then
echo "Missing Rollbar Access Token"
echo "missingsecrets=yes" >> $GITHUB_OUTPUT
else
echo "All secrets present"
echo "missingsecrets=no" >> $GITHUB_OUTPUT
fi
- name: Check Docker Already Published
id: check_published
env:
MISSING: ${{ steps.check_docker_credentials.outputs.missingsecrets }}
DOCKER_REPO_STABLE: ${{ secrets.DOCKER_REPO_STABLE }}
VERSION: ${{ steps.build_env.outputs.version }}
run: |
if [ "${MISSING}" == "no" ]; then
HTTPCODE=$(curl -s -I "https://registry.hub.docker.com/v2/repositories/${DOCKER_REPO_STABLE}/tags/${VERSION}/" | head -n 1 | cut -d$' ' -f2)
echo ${HTTPCODE}
if [ "${HTTPCODE}" == "200" ]; then
echo "Already Published"
echo "ispublished=yes" >> $GITHUB_OUTPUT
else
echo "Not Published"
echo "ispublished=no" >> $GITHUB_OUTPUT
fi
else
echo "No DockerHub"
echo "ispublished=no" >> $GITHUB_OUTPUT
fi
buildtest:
name: Test Build on ubuntu-latest
runs-on: ubuntu-latest
needs: workflowvars
steps:
- name: Checkout PhantomBot Repository
uses: actions/checkout@v4
with:
repository: PhantomBot/PhantomBot
ref: refs/tags/${{ needs.workflowvars.outputs.branch }}
persist-credentials: false
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: 17
- name: Set up Ant
run: sudo apt-get install ant
- name: Build with Ant
run: ant -noinput -buildfile build.xml test
dockertest:
name: Docker test on ubuntu-latest
runs-on: ubuntu-latest
needs: buildtest
timeout-minutes: 5
services:
registry:
image: registry:2
ports:
- 5000:5000
steps:
- name: Checkout Repository
uses: actions/checkout@v4
with:
repository: PhantomBot/PhantomBot
persist-credentials: false
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
with:
platforms: linux/amd64
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
with:
version: latest
driver-opts: network=host
- name: Build Docker
uses: docker/build-push-action@v5
with:
context: .
file: ./Dockerfile
platforms: linux/amd64
push: true
cache-from: type=gha
cache-to: type=gha,mode=max
build-args: |
PROJECT_VERSION=0.0.0
ANT_ARGS=-Dbuildtype=test -Dversion=0.0.0
tags: localhost:5000/tester/phantombot:test
- name: Test with Docker
run: docker run --rm --name phantombot localhost:5000/tester/phantombot:test launch-docker.sh --version
docker:
name: Docker build on ubuntu-latest
runs-on: ubuntu-latest
needs: [buildtest, dockertest, workflowvars]
if: ${{ contains(needs.workflowvars.outputs.dockermissing, 'no') && contains(needs.workflowvars.outputs.ispublished, 'no') }}
steps:
- name: Checkout PhantomBot Repository
uses: actions/checkout@v4
with:
repository: PhantomBot/PhantomBot
ref: refs/tags/${{ needs.workflowvars.outputs.branch }}
persist-credentials: false
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
with:
platforms: linux/amd64,linux/arm64,linux/arm/v7
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
with:
version: latest
- name: Login to DockerHub Registry
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USER }}
password: ${{ secrets.DOCKER_CLITOKEN }}
logout: true
- name: Notify Rollbar of Deploy Start
if: contains(needs.workflowvars.outputs.rollbarmissing, 'no')
id: rollbar_deploy
uses: rollbar/[email protected]
with:
environment: "stable_docker"
version: ${{ needs.workflowvars.outputs.version }}
status: "started"
env:
ROLLBAR_ACCESS_TOKEN: ${{ secrets.ROLLBAR_WRITE_TOKEN }}
ROLLBAR_USERNAME: ${{ github.actor }}
- name: Prep Ant script
env:
BRANCH: ${{ needs.workflowvars.outputs.branch }}
REVISION: ${{ needs.workflowvars.outputs.revision }}
run: |
sed -i -r 's/revision="[A-Za-z0-9._-]+"/revision="'$REVISION'"/;s/branch="[A-Za-z0-9._-]+"/branch="'$BRANCH'"/;s/status="[A-Za-z0-9._-]+"/status="release"/' ivy.xml
echo $?
- name: Build and Push DockerHub
uses: docker/build-push-action@v5
with:
context: .
file: ./Dockerfile
platforms: linux/amd64,linux/arm64,linux/arm/v7
push: true
cache-from: type=gha
cache-to: type=gha,mode=max
build-args: |
PROJECT_VERSION=${{ needs.workflowvars.outputs.version }}
ANT_ARGS=-Dbuildtype=stable -Dfallback.revision=${{ needs.workflowvars.outputs.revision }} -Dversion=${{ needs.workflowvars.outputs.version }} -Drollbar_token=${{ secrets.ROLLBAR_TOKEN }} -Drollbar_endpoint=${{ secrets.ROLLBAR_ENDPOINT }}
tags: |
${{ secrets.DOCKER_REPO_STABLE }}:${{ needs.workflowvars.outputs.version }}
${{ secrets.DOCKER_REPO_STABLE }}:latest
- name: Notify Rollbar of Deploy Failure
if: ${{ contains(needs.workflowvars.outputs.rollbarmissing, 'no') && (failure() || cancelled()) }}
uses: rollbar/[email protected]
with:
environment: "stable_docker"
version: ${{ needs.workflowvars.outputs.version }}
status: "failed"
env:
ROLLBAR_ACCESS_TOKEN: ${{ secrets.ROLLBAR_WRITE_TOKEN }}
ROLLBAR_USERNAME: ${{ github.actor }}
DEPLOY_ID: ${{ steps.rollbar_deploy.outputs.deploy_id }}
- name: Notify Rollbar of Deploy Success
if: ${{ contains(needs.workflowvars.outputs.rollbarmissing, 'no') && success() }}
uses: rollbar/[email protected]
with:
environment: "stable_docker"
version: ${{ needs.workflowvars.outputs.version }}
status: "succeeded"
env:
ROLLBAR_ACCESS_TOKEN: ${{ secrets.ROLLBAR_WRITE_TOKEN }}
ROLLBAR_USERNAME: ${{ github.actor }}
DEPLOY_ID: ${{ steps.rollbar_deploy.outputs.deploy_id }}