-
Notifications
You must be signed in to change notification settings - Fork 10
206 lines (202 loc) · 6.71 KB
/
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
name: Build
on:
push:
branches:
- main
tags:
- "*"
pull_request:
concurrency:
group: ${{ github.head_ref || github.sha }}-${{ github.workflow }}
cancel-in-progress: true
jobs:
build:
name: ${{ matrix.id }}
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
id:
- "alpine-17"
- "alpine-16"
- "alpine-15"
- "alpine-14"
- "alpine-13"
- "alpine-12"
- "alpine-17-slim"
- "alpine-16-slim"
- "alpine-15-slim"
- "alpine-14-slim"
- "alpine-13-slim"
- "alpine-12-slim"
- "debian-17"
- "debian-16"
- "debian-15"
- "debian-14"
- "debian-13"
- "debian-12"
steps:
- uses: actions/checkout@v4
- name: Parse ID
run: |
set -x
distribution=$(echo ${{ matrix.id }} | grep -o "^[^-]*")
postgresql_version=$(echo ${{ matrix.id }} | grep -o "[0-9]*")
variant=$(echo ${{ matrix.id }} | sed -e "s/^[^-]*-//g")
case "${GITHUB_REF}" in
refs/tags/*)
version=${GITHUB_REF_NAME}
pgroonga_ref=${version}
;;
*)
version=latest
pgroonga_ref=$( \
grep --no-filename PGROONGA_VERSION= alpine/*/Dockerfile | \
head -n 1 | \
grep -o '[0-9.]*' \
)
;;
esac
tag="groonga/pgroonga:${version}-${{ matrix.id }}"
tags="${tag}"
if [ ${{ matrix.id }} = "alpine-17" -a "${version}" = "latest" ]; then
tags="${tags},groonga/pgroonga:latest"
fi
echo "DOCKERFILE=${distribution}/${variant}/Dockerfile" >> ${GITHUB_ENV}
echo "DISTRIBUTION=${distribution}" >> ${GITHUB_ENV}
echo "PGROONGA_REF=${pgroonga_ref}" >> ${GITHUB_ENV}
echo "POSTGRESQL_VERSION=${postgresql_version}" >> ${GITHUB_ENV}
echo "TAG=${tag}" >> ${GITHUB_ENV}
echo "TAGS=${tags}" >> ${GITHUB_ENV}
echo "VARIANT=${variant}" >> ${GITHUB_ENV}
echo "VERSION=${version}" >> ${GITHUB_ENV}
NEED_PUSH=no
PLATFORMS="linux/amd64"
if [[ "${GITHUB_EVENT_NAME}" = "push" && \
"${GITHUB_REPOSITORY}" = "pgroonga/docker" && \
("${GITHUB_REF_NAME}" = "main" || \
"${GITHUB_REF_TYPE}" = "tag") ]]; then
NEED_PUSH=yes
# Include linux/arm64 only when pushing.
# When not pushing, the image is loaded locally, but this will cause an error
# if linux/arm64 is included.
PLATFORMS+=",linux/arm64"
fi
echo "NEED_PUSH=${NEED_PUSH}" >> ${GITHUB_ENV}
echo "PLATFORMS=${PLATFORMS}" >> ${GITHUB_ENV}
- uses: docker/login-action@v3
if: env.NEED_PUSH == 'yes'
with:
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}
- uses: docker/setup-qemu-action@v3
- uses: docker/setup-buildx-action@v3
id: buildx
- uses: docker/build-push-action@v6
id: build-push
with:
context: .
file: ${{ env.DOCKERFILE }}
platforms: ${{ env.PLATFORMS }}
push: ${{ env.NEED_PUSH == 'yes' }}
load: ${{ env.NEED_PUSH != 'yes' }}
tags: ${{ env.TAGS }}
- name: Image info
if: env.NEED_PUSH == 'yes'
run: |
echo "ref: ${GITHUB_REF}"
echo "tags: ${TAGS}"
echo "digest: ${{ steps.build-push.outputs.digest }}"
- uses: actions/checkout@v4
with:
path: pgroonga
ref: ${{ env.PGROONGA_REF }}
repository: pgroonga/pgroonga
- name: Test
env:
PGPASSWORD: pgroonga
run: |
echo "::group::Prepare tests"
pushd pgroonga
if [ "${DISTRIBUTION}" = "alpine" ]; then
# TODO: Remove me when Groonga bundles libstemmer
rm sql/full-text-search/text/options/token-filters/custom.sql
fi
# Reduce tests to reduce test time
rm -r sql/compatibility
if [ ${POSTGRESQL_VERSION} -lt 13 ]; then
rm sql/full-text-search/text/single/declarative-partitioning.sql
fi
ruby test/prepare.rb > schedule
popd
echo "::endgroup"
for platform in $(echo ${PLATFORMS} | tr "," " "); do
echo "::group::Prepare Docker container for ${platform}"
docker run \
--name pgroonga \
--detach \
--env POSTGRES_DB=pgroonga \
--env POSTGRES_PASSWORD=${PGPASSWORD} \
--env POSTGRES_USER=pgroonga \
--publish 127.0.0.1:5432:5432 \
--platform ${platform} \
--volume ${PWD}:/host \
${TAG} \
postgres \
-c max_prepared_transactions=1 \
-c search_path=public
for i in {1..60}; do
if pg_isready -h 127.0.0.1; then
break
fi
sleep 1
done
if [ $i -eq 60 ]; then
echo "PostgreSQL isn't available"
exit 1
fi
echo "::endgroup"
echo "::group::Test for ${platform}"
docker exec pgroonga /host/test/run.sh
echo "::endgroup"
echo "::group::Postpare Docker container"
log_path=pgroonga-$(echo ${platform} | cut -d/ -f2).log
docker exec pgroonga \
cp \
/var/lib/postgresql/data/pgroonga.log \
/host/${log_path}
sudo chown ${USER}: ${log_path}
docker kill --signal TERM pgroonga
for i in {1..60}; do
if [ $(docker ps --filter id=pgroonga | wc -l) -eq 1 ]; then
break
fi
sleep 1
done
if [ $i -eq 60 ]; then
echo "Can't shutdown PostgreSQL"
exit 1
fi
docker rm --force pgroonga
echo "::endgroup"
done
- name: Collect logs
if: always()
run: |
docker exec pgroonga cp /var/lib/postgresql/data/pgroonga.log /host/ || :
sudo chown ${USER}: pgroonga.log || :
- name: Upload logs
if: always()
uses: actions/upload-artifact@v4
with:
name: logs-${{ matrix.id }}
path: |
*.log
- name: Show logs
if: always()
run: |
for log in *.log; do
echo "::group::${log}"
cat "${log}"
echo "::endgroup"
done