Skip to content

Commit 1057002

Browse files
committed
Build: Add CI workflow for static codeorigin
1 parent 6721a56 commit 1057002

2 files changed

Lines changed: 49 additions & 6 deletions

File tree

.github/workflows/CI.yaml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: CI
2+
on:
3+
# Manually
4+
workflow_dispatch:
5+
# Note that we deploy regularly from main.
6+
# To test ahead of time, push to a new branch first, or open a PR.
7+
push:
8+
pull_request:
9+
10+
jobs:
11+
docker-test:
12+
# Includes PHP 7.4, Python 3, Node 14
13+
# https://github.com/actions/virtual-environments/blob/ubuntu20/20210816.1/images/linux/Ubuntu2004-README.md
14+
runs-on: ubuntu-20.04
15+
steps:
16+
- uses: actions/checkout@v2
17+
18+
- name: Build the image
19+
run: docker build -t codeorigin-dev:$GITHUB_SHA ./
20+
21+
- name: Test the container
22+
run: |
23+
docker run --rm -p 4000:80/tcp --detach codeorigin-dev:$GITHUB_SHA
24+
# The first error is "Empty reply from server", which curl
25+
# considers an HTTP failure rather than a connection or network failure.
26+
# once GitHub's images come with curl 7.71.0+, use --retry-all-errors
27+
# instead of hardcoded sleep. --krinkle 2021-08-21
28+
sleep 1
29+
curl -f --retry 5 --retry-delay 1 --retry-connrefused http://127.0.0.1:4000/jquery-3.0.0.js > /dev/null
30+
curl -I http://127.0.0.1:4000/jquery-3.0.0.js
31+
php test/cfg-test.php

test/cfg-test.php

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -176,16 +176,24 @@ function jq_req( $url ) {
176176
return $len;
177177
},
178178
] );
179-
$resp['body'] = curl_exec( $ch );
180-
curl_close( $ch );
181-
return $resp;
179+
try {
180+
$ret = curl_exec( $ch );
181+
if ( $ret === false ) {
182+
throw new Exception( curl_error( $ch ) );
183+
}
184+
$resp['body'] = $ret;
185+
return $resp;
186+
} finally {
187+
curl_close( $ch );
188+
}
182189
}
183190

184191
class Unit {
185192
static $i = 0;
186193
static $pass = true;
187194

188195
public static function start() {
196+
error_reporting( E_ALL );
189197
print "TAP version 13\n";
190198
}
191199

@@ -202,9 +210,13 @@ public static function test( $name, $actual, $expected ) {
202210
}
203211

204212
public static function testHttp( $server, $path, array $expectHeaders, $expectBody = null ) {
205-
$resp = jq_req( "http://{$server}{$path}" );
206-
foreach ( $expectHeaders as $key => $val ) {
207-
self::test( "GET $path > header $key", @$resp['headers'][$key], $val );
213+
try {
214+
$resp = jq_req( "http://{$server}{$path}" );
215+
foreach ( $expectHeaders as $key => $val ) {
216+
self::test( "GET $path > header $key", @$resp['headers'][$key], $val );
217+
}
218+
} catch ( Exception $e ) {
219+
self::test( "GET $path > error", $e->getMessage(), null );
208220
}
209221
}
210222

0 commit comments

Comments
 (0)