Skip to content

Commit ec9f5f3

Browse files
committed
Zip all turtle files in the build process
1 parent 3644653 commit ec9f5f3

3 files changed

Lines changed: 58 additions & 11 deletions

File tree

.github/workflows/build.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,13 @@ jobs:
3131
- name: Commit and push if build output changed
3232
run: |
3333
set -e
34-
git add build/def.built.ttl build/rps.built.ttl
34+
git add build/def.built.ttl build/rps.built.ttl build/foerderfunke-knowledge-base.zip
3535
if git diff --staged --quiet; then
36-
echo "No changes in build/def.built.ttl or build/rps.built.ttl. Skipping commit."
36+
echo "No changes in build outputs (def.built.ttl, rps.built.ttl, foerderfunke-knowledge-base.zip). Skipping commit."
3737
exit 0
3838
fi
3939
echo "Changes detected in build outputs. Committing..."
4040
git -c user.name="github-actions[bot]" \
4141
-c user.email="41898282+github-actions[bot]@users.noreply.github.com" \
42-
commit -m "Update built.ttl files [skip ci]"
42+
commit -m "Update build outputs [skip ci]"
4343
git push

build.js

Lines changed: 53 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
1-
import path from "path"
2-
import { fileURLToPath } from "url"
3-
import { promises, writeFileSync } from "fs"
41
import { newStore, addTurtleToStore, storeToTurtle, sparqlInsertDelete } from "@foerderfunke/sem-ops-utils"
2+
import { promises, writeFileSync, createWriteStream } from "fs"
3+
import { fileURLToPath } from "url"
4+
import { ZipFile } from "yazl"
5+
import path from "path"
56

67
const ROOT = path.join(path.dirname(fileURLToPath(import.meta.url)))
78
await promises.mkdir(`${ROOT}/build`, { recursive: true })
89

10+
const dfDir = path.join(ROOT, "datafields")
11+
const shaclDir = path.join(ROOT, "shacl")
12+
913
// ----------- def.built.ttl -----------
1014

1115
let header = ["# This file is a generated enriched merge of the following source files:"]
12-
const dfDir = path.join(ROOT, "datafields")
1316

1417
const defTurtleFiles = [
1518
`${ROOT}/definitions.ttl`,
@@ -51,9 +54,9 @@ console.log(`Wrote to ${target}`)
5154

5255
header = ["# This file is a generated merge of the following source files:"]
5356
const shaclDirs = [
54-
`${ROOT}/shacl`,
55-
`${ROOT}/shacl/beta`,
56-
`${ROOT}/shacl/bielefeld`
57+
`${shaclDir}`,
58+
`${shaclDir}/beta`,
59+
`${shaclDir}/bielefeld`
5760
]
5861
let shaclFiles = []
5962
for (let shaclDir of shaclDirs) {
@@ -70,3 +73,46 @@ turtle = header.join("\n") + "\n\n" + await storeToTurtle(rpsStore)
7073
target = `${ROOT}/build/rps.built.ttl`
7174
writeFileSync(target, turtle, "utf8")
7275
console.log(`Wrote to ${target}`)
76+
77+
// ----------- foerderfunke-knowledge-base.zip -----------
78+
79+
const zipOutput = `${ROOT}/build/foerderfunke-knowledge-base.zip`
80+
81+
const defFiles = [
82+
`${ROOT}/definitions.ttl`,
83+
`${ROOT}/materialization.ttl`,
84+
`${ROOT}/consistency.ttl`
85+
]
86+
87+
async function addDirToZip(zip, dir, zipBasePath = "") {
88+
const entries = await promises.readdir(dir, { withFileTypes: true })
89+
for (const entry of entries) {
90+
const fullPath = path.join(dir, entry.name)
91+
const zipPath = path.join(zipBasePath, entry.name)
92+
if (entry.isDirectory()) {
93+
await addDirToZip(zip, fullPath, zipPath)
94+
} else if (entry.isFile()) {
95+
zip.addFile(fullPath, zipPath)
96+
}
97+
}
98+
}
99+
100+
const zip = new ZipFile()
101+
102+
const infoTxt = `This ZIP file contains all the semantic definitions from the FörderFunke knowledge-base.\nCreated: ${new Date().toISOString()}`
103+
zip.addBuffer(Buffer.from(infoTxt, "utf8"), "info.txt")
104+
105+
await addDirToZip(zip, dfDir, "datafields")
106+
await addDirToZip(zip, shaclDir, "shacl")
107+
for (const file of defFiles) zip.addFile(file, path.basename(file))
108+
109+
zip.end()
110+
111+
await new Promise((resolve, reject) => {
112+
zip.outputStream
113+
.pipe(createWriteStream(zipOutput))
114+
.on("close", resolve)
115+
.on("error", reject)
116+
})
117+
118+
console.log(`Wrote to ${zipOutput}`)

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
},
1212
"devDependencies": {
1313
"@foerderfunke/sem-ops-utils": "^0.3.5",
14-
"mocha": "^11.1.0"
14+
"mocha": "^11.1.0",
15+
"yazl": "^3.3.1"
1516
}
1617
}

0 commit comments

Comments
 (0)