-
Notifications
You must be signed in to change notification settings - Fork 0
180 lines (154 loc) · 6.42 KB
/
ci.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
name: Build and Test
on: [push, pull_request]
jobs:
docker:
name: Docker image test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Modify scripts and get version
id: version
uses: actions/github-script@v6
with:
script: |
const date = new Date();
const year = date.getUTCFullYear();
const month = `${date.getUTCMonth()+1}`.padStart(2, '0');
const day = `${date.getUTCDate()}`.padStart(2, '0');
const hour = `${date.getUTCHours()}`.padStart(2, '0');
const minute = `${date.getUTCMinutes()}`.padStart(2, '0');
const d = `${year}-${month}-${day}T${hour}-${minute}`;
core.setOutput('version', `${d}-${context.sha.substring(0, 7)}`);
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Cache Docker layers
uses: actions/cache@v3
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-
# Test image build
- name: Copy configuration and move to dev for docker build
run: |
cp -r config/* dev/
cp dev/aws.example.env dev/aws.env
cp dev/secret.example.php dev/secret.php
sed -i -r 's/mediawiki:latest/mediawiki:ci-test/g' docker-compose.yml
- name: Build a test image on amd64 and cache
uses: docker/build-push-action@v3
with:
platforms: linux/amd64
cache-from: |
type=local,src=/tmp/.buildx-cache
cache-to: |
type=inline
type=local,dest=/tmp/.buildx-cache,mode=max
no-cache: ${{ contains(github.event.head_commit.message, '[no cache]') }}
build-args: BUILD_VER=${{ steps.version.outputs.version }}
load: true
push: false
tags: ghcr.io/shinycolorswiki/mediawiki:ci-test
- name: Docker compose up
run: docker compose up -d --force-recreate
# Test image
- name: Try access Main_Page (repeat 1s, timeout 3m)
timeout-minutes: 3
if: success() || failure()
run: until curl -sL --fail-with-body "http://127.0.0.1:8080/wiki/Main_Page"; do sleep 1; done
- name: Test Editor
if: success() || failure()
run: curl -sL --fail-with-body "http://127.0.0.1:8080/w/index.php?title=Main_Page&action=edit"
- name: Test VisualEditor
if: success() || failure()
run: curl -sL --fail-with-body "http://127.0.0.1:8080/w/api.php?action=visualeditor&format=json&page=arbitrary_page&paction=parse&wikitext=arbitrary"
- name: Test Special:Version (timeout 1m)
timeout-minutes: 1
if: success() || failure()
run: curl -sL --fail-with-body "http://127.0.0.1:8080/wiki/Special:Version"
- name: Test Special:MathStatus (timeout 1m)
timeout-minutes: 1
if: success() || failure()
run: curl -sL --fail-with-body "http://127.0.0.1:8080/wiki/Special:MathStatus"
- name: Test /id/?curid=1 (timeout 1m)
timeout-minutes: 1
if: success() || failure()
run: curl -sL --fail-with-body "http://127.0.0.1:8080/id/?curid=1"
- name: Test container healthy (timeout 1m)
timeout-minutes: 1
if: success() || failure()
run: |
until [[ $(docker inspect --format='{{.State.Health.Status}}' docker-mediawiki-fastcgi-1) == "healthy" ]]; do \
echo $(docker inspect --format='{{.State.Health}}' docker-mediawiki-fastcgi-1) && sleep 1 \
; done
# Check test image logs
- name: Docker compose ps
if: success() || failure()
run: docker compose ps
- name: docker compose logs (fastcgi)
if: success() || failure()
run: docker compose logs | grep -i 'fastcgi-1'
- name: docker compose logs (http)
if: success() || failure()
run: docker compose logs | grep -i 'http-1'
- name: docker compose logs (others)
if: success() || failure()
run: docker compose logs | grep -iv 'fastcgi-1' | grep -iv 'http-1'
# Docker Registry login
- name: Login to GitHub Container Registry
if: ${{ github.repository_owner == 'ShinyColorsWiki' && github.ref == 'refs/heads/master' }}
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Login to Quay.io Container Registry
uses: docker/login-action@v2
if: ${{ github.repository_owner == 'ShinyColorsWiki' && github.ref == 'refs/heads/master' }}
with:
registry: quay.io
username: ${{ secrets.QUAY_USERNAME }}
password: ${{ secrets.QUAY_PASSWORD }}
# Build and push
- name: Build a multi-platform docker image and push (for master)
uses: docker/build-push-action@v3
with:
platforms: linux/amd64,linux/arm64
cache-from: |
type=local,src=/tmp/.buildx-cache
cache-to: |
type=inline
type=local,dest=/tmp/.buildx-cache-new,mode=max
build-args: BUILD_VER=${{ steps.version.outputs.version }}
load: false
no-cache: ${{ contains(github.event.head_commit.message, '[no cache]') }}
push: ${{ github.repository_owner == 'ShinyColorsWiki' && github.ref == 'refs/heads/master' }}
tags: |
ghcr.io/shinycolorswiki/mediawiki:latest
ghcr.io/shinycolorswiki/mediawiki:${{ github.sha }}
ghcr.io/shinycolorswiki/mediawiki:${{ steps.version.outputs.version }}
quay.io/shinycolorswiki/mediawiki:latest
quay.io/shinycolorswiki/mediawiki:${{ github.sha }}
quay.io/shinycolorswiki/mediawiki:${{ steps.version.outputs.version }}
- # Temp fix
# https://github.com/docker/build-push-action/issues/252
# https://github.com/moby/buildkit/issues/1896
name: Move cache
run: |
rm -rf /tmp/.buildx-cache
mv /tmp/.buildx-cache-new /tmp/.buildx-cache
deploy:
name: Trigger deploy to upstream
runs-on: ubuntu-latest
needs: docker
if: ${{ github.repository_owner == 'ShinyColorsWiki' && github.ref == 'refs/heads/master' }}
steps:
- name: Repository Dispatch
uses: peter-evans/repository-dispatch@v2
with:
token: ${{ secrets.BOT_PA_TOKEN }}
repository: ${{ secrets.REPO_NAME }}
event-type: update_deploy
client-payload: '{"ref": "${{ github.ref }}", "sha": "${{ github.sha }}"}'