Repository navigation
117 lines (104 loc) · 4.11 KB
/
Copy pathci.yml
File metadata and controls
117 lines (104 loc) · 4.11 KB
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
name: CI
on:
push:
branches:
- main
- develop
pull_request:
branches:
- main
- develop
permissions:
contents: read
jobs:
validate:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v5
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.3'
tools: composer:v2
coverage: none
- name: Validate Composer
# Metadata-only composer.json changes do not affect installed dependencies.
# Keep schema validation strict while allowing the legacy lockfile hash.
run: composer validate --strict --no-check-lock
- name: Install dependencies
run: composer install --no-interaction --prefer-dist --no-progress
- name: Lint PHP
run: |
for file in ./*.php; do
php -l "$file"
done
- name: Validate camera data
run: |
php -r '
$data = json_decode(file_get_contents("data-camera.json"), true, 512, JSON_THROW_ON_ERROR);
if (!is_array($data) || count($data) === 0) {
fwrite(STDERR, "Camera data must be a non-empty array.\n");
exit(1);
}
$ids = [];
foreach ($data as $index => $camera) {
$id = $camera["CamId"] ?? "";
$name = trim((string) ($camera["CamName"] ?? ""));
if (!preg_match("/^[a-f0-9]{24}$/i", (string) $id)) {
fwrite(STDERR, "Invalid CamId at index {$index}: {$id}\n");
exit(1);
}
if (isset($ids[$id])) {
fwrite(STDERR, "Duplicate CamId at index {$index}: {$id}\n");
exit(1);
}
$ids[$id] = true;
if ($name === "") {
fwrite(STDERR, "Missing CamName at index {$index}.\n");
exit(1);
}
}
echo "Validated " . count($data) . " unique cameras.\n";
'
- name: Validate sitemap
run: |
php sitemap.php > /tmp/camera-sitemap.xml
php -r '
$data = json_decode(file_get_contents("data-camera.json"), true, 512, JSON_THROW_ON_ERROR);
$xml = simplexml_load_file("/tmp/camera-sitemap.xml");
if ($xml === false) {
fwrite(STDERR, "Generated sitemap is invalid XML.\n");
exit(1);
}
$expected = count($data) + 1;
$actual = count($xml->url);
if ($actual !== $expected) {
fwrite(STDERR, "Expected {$expected} sitemap URLs, got {$actual}.\n");
exit(1);
}
echo "Validated {$actual} sitemap URLs.\n";
'
grep -q 'https://camera-hcm.eplus.dev/sitemap.php' sitemap.xml
grep -q 'Sitemap: https://camera-hcm.eplus.dev/sitemap.xml' robots.txt
- name: Smoke-check SEO anchors
run: |
grep -q 'id="cameraGrid"' index.html
grep -q 'id="searchInput"' index.html
grep -q 'rel="canonical" href="https://camera-hcm.eplus.dev/"' index.html
grep -q 'application/ld+json' index.html
grep -q 'camera.php?id=' index.html
grep -q 'max-image-preview:large' index.html
grep -q 'favicon.svg' index.html
grep -q 'manifest.webmanifest' index.html
- name: HTTP smoke test
run: |
FIRST_ID="$(php -r '$data=json_decode(file_get_contents("data-camera.json"), true, 512, JSON_THROW_ON_ERROR); echo $data[0]["CamId"];')"
php -S 127.0.0.1:8080 > /tmp/camera-php-server.log 2>&1 &
SERVER_PID=$!
trap 'kill "$SERVER_PID"' EXIT
sleep 1
curl -fsS "http://127.0.0.1:8080/" | grep -q 'Camera giao thông TP.HCM'
curl -fsS "http://127.0.0.1:8080/camera.php?id=$FIRST_ID" | grep -q 'https://camera-hcm.eplus.dev/camera.php?id='
curl -fsS "http://127.0.0.1:8080/camera.php?id=$FIRST_ID" | grep -q 'application/ld+json'
curl -fsS "http://127.0.0.1:8080/sitemap.php" | grep -q '<urlset'