-
Notifications
You must be signed in to change notification settings - Fork 56
247 lines (236 loc) · 7.25 KB
/
test_pull.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
name: Test PR and Upload to Docker Hub
on:
workflow_run:
workflows: ["Build Pull Request"]
types:
- completed
env:
PUID: '1000'
PGID: '1000'
PHP_TZ: 'UTC'
jobs:
upload:
runs-on: ubuntu-latest
if: >
github.event.workflow_run.event == 'pull_request' &&
github.event.workflow_run.conclusion == 'success'
outputs:
PR_NO: ${{ steps.get_pull.outputs.PR_NO }}
check_id: ${{ fromJson(steps.create_check.outputs.result).data.id }}
permissions:
actions: read
checks: write
contents: read
pull-requests: write
steps:
-
name: 'Download artifact'
uses: actions/[email protected]
with:
script: |
var artifacts = await github.actions.listWorkflowRunArtifacts({
owner: context.repo.owner,
repo: context.repo.repo,
run_id: ${{ github.event.workflow_run.id }},
});
var matchArtifact = artifacts.data.artifacts.filter((artifact) => {
return artifact.name == "artifact"
})[0];
var download = await github.actions.downloadArtifact({
owner: context.repo.owner,
repo: context.repo.repo,
artifact_id: matchArtifact.id,
archive_format: 'zip',
});
var fs = require('fs');
fs.writeFileSync('${{github.workspace}}/artifact.zip', Buffer.from(download.data));
-
name: "Unzip"
run: unzip artifact.zip && sha256sum lychee.tar
-
name: "Get Pull Request number and SHA"
id: get_pull
run: |
cat pr && echo "PR_NO=`cat pr`" >> $GITHUB_OUTPUT
cat sha && echo "PR_SHA=`cat sha`" >> $GITHUB_OUTPUT
-
name: "Create check"
id: create_check
uses: actions/github-script@v6
env:
parameter_url: '${{ github.event.workflow_run.html_url }}'
with:
script: |
return await github.rest.checks.create({
owner: context.repo.owner,
repo: context.repo.repo,
head_sha: "${{ steps.get_pull.outputs.PR_SHA }}",
name: "Test Image",
status: "in_progress",
details_url: process.env.parameter_url,
});
-
name: debug
run: echo '${{ steps.create_check.outputs.result }}'
-
name: "Import image"
run: docker image load -i ./lychee.tar
-
name: Login to DockerHub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
-
name: Push
run: docker image push lycheeorg/lychee:testing-${{ github.event.workflow_run.id }}
default-env:
needs: upload
runs-on: ubuntu-latest
services:
lychee-docker:
image: lycheeorg/lychee:testing-${{ github.event.workflow_run.id }}
ports:
- 80:80
steps:
-
name: GET
run: 'curl -sSw "%{stderr}%{http_code}" http://localhost/ > /dev/null && curl -f http://localhost/'
sqlite:
needs: upload
runs-on: ubuntu-latest
services:
lychee-docker:
image: lycheeorg/lychee:testing-${{ github.event.workflow_run.id }}
ports:
- 80:80
env:
DB_CONNECTION: sqlite
steps:
-
name: GET
run: 'curl -sSw "%{stderr}%{http_code}" http://localhost/ > /dev/null && curl -f http://localhost/'
sqlite2:
needs: upload
runs-on: ubuntu-latest
services:
lychee-docker:
image: lycheeorg/lychee:testing-${{ github.event.workflow_run.id }}
ports:
- 80:80
env:
DB_CONNECTION: sqlite
DB_DATABASE: '/var/www/html/Lychee/nonexistent'
steps:
-
name: GET
run: 'curl -sSw "%{stderr}%{http_code}" http://localhost/ > /dev/null && curl -f http://localhost/'
mysql:
needs: upload
runs-on: ubuntu-latest
services:
lychee-docker:
image: lycheeorg/lychee:testing-${{ github.event.workflow_run.id }}
ports:
- 80:80
db:
image: mariadb:latest
env:
MYSQL_ROOT_PASSWORD: password
MYSQL_DATABASE: lychee
env:
DB_CONNECTION: mysql
DB_HOST: db
DB_PORT: '3306'
DB_DATABASE: lychee
DB_USERNAME: root
DB_PASSWORD: password
steps:
-
name: GET
run: 'curl -sSw "%{stderr}%{http_code}" http://localhost/ > /dev/null && curl -f http://localhost/'
postgres:
needs: upload
runs-on: ubuntu-latest
services:
lychee-docker:
image: lycheeorg/lychee:testing-${{ github.event.workflow_run.id }}
ports:
- 80:80
db:
image: postgres:latest
env:
POSTGRES_PASSWORD: password
POSTGRES_DB: lychee
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
env:
DB_CONNECTION: pgsql
DB_HOST: db
DB_PORT: '5432'
DB_DATABASE: lychee
DB_USERNAME: postgres
DB_PASSWORD: password
steps:
-
name: GET
run: 'curl -sSw "%{stderr}%{http_code}" http://localhost/ > /dev/null && curl -f http://localhost/'
docker-compose:
needs: upload
runs-on: ubuntu-latest
services:
lychee-docker:
image: lycheeorg/lychee:testing-${{ github.event.workflow_run.id }}
ports:
- 80:80
steps:
-
name: Checkout
uses: actions/checkout@v3
-
name: Set Password
run: "sed -i 's/<.*_PASSWORD>/password/g' docker-compose.yml"
-
name: Set Image
run: "sed -i 's|image: lycheeorg/lychee|image: lycheeorg/lychee:testing-${{ github.event.workflow_run.id }}|' docker-compose.yml"
-
name: Install docker-compose
run: "sudo apt install docker-compose"
-
name: Run docker-compose
run: 'docker-compose up -d && sleep 45 && docker-compose ps && curl -sSw "%{stderr}%{http_code}" http://localhost:90/ > /dev/null && curl -f http://localhost:90/'
retag:
needs: [upload, default-env, sqlite, sqlite2, mysql, postgres, docker-compose]
runs-on: ubuntu-latest
container:
image: gcr.io/go-containerregistry/crane:debug
steps:
-
name: Retag image
env:
PR_NO: ${{ needs.upload.outputs.PR_NO }}
run: |
crane auth login -u ${{ secrets.DOCKERHUB_USERNAME }} -p ${{ secrets.DOCKERHUB_TOKEN }} index.docker.io
crane tag lycheeorg/lychee:testing-${{ github.event.workflow_run.id }} testing-pull$PR_NO
update_check:
if: github.event.workflow_run.conclusion == 'success'
needs: [upload,retag]
runs-on: ubuntu-latest
permissions:
actions: read
checks: write
contents: read
pull-requests: write
steps:
-
name: "Update check"
uses: actions/github-script@v6
with:
script: |
await github.rest.checks.update({
owner: context.repo.owner,
repo: context.repo.repo,
check_run_id: ${{ needs.upload.outputs.check_id }},
name: "Test Image",
status: "completed",
conclusion: "${{ needs.retag.result }}",
});