Repository navigation
138 lines (133 loc) · 5.36 KB
/
Copy pathupdateDatabase.yaml
File metadata and controls
138 lines (133 loc) · 5.36 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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
name: Update database
on:
workflow_dispatch:
schedule:
- cron: "0 0 1 * *"
permissions:
contents: read
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
update-database:
permissions:
contents: write
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6
- uses: actions/setup-node@249970729cb0ef3589644e2896645e5dc5ba9c38 # v6
with:
node-version: 24
cache: "npm"
cache-dependency-path: utils/database-conventer/package-lock.json
- name: Install system tools
run: |
set -euo pipefail
sudo apt-get update
sudo apt-get install --no-install-recommends -y build-essential unar
make --version
unar -version
- name: Install npm packages
run: npm ci
working-directory: ./utils/database-conventer
- name: Build GEA extractor
run: make
working-directory: ./utils/database-conventer
- name: Download Installer
run: node downloadDatabase.js
working-directory: ./utils/database-conventer
- name: Extract database
run: |
set -euo pipefail
test -x ./gea-extract
./gea-extract ./temp/installer.exe ./src \
rall1.dbf uroad.dbf uroad1.dbf errword.dbf cityarea.dbf Inds.DBF
test -s ./src/rall1.dbf
working-directory: ./utils/database-conventer
- name: Convert database
run: |
set -euo pipefail
node index.js
node corrections.js
node compact.js
working-directory: ./utils/database-conventer
- name: Validate converted database
run: |
set -euo pipefail
test -s ./utils/database-conventer/result/zipcode.json
node - <<'NODE'
const fs = require("fs");
const resultPath = "./utils/database-conventer/result/zipcode.json";
const data = JSON.parse(fs.readFileSync(resultPath, "utf8"));
const cities = Object.keys(data);
if (cities.length < 20) {
throw new Error(`Expected at least 20 cities, found ${cities.length}`);
}
const scopes = cities.flatMap((city) =>
Object.values(data[city].areas).flatMap((area) =>
Object.values(area.roads).flatMap((road) => road.scopes),
),
);
if (scopes.length < 10000) {
throw new Error(`Expected at least 10000 scopes, found ${scopes.length}`);
}
if (scopes.some((scope) => !Number.isInteger(scope.zipcode))) {
throw new Error("The converted database contains an invalid zipcode");
}
console.log(`Validated ${cities.length} cities and ${scopes.length} scopes`);
const corrections = JSON.parse(
fs.readFileSync("./utils/database-conventer/result/corrections.json", "utf8"),
);
// Roads are stored as one line per district of comma-separated edits.
const roadCorrections = corrections.roads
.split("\n")
.reduce((total, line) => total + line.split("\t")[1].split(",").length, 0);
if (roadCorrections < 10000) {
throw new Error(`Expected at least 10000 road corrections, found ${roadCorrections}`);
}
// Places are stored as rules; count the written forms they add.
import("./src/utils/placeAliases.js").then(({ expandPlaceAliases }) => {
const districts = cities.flatMap((city) =>
Object.keys(data[city].areas).map((area) => ({ city, area })),
);
const placeAliases =
expandPlaceAliases(districts, corrections.places).size -
expandPlaceAliases(districts).size;
if (placeAliases < 1000) {
throw new Error(`Expected at least 1000 place names, found ${placeAliases}`);
}
console.log(`Validated ${roadCorrections} road corrections and ${placeAliases} place names`);
});
NODE
- name: Copy result
run: |
set -euo pipefail
cp ./utils/database-conventer/result/zipcode.txt ./src/assets/zipcode.txt
cp ./utils/database-conventer/result/corrections.json ./src/assets/corrections.json
git diff --check
- name: Install the site's packages
run: npm ci
- name: Run tests
run: npm test
- name: Commit changes
id: commit
run: |
set -euo pipefail
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git add -- src/assets/zipcode.txt src/assets/corrections.json
if git diff --cached --quiet; then
echo "The zipcode database is already up to date"
exit 0
fi
git commit -m "chore(data): update zipcode database"
git push origin "HEAD:${GITHUB_REF_NAME}"
echo "pushed=true" >> "$GITHUB_OUTPUT"
# Cloudflare deploys a push in about 80 seconds; search engines should
# find the new pages when they come.
- name: Tell search engines which pages changed
if: steps.commit.outputs.pushed == 'true' && github.ref == 'refs/heads/main'
run: |
sleep 180
node scripts/indexnow.mjs HEAD^