Skip to content

Commit

Permalink
Merge pull request #298 from dfpc-coe/kmz-tests
Browse files Browse the repository at this point in the history
Basic KMZ Support & Initial Data Task Integration Tests
  • Loading branch information
ingalls authored Aug 28, 2024
2 parents 764ada5 + 2ffc535 commit 5344d81
Show file tree
Hide file tree
Showing 12 changed files with 2,050 additions and 193 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ecr_task.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
matrix:
task: [task, pmtiles, hooks, events]
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
ref: ${{github.event.pull_request.head.sha || github.sha}}

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Get tag
id: tag
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/root.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ jobs:
runs-on: ubuntu-latest
if: github.event.pull_request.draft == false
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
ref: ${{github.event.pull_request.head.sha || github.sha}}

- uses: actions/setup-node@v3
- uses: actions/setup-node@v4
with:
node-version: 18
node-version: 22
registry-url: https://registry.npmjs.org/

- name: Install
Expand Down
23 changes: 18 additions & 5 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,32 @@ on:
- ready_for_review

jobs:
test:
data:
runs-on: ubuntu-latest
if: github.event.pull_request.draft == false
timeout-minutes: 60
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
ref: ${{github.event.pull_request.head.sha || github.sha}}

- uses: actions/setup-node@v3
- name: Docker Data Task Build
run: docker compose build task

- name: Docker Data Task Lint
run: docker run cloudtak-task:latest npm run lint

- name: Docker Data Task Test
run: docker run cloudtak-task:latest npm test

test:
runs-on: ubuntu-latest
if: github.event.pull_request.draft == false
timeout-minutes: 60
steps:
- uses: actions/checkout@v4
with:
node-version: 18
registry-url: https://registry.npmjs.org/
ref: ${{github.event.pull_request.head.sha || github.sha}}

- name: Docker Compose Build
run: docker compose up --build -d postgis
Expand Down
26 changes: 24 additions & 2 deletions tasks/data/lib/kml.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import fs from 'node:fs/promises';
import os from 'node:os';
import path from 'node:path';
import StreamZip from 'node-stream-zip';
import { kml } from '@tmcw/togeojson';
import { DOMParser } from '@xmldom/xmldom';

export default class KML {
static register() {
return {
inputs: ['.kml']
inputs: ['.kml', '.kmz']
};
}

Expand All @@ -16,7 +17,28 @@ export default class KML {
}

async convert() {
const dom = new DOMParser().parseFromString(String(await fs.readFile(path.resolve(os.tmpdir(), this.etl.task.asset))), 'text/xml');
const { ext } = path.parse(path.resolve(os.tmpdir(), this.etl.task.asset));

let asset;

if (ext === '.kmz') {
const zip = new StreamZip.async({
file: path.resolve(os.tmpdir(), this.etl.task.asset),
skipEntryNameValidation: true
});

const preentries = await zip.entries();

if (!preentries['doc.kml']) throw new Error('No doc.kml found in KMZ');

await zip.extract(null, os.tmpdir());

asset = path.resolve(os.tmpdir(), 'doc.kml');
} else {
asset = path.resolve(os.tmpdir(), this.etl.task.asset);
}

const dom = new DOMParser().parseFromString(String(await fs.readFile(asset)), 'text/xml');

const converted = kml(dom).features.map((feat) => {
return JSON.stringify(feat);
Expand Down
Loading

0 comments on commit 5344d81

Please sign in to comment.