-
-
Notifications
You must be signed in to change notification settings - Fork 8
276 lines (276 loc) · 12.3 KB
/
xqerl.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
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
# https://docs.github.com/en/actions/learn-github-actions/expressions
name: build check release
on:
push:
branches:
- 'main'
tags:
- 'v*.*.*'
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: checkout repo
uses: actions/checkout@v3
- name: set env
run: |
grep -qoP 'v\d+\.\d+\.\d+' rebar.config
grep -qoP '\d+\.\d+\.\d+' src/xqerl.app.src
REBAR_RELEASE="$(grep -oP 'v\d+\.\d+\.\d+' rebar.config)"
APP_VSN="$(grep -oP '\d+\.\d+\.\d+' src/xqerl.app.src)"
echo "rebar_release=$REBAR_RELEASE" >> $GITHUB_ENV
echo "app_vsn=$APP_VSN" >> $GITHUB_ENV
- name: when branch do some inital checks
if: ${{ github.ref_type == 'branch' }}
run: |
echo ${{github.ref_name}}
echo 'check: rebar_release and app_vsn have the same version number'
${{ env.rebar_release == format('{0}{1}','v', env.app_vsn ) }}
echo " - rebar_release: ${{ env.rebar_release}} "
echo " - xqerl app vsn: ${{ env.app_vsn }} "
- name: when tag do some inital checks
if: ${{ github.ref_type == 'tag' }}
run: |
echo " - release version: ${{github.ref_name}}"
# - derive NOTE from the annotated tag message
NOTE="$(git tag -l --format='%(contents:subject)' ${{github.ref_name}} )"
echo " - release subject: ${NOTE}"
echo 'check: rebar_release and app_vsn have the same version number'
${{ env.rebar_release == format('{0}{1}','v', env.app_vsn ) }}
echo 'check: tag version is the same as rebar release version'
${{ env.rebar_release == github.ref_name }}
echo 'check: annotated tag will have tag message '
# A pushed tag may be lightwieght tag therefor no subject
[ ! -z "${NOTE}" ] || echo 'ERR: lightweight tag pushed. use annotated tag to create release'
[ ! -z "${NOTE}" ]
#echo " - rebar_release: ${{ env.rebar_release}} "
#echo " - xqerl app vsn: ${{ env.app_vsn }} "
- name: Cache dependencies
id: cache-deps
uses: actions/cache@v2
with:
path: _build
key: rebar-${{ hashFiles('./rebar.lock') }}
- name: Cache dependencies
if: steps.cache-deps.outputs.cache-hit != 'true'
run: |
rebar3 deps
rebar3 compile
- name: build production tar
run: |
rebar3 as prod tar
mv _build/prod/rel/xqerl/xqerl-*.tar.gz ./xqerl.tar.gz
- name: Upload built artifact
uses: actions/upload-artifact@v3
with:
name: xqerl-prod-tar
path: ./xqerl.tar.gz
checks:
if: ${{ github.ref_type == 'branch' }}
needs: build
runs-on: ubuntu-latest
steps:
- name: checkout repo
uses: actions/checkout@v3
- name: Download built artifact
uses: actions/download-artifact@v3
with:
name: xqerl-prod-tar
- name: Unpack release tar and install xqerl application
run: |
mkdir -p $HOME/.local/xqerl
mkdir -p $HOME/.local/bin
# echo "$HOME/.local/bin" >> $GITHUB_PATH
tar -zxf xqerl.tar.gz -C $HOME/.local/xqerl
ln -s $HOME/.local/xqerl/bin/xqerl $HOME/.local/bin
which xqerl
- name: Start the xqerl application
run: |
xqerl daemon
sleep 2
xqerl eval 'application:ensure_all_started(xqerl).'
- name: Checks - OTP Beam inspection
run: |
printf %60s | tr ' ' '-' && echo
echo -n '- ping: '
xqerl ping | grep -oP 'pong'
echo -n '- pid: '
xqerl pid | grep -oP '\d+'
printf %60s | tr ' ' '-' && echo
echo -n ' - set xqerl working directory: '
xqerl eval "file:set_cwd('$(pwd)')."
xqerl eval 'file:get_cwd().'
printf %60s | tr ' ' '=' && echo
- name: Checks - xqerl eval on running instance
run: |
printf %60s | tr ' ' '-' && echo
echo ' - run a xQuery expression'
xqerl eval 'xqerl:run("xs:token(\"cats\"), xs:string(\"dogs\"), true() ").' | \
grep -oP '^\[\{xq.+$'
printf %60s | tr ' ' '-' && echo
echo ' - compile an xQuery file'
xqerl eval 'xqerl:compile("docs/src/sudoku2.xq").' | \
grep -oP 'file(.+)\.xq'
printf %60s | tr ' ' '-' && echo
echo ' - compile, run then grep the title'
xqerl eval 'S = xqerl:compile("docs/src/sudoku2.xq"),binary_to_list(xqerl_node:to_xml(S:main(#{}))).' | \
grep -oP '<title>(.+)</title>'
printf %60s | tr ' ' '-' && echo
echo -n ' - load an XML file into the DB: '
xqerl eval \
'xqldb_dml:insert_doc("http://xqerl.org/my_doc.xml","./test/QT3-test-suite/app/FunctxFn/functx_order.xml").' | \
grep -oP 'ok'
printf %60s | tr ' ' '-' && echo
echo ' - view using the the xqerl:run/1 function with xQuery fn:doc#1 function'
xqerl eval "binary_to_list(xqerl:run(\" 'http://xqerl.org/my_doc.xml' => doc() => serialize() \"))."
printf %60s | tr ' ' '-' && echo
echo -n ' - delete db doc '
xqerl eval 'xqldb_dml:delete_doc("http://xqerl.org/my_doc.xml").' | \
grep -oP 'ok'
printf %60s | tr ' ' '-' && echo
echo -n ' - import into DB docs from directory: '
xqerl eval 'xqldb_dml:import_from_directory("http://xqerl.org/tests/", "./test/QT3-test-suite").' | \
grep -oP 'ok'
printf %60s | tr ' ' '=' && echo
- name: Stop xqerl
run: xqerl stop
release:
if: ${{ github.ref_type == 'tag' }}
needs: build
runs-on: ubuntu-latest
steps:
- name: checkout repo
uses: actions/checkout@v3
- name: Download built artifact
uses: actions/download-artifact@v3
with:
name: xqerl-prod-tar
- name: Release artifact
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
echo " - release version: ${{github.ref_name}}"
# - derive NOTE from the annotated tag message
NOTE="$(git tag -l --format='%(contents:subject)' ${{github.ref_name}} )"
echo " - release note: ${NOTE}"
# in build we detirmined that rebar.config version is the same as pushed annotated tag
# so we can just use ${{github.ref_name}} for the release name
# mv ./xqerl.tar.gz ./xqerl-${{github.ref_name}}.tar.gz
# use the gh client to create release
gh release create ${{github.ref_name}} "./xqerl.tar.gz#xqerl ${{github.ref_name}}" \
--notes "${NOTE}" \
--title "xqerl release ${{github.ref_name}}" \
--target ${{github.sha}}
package:
if: ${{ github.ref_type == 'tag' }}
needs: build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Pull Images
run: |
XQERL_VERSION=$(grep -oP 'v\d+\.\d+\.\d+' rebar.config)
# pull in the latest versions of alpine and erlang alpine
podman pull docker.io/alpine:latest
ALPINE_VERSION=$(podman run --rm docker.io/alpine:latest /bin/ash -c 'cat /etc/os-release' | grep -oP 'VERSION_ID=\K.+')
podman pull docker.io/erlang:alpine
OTP_VERSION=$(podman run --rm docker.io/erlang:alpine sh -c 'cat /usr/local/lib/erlang/releases/*/OTP_VERSION')
echo " - release version: ${XQERL_VERSION}"
echo " - uses alpine version: ${ALPINE_VERSION}"
echo " - uses erlang OTP version: ${OTP_VERSION}"
- name: Buildah
run: |
XQERL_VERSION=$(grep -oP 'v\d+\.\d+\.\d+' rebar.config)
BASE_CONTAINER=$(buildah from docker.io/erlang:alpine)
buildah copy ${BASE_CONTAINER} ./ /home/
buildah run ${BASE_CONTAINER} sh -c 'apk add --update git tar \
&& cd /home \
&& rebar3 as prod tar \
&& mkdir /usr/local/xqerl \
&& tar -zxf _build/prod/rel/xqerl/*.tar.gz -C /usr/local/xqerl'
CONTAINER=$(buildah from docker.io/alpine:latest)
buildah run ${CONTAINER} sh -c 'apk add --no-cache openssl ncurses-libs tzdata libstdc++ \
&& mkdir /usr/local/xqerl \
&& cd /usr/local/bin \
&& ln -s /usr/local/xqerl/bin/xqerl'
buildah copy --from ${BASE_CONTAINER} $CONTAINER /usr/local/xqerl /usr/local/xqerl
printf %60s | tr ' ' '-' && echo
echo " - check"
buildah run ${CONTAINER} sh -c 'which xqerl' # should error if fails to find
echo " - set working dir and entry point"
buildah config --cmd '' ${CONTAINER}
buildah config --workingdir /usr/local/xqerl ${CONTAINER}
buildah config --entrypoint '[ "xqerl", "foreground"]' ${CONTAINER}
echo " - set environment vars"
buildah config --env LANG=C.UTF-8 ${CONTAINER}
buildah config --env HOME=/home ${CONTAINER}
buildah config --env XQERL_HOME=/usr/local/xqerl ${CONTAINER}
printf %60s | tr ' ' '-' && echo
buildah run ${CONTAINER} sh -c 'printenv' || true
printf %60s | tr ' ' '-' && echo
echo " - set stop signal"
buildah config --stop-signal SIGTERM ${CONTAINER}
echo " - set labels"
buildah config --label org.opencontainers.image.base.name=alpine ${CONTAINER}
buildah config --label org.opencontainers.image.title='xqerl' ${CONTAINER}
buildah config --label org.opencontainers.image.description='Erlang XQuery 3.1 Processor and XML Database' ${CONTAINER}
buildah config --label org.opencontainers.image.source=https://github.com/${GITHUB_REPOSITORY} ${CONTAINER} # where the image is built
buildah config --label org.opencontainers.image.documentation=https://github.com//${GITHUB_REPOSITORY} ${CONTAINER} # image documentation
buildah config --label org.opencontainers.image.version=${XQERL_VERSION} ${CONTAINER} # version
buildah run ${CONTAINER} sh -c \
'xqerl daemon && sleep 2 && xqerl eval "file:make_symlink(code:priv_dir(xqerl),\"./priv\")." && xqerl stop'
buildah commit --squash --rm ${CONTAINER} localhost/xqerl
printf %60s | tr ' ' '-' && echo
- name: Container Checks
run: |
echo " - list docker images"
podman images
printf %60s | tr ' ' '-' && echo
echo " - run container with sh as entrypoint and list working directories"
podman run --rm --entrypoint '["/bin/sh", "-c"]' localhost/xqerl 'ls -al .'
echo " - run container with published ports"
podman run --name xq --publish 8081:8081 --detach localhost/xqerl
sleep 4
echo -n ' - check running: '
podman container inspect -f '{{.State.Running}}' xq
echo -n ' - check application all started: '
podman exec xq xqerl eval "application:ensure_all_started(xqerl)." | grep -oP '^.\Kok'
echo " - check log - only show supervisor"
printf %60s | tr ' ' '-' && echo
podman logs -n -t --since 0 -l | grep -oP '^.+\Ksupervisor:.+$'
printf %60s | tr ' ' '-' && echo
echo -n ' - check status and running size: '
podman ps --size --format "{{.Names}} {{.Status}} {{.Size}}"
echo ' - display the running processes of the container: '
podman top xq user pid %C
podman stop xq || true
- name: Login to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Push to GitHub Container Registry
run: |
XQERL_VERSION=$(grep -oP 'v\d+\.\d+\.\d+' rebar.config)
buildah tag localhost/xqerl ghcr.io/${GITHUB_REPOSITORY}:${XQERL_VERSION}
buildah push ghcr.io/${GITHUB_REPOSITORY}:${XQERL_VERSION}
- name: Login to Docker Container Registry
env:
DOCKER_TOKEN: ${{ secrets.DOCKER_TOKEN }}
if: "${{ env.DOCKER_TOKEN != '' }}"
uses: docker/login-action@v1
with:
registry: docker.io
username: ${{ github.actor }}
password: ${{ secrets.DOCKER_TOKEN }}
- name: Push to Docker Container Registry
env:
DOCKER_TOKEN: ${{ secrets.DOCKER_TOKEN }}
if: "${{ env.DOCKER_TOKEN != '' }}"
run: |
XQERL_VERSION=$(grep -oP 'v\d+\.\d+\.\d+' rebar.config)
buildah tag localhost/xqerl docker.io/${GITHUB_REPOSITORY}:${XQERL_VERSION}
buildah push docker.io/${GITHUB_REPOSITORY}:${XQERL_VERSION}
buildah tag localhost/xqerl docker.io/${GITHUB_REPOSITORY}:latest
buildah push docker.io/${GITHUB_REPOSITORY}:latest