From d7ec5310ef81423e693a714c3f9e965101eea60f Mon Sep 17 00:00:00 2001 From: Wentao Kuang Date: Tue, 14 Mar 2023 14:49:10 +1300 Subject: [PATCH 01/17] Move the union out of the calculation loop to improve the atrribution performance. --- .../lambda-tiler/src/__tests__/config.data.ts | 143 +++++++++++++++++- .../src/routes/__tests__/attribution.test.ts | 66 +++++++- .../lambda-tiler/src/routes/attribution.ts | 13 +- 3 files changed, 211 insertions(+), 11 deletions(-) diff --git a/packages/lambda-tiler/src/__tests__/config.data.ts b/packages/lambda-tiler/src/__tests__/config.data.ts index 85907683c..af5220652 100644 --- a/packages/lambda-tiler/src/__tests__/config.data.ts +++ b/packages/lambda-tiler/src/__tests__/config.data.ts @@ -78,7 +78,148 @@ export const Imagery3857: ConfigImagery = { width: 51977.179234057665, height: 30574.81131407339, }, - files: [], + files: [ + { + x: 19461478.89763212, + y: -4591419.415033963, + width: 305.7481131407044, + height: 305.7481131407044, + name: '17-129188-80552', + }, + { + x: 19502754.89290612, + y: -4603343.591446448, + width: 305.7481131407044, + height: 305.7481131407044, + name: '17-129323-80591', + }, + { + x: 19504283.633471873, + y: -4608847.057483015, + width: 611.4962262814096, + height: 611.4962262814096, + name: '16-64664-40304', + }, + { + x: 19509175.60328212, + y: -4605178.080125325, + width: 611.4962262814096, + height: 611.4962262814096, + name: '16-64672-40298', + }, + { + x: 19509175.60328212, + y: -4604566.583899044, + width: 611.4962262814096, + height: 611.4962262814096, + name: '16-64672-40297', + }, + { + x: 19459032.912726905, + y: -4582552.719752827, + width: 1222.9924525628148, + height: 1222.9924525628148, + name: '15-32295-20130', + }, + { + x: 19460255.905179467, + y: -4592336.659373329, + width: 1222.9924525628148, + height: 1222.9924525628148, + name: '15-32296-20138', + }, + { + x: 19501837.648566607, + y: -4609458.55370921, + width: 1222.9924525628148, + height: 1222.9924525628148, + name: '15-32330-20152', + }, + { + x: 19503060.64101917, + y: -4609458.55370921, + width: 1222.9924525628148, + height: 1222.9924525628148, + name: '15-32331-20152', + }, + { + x: 19503060.64101917, + y: -4603343.591446393, + width: 1222.9924525628148, + height: 1222.9924525628148, + name: '15-32331-20147', + }, + { + x: 19457809.920274343, + y: -4593559.651825892, + width: 2445.9849051256297, + height: 2445.9849051256297, + name: '14-16147-10069', + }, + { + x: 19457809.920274343, + y: -4591113.666920764, + width: 2445.9849051256297, + height: 2445.9849051256297, + name: '14-16147-10068', + }, + { + x: 19457809.920274343, + y: -4588667.682015641, + width: 2445.9849051256297, + height: 2445.9849051256297, + name: '14-16147-10067', + }, + { + x: 19457809.920274343, + y: -4581329.727300262, + width: 2445.9849051256297, + height: 2445.9849051256297, + name: '14-16147-10064', + }, + { + x: 19460255.905179467, + y: -4591113.666920764, + width: 2445.9849051256297, + height: 2445.9849051256297, + name: '14-16148-10068', + }, + { + x: 19460255.905179586, + y: -4588667.682015713, + width: 4891.969810251274, + height: 4891.969810251274, + name: '13-8074-5033', + }, + { + x: 19460255.905179586, + y: -4583775.712205462, + width: 4891.969810251274, + height: 4891.969810251274, + name: '13-8074-5032', + }, + { + x: 19499391.663661595, + y: -4608235.561256718, + width: 4891.969810251274, + height: 4891.969810251274, + name: '13-8082-5037', + }, + { + x: 19504283.63347185, + y: -4608235.561256718, + width: 4891.969810251274, + height: 4891.969810251274, + name: '13-8083-5037', + }, + { + x: 19504283.63347185, + y: -4603343.591446467, + width: 4891.969810251274, + height: 4891.969810251274, + name: '13-8083-5036', + }, + ], }; export const Provider: ConfigProvider = { diff --git a/packages/lambda-tiler/src/routes/__tests__/attribution.test.ts b/packages/lambda-tiler/src/routes/__tests__/attribution.test.ts index 8e826a7b7..022d6471f 100644 --- a/packages/lambda-tiler/src/routes/__tests__/attribution.test.ts +++ b/packages/lambda-tiler/src/routes/__tests__/attribution.test.ts @@ -1,7 +1,8 @@ import { Attribution } from '@basemaps/attribution'; import { ConfigProviderMemory } from '@basemaps/config'; -import { Nztm2000QuadTms } from '@basemaps/geo'; -import { LogConfig } from '@basemaps/shared'; +import { GoogleTms, Nztm2000QuadTms } from '@basemaps/geo'; +import { LogConfig, Projection } from '@basemaps/shared'; +import { BBox } from '@linzjs/geojson'; import { HttpHeader } from '@linzjs/lambda'; import o from 'ospec'; import sinon from 'sinon'; @@ -9,6 +10,7 @@ import { handler } from '../../index.js'; import { ConfigLoader } from '../../util/config.loader.js'; import { FakeData, Imagery2193, Imagery3857, Provider, TileSetAerial } from '../../__tests__/config.data.js'; import { mockUrlRequest } from '../../__tests__/xyz.util.js'; +import { createCoordinates } from '../attribution.js'; // const ExpectedJson = { // id: 'aerial_WebMercatorQuad', @@ -387,4 +389,64 @@ o.spec('/v1/attribution', () => { o(output.collections[0].summaries['linz:zoom']).deepEquals({ min: 0, max: Nztm2000QuadTms.maxZoom }); }); }); + + o('should create valid coordinates', async () => { + //bbox: BBox, files: NamedBounds[], proj: Projection + const bbox = [174.79248047, -38.21228805, 175.25939941, -37.99616268] as BBox; + const proj = Projection.get(GoogleTms); + const coordinates = createCoordinates(bbox, Imagery3857.files, proj); + console.log(JSON.stringify(coordinates)); + o(coordinates).deepEquals([ + [ + [ + [174.79247149, -38.09998972], + [174.81446211, -38.09998972], + [174.81446211, -38.09134368], + [174.82544844, -38.09134368], + [174.82544844, -38.08485848], + [174.82819502, -38.08485848], + [174.82819502, -38.08269662], + [174.83643476, -38.08269662], + [174.83643476, -38.06539942], + [174.85840742, -38.06539942], + [174.85840742, -37.9961556], + [174.81446211, -37.9961556], + [174.81446211, -37.9961556], + [174.79247149, -37.9961556], + [174.79247149, -38.01348331], + [174.80345781, -38.01348331], + [174.80345781, -38.02213855], + [174.81444414, -38.02213855], + [174.81444414, -38.04808399], + [174.79247149, -38.04808399], + [174.79247149, -38.09998972], + ], + ], + [ + [ + [175.16600664, -38.20366238], + [175.1879793, -38.20366238], + [175.1879793, -38.21229511], + [175.20996992, -38.21229511], + [175.20996992, -38.20797887], + [175.21546308, -38.20797887], + [175.21546308, -38.20366238], + [175.25391523, -38.20366238], + [175.25391523, -38.18207606], + [175.2594084, -38.18207606], + [175.2594084, -38.17342562], + [175.25391523, -38.17342562], + [175.25391523, -38.13454951], + [175.20995195, -38.13454951], + [175.20995195, -38.16046922], + [175.19896563, -38.16046922], + [175.19896563, -38.16694771], + [175.19621904, -38.16694771], + [175.19621904, -38.16910707], + [175.16600664, -38.16910707], + [175.16600664, -38.20366238], + ], + ], + ]); + }); }); diff --git a/packages/lambda-tiler/src/routes/attribution.ts b/packages/lambda-tiler/src/routes/attribution.ts index f08ae3261..83245713b 100644 --- a/packages/lambda-tiler/src/routes/attribution.ts +++ b/packages/lambda-tiler/src/routes/attribution.ts @@ -45,23 +45,20 @@ function roundPair(p: Pair): Pair { * @param files in target projection * @return MultiPolygon in WGS84 */ -function createCoordinates(bbox: BBox, files: NamedBounds[], proj: Projection): MultiPolygon { +export function createCoordinates(bbox: BBox, files: NamedBounds[], proj: Projection): MultiPolygon { if (Wgs84.delta(bbox[0], bbox[2]) <= 0) { // This bounds spans more than half the globe which multiPolygonToWgs84 can't handle; just // return bbox as polygon return Wgs84.bboxToMultiPolygon(bbox); } - let coordinates: MultiPolygon = []; - + // let coordinates: MultiPolygon = []; + const polygons: MultiPolygon = []; // merge imagery bounds - for (const image of files) { - const poly = [Bounds.fromJson(image).pad(SmoothPadding).toPolygon()] as MultiPolygon; - coordinates = union(coordinates, poly); - } + for (const image of files) polygons.push(Bounds.fromJson(image).pad(SmoothPadding).toPolygon()); + const coordinates = union(polygons); const roundToWgs84 = (p: number[]): number[] => roundPair(proj.toWgs84(p) as Pair); - return multiPolygonToWgs84(coordinates, roundToWgs84); } From 714230419bf07102cfb66e8faaedc54a647d94c0 Mon Sep 17 00:00:00 2001 From: Wentao Kuang Date: Tue, 14 Mar 2023 15:00:52 +1300 Subject: [PATCH 02/17] Remove comment out code. --- packages/lambda-tiler/src/routes/attribution.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/lambda-tiler/src/routes/attribution.ts b/packages/lambda-tiler/src/routes/attribution.ts index 83245713b..b8856644f 100644 --- a/packages/lambda-tiler/src/routes/attribution.ts +++ b/packages/lambda-tiler/src/routes/attribution.ts @@ -52,7 +52,6 @@ export function createCoordinates(bbox: BBox, files: NamedBounds[], proj: Projec return Wgs84.bboxToMultiPolygon(bbox); } - // let coordinates: MultiPolygon = []; const polygons: MultiPolygon = []; // merge imagery bounds for (const image of files) polygons.push(Bounds.fromJson(image).pad(SmoothPadding).toPolygon()); From 211fcbdda91aea0b6f7e9ae3fbe8e9d25e6cd574 Mon Sep 17 00:00:00 2001 From: Wentao Kuang Date: Wed, 15 Mar 2023 10:48:33 +1300 Subject: [PATCH 03/17] Add smoke test for attribution api --- .github/workflows/screenshot.yml | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/.github/workflows/screenshot.yml b/.github/workflows/screenshot.yml index 0383b2da4..d9d70a8a8 100644 --- a/.github/workflows/screenshot.yml +++ b/.github/workflows/screenshot.yml @@ -1,6 +1,6 @@ name: screenshot -on: +on: pull_request: push: branches: @@ -24,7 +24,7 @@ jobs: npx lerna run bundle --stream npm pack --workspaces env: - NODE_ENV: "production" + NODE_ENV: 'production' - name: (NonProd) Configure AWS Credentials uses: aws-actions/configure-aws-credentials@v1.6.1 @@ -32,16 +32,29 @@ jobs: aws-region: ap-southeast-2 mask-aws-account-id: true role-to-assume: ${{ secrets.AWS_ROLE_SCREENSHOT }} - + - name: (Screenshot) Screenshot Pull Request Changes run: | ./packages/cli/bin/bmc.js serve --config s3://linz-basemaps/config/config-latest.json.gz & - + # Wait for the server to start timeout 30 bash -c 'while [[ "$(curl -s -o /dev/null -w ''%{http_code}'' http://localhost:5000/v1/version)" != "200" ]]; do sleep 0.5; done' || false - + docker run --rm --network="host" -v $PWD:$PWD ghcr.io/linz/basemaps-screenshot/cli:v1 --url http://localhost:5000 --output $PWD/.artifacts/visual-snapshots - + + - name: (smoke-test) Screenshot Pull Request Changes + continue-on-error: true + run: | + # ./packages/cli/bin/bmc.js serve --config s3://linz-basemaps/config/config-latest.json.gz & + + # # Wait for the server to start + # timeout 30 bash -c 'while [[ "$(curl -s -o /dev/null -w ''%{http_code}'' http://localhost:5000/v1/version)" != "200" ]]; do sleep 0.5; done' || false + + # Validation screenshot + curl -s -X GET http://localhost:5000/v1/tiles/aerial/WebMercatorQuad/attribution.json?api=${{ secrets.BASEMAPS_API_KEY }} > attribution_3857_local.json + curl -s -X GET https://basemaps.linz.govt.nz/v1/tiles/aerial/WebMercatorQuad/attribution.json?api=${{ secrets.BASEMAPS_API_KEY }} > attribution_3857_prod.json # Give longer timeout as production have performance issue now. + diff <(jq --sort-keys . attribution_3857_local.json) <(jq --sort-keys . attribution_3857_prod.json) + - name: Save snapshots uses: getsentry/action-visual-snapshot@v2 with: @@ -70,5 +83,5 @@ jobs: id: visual-snapshots-diff uses: blacha/action-visual-snapshot@v2 with: - storage-prefix: "s3://linz-basemaps-screenshot" - storage-url: "https://d25mfjh9syaxsr.cloudfront.net" + storage-prefix: 's3://linz-basemaps-screenshot' + storage-url: 'https://d25mfjh9syaxsr.cloudfront.net' From ffc2acd0929e3cf64a053f89b8ec1ee3eade5ef8 Mon Sep 17 00:00:00 2001 From: Wentao Kuang Date: Wed, 15 Mar 2023 11:00:11 +1300 Subject: [PATCH 04/17] Test for 2193 --- .github/workflows/screenshot.yml | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/.github/workflows/screenshot.yml b/.github/workflows/screenshot.yml index d9d70a8a8..62eba1b09 100644 --- a/.github/workflows/screenshot.yml +++ b/.github/workflows/screenshot.yml @@ -40,7 +40,7 @@ jobs: # Wait for the server to start timeout 30 bash -c 'while [[ "$(curl -s -o /dev/null -w ''%{http_code}'' http://localhost:5000/v1/version)" != "200" ]]; do sleep 0.5; done' || false - docker run --rm --network="host" -v $PWD:$PWD ghcr.io/linz/basemaps-screenshot/cli:v1 --url http://localhost:5000 --output $PWD/.artifacts/visual-snapshots + # docker run --rm --network="host" -v $PWD:$PWD ghcr.io/linz/basemaps-screenshot/cli:v1 --url http://localhost:5000 --output $PWD/.artifacts/visual-snapshots - name: (smoke-test) Screenshot Pull Request Changes continue-on-error: true @@ -52,9 +52,13 @@ jobs: # Validation screenshot curl -s -X GET http://localhost:5000/v1/tiles/aerial/WebMercatorQuad/attribution.json?api=${{ secrets.BASEMAPS_API_KEY }} > attribution_3857_local.json - curl -s -X GET https://basemaps.linz.govt.nz/v1/tiles/aerial/WebMercatorQuad/attribution.json?api=${{ secrets.BASEMAPS_API_KEY }} > attribution_3857_prod.json # Give longer timeout as production have performance issue now. + curl --connect-timeout -s -X GET https://basemaps.linz.govt.nz/v1/tiles/aerial/WebMercatorQuad/attribution.json?api=${{ secrets.BASEMAPS_API_KEY }} > attribution_3857_prod.json # Give longer timeout as production have performance issue now. + + curl -s -X GET http://localhost:5000/v1/tiles/aerial/NZTM2000Quad/attribution.json?api=${{ secrets.BASEMAPS_API_KEY }} > attribution_2193_local.json + curl --connect-timeout 100 -s -X GET https://basemaps.linz.govt.nz/v1/tiles/aerial/NZTM2000Quad/attribution.json?api=${{ secrets.BASEMAPS_API_KEY }} > attribution_2193_prod.json # Give longer timeout as production have performance issue now. + diff <(jq --sort-keys . attribution_3857_local.json) <(jq --sort-keys . attribution_3857_prod.json) - + diff <(jq --sort-keys . attribution_2193_local.json) <(jq --sort-keys . attribution_2193_prod.json) - name: Save snapshots uses: getsentry/action-visual-snapshot@v2 with: From c83e8839ac88a659c27213eed15f4fcc98770770 Mon Sep 17 00:00:00 2001 From: Wentao Kuang Date: Wed, 15 Mar 2023 11:14:17 +1300 Subject: [PATCH 05/17] continue on error --- .github/workflows/screenshot.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/screenshot.yml b/.github/workflows/screenshot.yml index 62eba1b09..d7bc517f1 100644 --- a/.github/workflows/screenshot.yml +++ b/.github/workflows/screenshot.yml @@ -43,7 +43,6 @@ jobs: # docker run --rm --network="host" -v $PWD:$PWD ghcr.io/linz/basemaps-screenshot/cli:v1 --url http://localhost:5000 --output $PWD/.artifacts/visual-snapshots - name: (smoke-test) Screenshot Pull Request Changes - continue-on-error: true run: | # ./packages/cli/bin/bmc.js serve --config s3://linz-basemaps/config/config-latest.json.gz & @@ -52,13 +51,15 @@ jobs: # Validation screenshot curl -s -X GET http://localhost:5000/v1/tiles/aerial/WebMercatorQuad/attribution.json?api=${{ secrets.BASEMAPS_API_KEY }} > attribution_3857_local.json - curl --connect-timeout -s -X GET https://basemaps.linz.govt.nz/v1/tiles/aerial/WebMercatorQuad/attribution.json?api=${{ secrets.BASEMAPS_API_KEY }} > attribution_3857_prod.json # Give longer timeout as production have performance issue now. + curl --connect-timeout 100 -s -X GET https://basemaps.linz.govt.nz/v1/tiles/aerial/WebMercatorQuad/attribution.json?api=${{ secrets.BASEMAPS_API_KEY }} > attribution_3857_prod.json # Give longer timeout as production have performance issue now. curl -s -X GET http://localhost:5000/v1/tiles/aerial/NZTM2000Quad/attribution.json?api=${{ secrets.BASEMAPS_API_KEY }} > attribution_2193_local.json curl --connect-timeout 100 -s -X GET https://basemaps.linz.govt.nz/v1/tiles/aerial/NZTM2000Quad/attribution.json?api=${{ secrets.BASEMAPS_API_KEY }} > attribution_2193_prod.json # Give longer timeout as production have performance issue now. diff <(jq --sort-keys . attribution_3857_local.json) <(jq --sort-keys . attribution_3857_prod.json) diff <(jq --sort-keys . attribution_2193_local.json) <(jq --sort-keys . attribution_2193_prod.json) + continue-on-error: true + - name: Save snapshots uses: getsentry/action-visual-snapshot@v2 with: From 7dafa457af40dd5d5e0d56c47042154a88010bce Mon Sep 17 00:00:00 2001 From: Wentao Kuang Date: Wed, 15 Mar 2023 12:20:27 +1300 Subject: [PATCH 06/17] continue on error and log error --- .github/workflows/screenshot.yml | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/.github/workflows/screenshot.yml b/.github/workflows/screenshot.yml index d7bc517f1..148e12201 100644 --- a/.github/workflows/screenshot.yml +++ b/.github/workflows/screenshot.yml @@ -43,13 +43,9 @@ jobs: # docker run --rm --network="host" -v $PWD:$PWD ghcr.io/linz/basemaps-screenshot/cli:v1 --url http://localhost:5000 --output $PWD/.artifacts/visual-snapshots - name: (smoke-test) Screenshot Pull Request Changes + id: attribution + continue-on-error: true run: | - # ./packages/cli/bin/bmc.js serve --config s3://linz-basemaps/config/config-latest.json.gz & - - # # Wait for the server to start - # timeout 30 bash -c 'while [[ "$(curl -s -o /dev/null -w ''%{http_code}'' http://localhost:5000/v1/version)" != "200" ]]; do sleep 0.5; done' || false - - # Validation screenshot curl -s -X GET http://localhost:5000/v1/tiles/aerial/WebMercatorQuad/attribution.json?api=${{ secrets.BASEMAPS_API_KEY }} > attribution_3857_local.json curl --connect-timeout 100 -s -X GET https://basemaps.linz.govt.nz/v1/tiles/aerial/WebMercatorQuad/attribution.json?api=${{ secrets.BASEMAPS_API_KEY }} > attribution_3857_prod.json # Give longer timeout as production have performance issue now. @@ -58,7 +54,10 @@ jobs: diff <(jq --sort-keys . attribution_3857_local.json) <(jq --sort-keys . attribution_3857_prod.json) diff <(jq --sort-keys . attribution_2193_local.json) <(jq --sort-keys . attribution_2193_prod.json) - continue-on-error: true + + - name: API validation + if: steps.attribution.outcome != 'success' + run: echo 'Attribution validation failure' - name: Save snapshots uses: getsentry/action-visual-snapshot@v2 From 4cc55f8810adf241f01ecc46bc75e2f019febdb4 Mon Sep 17 00:00:00 2001 From: Wentao Kuang Date: Wed, 15 Mar 2023 12:54:25 +1300 Subject: [PATCH 07/17] Add validation for wmts --- .github/workflows/screenshot.yml | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/.github/workflows/screenshot.yml b/.github/workflows/screenshot.yml index 148e12201..d4714b54e 100644 --- a/.github/workflows/screenshot.yml +++ b/.github/workflows/screenshot.yml @@ -11,7 +11,7 @@ jobs: runs-on: ubuntu-latest env: BASEMAPS_BUCKET: linz-basemaps - + PR_NUMBER: ${{ github.event.number }} permissions: id-token: write contents: read @@ -42,7 +42,7 @@ jobs: # docker run --rm --network="host" -v $PWD:$PWD ghcr.io/linz/basemaps-screenshot/cli:v1 --url http://localhost:5000 --output $PWD/.artifacts/visual-snapshots - - name: (smoke-test) Screenshot Pull Request Changes + - name: (Smoke Test) Attribution validation id: attribution continue-on-error: true run: | @@ -55,9 +55,22 @@ jobs: diff <(jq --sort-keys . attribution_3857_local.json) <(jq --sort-keys . attribution_3857_prod.json) diff <(jq --sort-keys . attribution_2193_local.json) <(jq --sort-keys . attribution_2193_prod.json) + - name: (Smoke Test) WMTS validation + id: wmts + continue-on-error: true + run: | + curl -s -X GET http://localhost:5000/v1/tiles/aerial/WebMercatorQuad/WMTSCapabilities.xml?api=${{ secrets.BASEMAPS_API_KEY }} > wmts_3857_local.xml + curl -s -X GET https://basemaps.linz.govt.nz/v1/tiles/aerial/WebMercatorQuad/WMTSCapabilities.xml?api=${{ secrets.BASEMAPS_API_KEY }} > wmts_3857_prod.xml + + curl -s -X GET http://localhost:5000/v1/tiles/aerial/NZTM2000Quad/WMTSCapabilities.xml?api=${{ secrets.BASEMAPS_API_KEY }} > wmts_2193_local.xml + curl --connect-timeout 100 -s -X GET https://basemaps.linz.govt.nz/v1/tiles/aerial/NZTM2000Quad/WMTSCapabilities.xml?api=?api=${{ secrets.BASEMAPS_API_KEY }} > wmts_2193_prod.xml + + diff <(xmllint --c14n wmts_3857_local.xml) <(xmllint --c14n wmts_3857_prod.xml ) + diff <(xmllint --c14n wmts_2193_local.xml) <(xmllint --c14n wmts_2193_prod.xml) + - name: API validation - if: steps.attribution.outcome != 'success' - run: echo 'Attribution validation failure' + if: steps.attribution.outcome != 'success' || steps.wmts.outcome != 'success' + run: gh pr comment ${PR_NUMBER} --body "API validation failure." - name: Save snapshots uses: getsentry/action-visual-snapshot@v2 From 5bc5095fcd80b64f5ac8b69fa6ff9f49eddbcee4 Mon Sep 17 00:00:00 2001 From: Wentao Kuang Date: Wed, 15 Mar 2023 13:07:09 +1300 Subject: [PATCH 08/17] Update github token --- .github/workflows/screenshot.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/screenshot.yml b/.github/workflows/screenshot.yml index d4714b54e..fa4041a26 100644 --- a/.github/workflows/screenshot.yml +++ b/.github/workflows/screenshot.yml @@ -11,6 +11,7 @@ jobs: runs-on: ubuntu-latest env: BASEMAPS_BUCKET: linz-basemaps + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} PR_NUMBER: ${{ github.event.number }} permissions: id-token: write @@ -65,6 +66,7 @@ jobs: curl -s -X GET http://localhost:5000/v1/tiles/aerial/NZTM2000Quad/WMTSCapabilities.xml?api=${{ secrets.BASEMAPS_API_KEY }} > wmts_2193_local.xml curl --connect-timeout 100 -s -X GET https://basemaps.linz.govt.nz/v1/tiles/aerial/NZTM2000Quad/WMTSCapabilities.xml?api=?api=${{ secrets.BASEMAPS_API_KEY }} > wmts_2193_prod.xml + apt -y install libxml2-utils diff <(xmllint --c14n wmts_3857_local.xml) <(xmllint --c14n wmts_3857_prod.xml ) diff <(xmllint --c14n wmts_2193_local.xml) <(xmllint --c14n wmts_2193_prod.xml) From 0a56bd61e06cb60d22caae7502a6fc3f960b790c Mon Sep 17 00:00:00 2001 From: Wentao Kuang Date: Wed, 15 Mar 2023 13:09:24 +1300 Subject: [PATCH 09/17] gh token --- .github/workflows/screenshot.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/screenshot.yml b/.github/workflows/screenshot.yml index fa4041a26..dae0e78a3 100644 --- a/.github/workflows/screenshot.yml +++ b/.github/workflows/screenshot.yml @@ -11,7 +11,7 @@ jobs: runs-on: ubuntu-latest env: BASEMAPS_BUCKET: linz-basemaps - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + GH_TOKEN: ${{ github.token }} PR_NUMBER: ${{ github.event.number }} permissions: id-token: write From a0a9a2fe9b5f97514049570854d60348e64fc82e Mon Sep 17 00:00:00 2001 From: Wentao Kuang Date: Wed, 15 Mar 2023 13:15:57 +1300 Subject: [PATCH 10/17] Install xmllint at root --- .github/workflows/screenshot.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/screenshot.yml b/.github/workflows/screenshot.yml index dae0e78a3..1d0972fe2 100644 --- a/.github/workflows/screenshot.yml +++ b/.github/workflows/screenshot.yml @@ -66,7 +66,7 @@ jobs: curl -s -X GET http://localhost:5000/v1/tiles/aerial/NZTM2000Quad/WMTSCapabilities.xml?api=${{ secrets.BASEMAPS_API_KEY }} > wmts_2193_local.xml curl --connect-timeout 100 -s -X GET https://basemaps.linz.govt.nz/v1/tiles/aerial/NZTM2000Quad/WMTSCapabilities.xml?api=?api=${{ secrets.BASEMAPS_API_KEY }} > wmts_2193_prod.xml - apt -y install libxml2-utils + sudo apt-get install libxml2-utils diff <(xmllint --c14n wmts_3857_local.xml) <(xmllint --c14n wmts_3857_prod.xml ) diff <(xmllint --c14n wmts_2193_local.xml) <(xmllint --c14n wmts_2193_prod.xml) From e4185a96da397b005ff1ba6f34909e5f113514cc Mon Sep 17 00:00:00 2001 From: Wentao Kuang Date: Wed, 15 Mar 2023 13:24:27 +1300 Subject: [PATCH 11/17] Add issue write permission --- .github/workflows/screenshot.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/screenshot.yml b/.github/workflows/screenshot.yml index 1d0972fe2..8fe55c21d 100644 --- a/.github/workflows/screenshot.yml +++ b/.github/workflows/screenshot.yml @@ -16,6 +16,8 @@ jobs: permissions: id-token: write contents: read + issues: write # This permission shouldn't needed as there is a bug currently for gh pr edit. https://github.com/cli/cli/issues/4631 + pull-requests: write steps: - uses: linz/action-typescript@v2 From b22263679390e61989177d96031269e1a10e7a76 Mon Sep 17 00:00:00 2001 From: Wentao Kuang Date: Wed, 15 Mar 2023 13:40:27 +1300 Subject: [PATCH 12/17] Replace the local host in resource url --- .github/workflows/screenshot.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/screenshot.yml b/.github/workflows/screenshot.yml index 8fe55c21d..606006308 100644 --- a/.github/workflows/screenshot.yml +++ b/.github/workflows/screenshot.yml @@ -69,6 +69,9 @@ jobs: curl --connect-timeout 100 -s -X GET https://basemaps.linz.govt.nz/v1/tiles/aerial/NZTM2000Quad/WMTSCapabilities.xml?api=?api=${{ secrets.BASEMAPS_API_KEY }} > wmts_2193_prod.xml sudo apt-get install libxml2-utils + # Replace the localhost in the resource url before comparison + sed -i -e 's/http://localhost:5000/https://basemaps.linz.govt.nz/g' wmts_3857_local.xml + sed -i -e 's/http://localhost:5000/https://basemaps.linz.govt.nz/g' wmts_2193_local.xml diff <(xmllint --c14n wmts_3857_local.xml) <(xmllint --c14n wmts_3857_prod.xml ) diff <(xmllint --c14n wmts_2193_local.xml) <(xmllint --c14n wmts_2193_prod.xml) From bb18190ab0f39e7411df8d84890f603c0da267c4 Mon Sep 17 00:00:00 2001 From: Wentao Kuang Date: Wed, 15 Mar 2023 13:51:09 +1300 Subject: [PATCH 13/17] Update sed --- .github/workflows/screenshot.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/screenshot.yml b/.github/workflows/screenshot.yml index 606006308..42ce6b3c9 100644 --- a/.github/workflows/screenshot.yml +++ b/.github/workflows/screenshot.yml @@ -70,8 +70,8 @@ jobs: sudo apt-get install libxml2-utils # Replace the localhost in the resource url before comparison - sed -i -e 's/http://localhost:5000/https://basemaps.linz.govt.nz/g' wmts_3857_local.xml - sed -i -e 's/http://localhost:5000/https://basemaps.linz.govt.nz/g' wmts_2193_local.xml + sed -i -e 's,http://localhost:5000,https://basemaps.linz.govt.nz,g' wmts_3857_local.xml + sed -i -e 's,http://localhost:5000,https://basemaps.linz.govt.nz,g' wmts_2193_local.xml diff <(xmllint --c14n wmts_3857_local.xml) <(xmllint --c14n wmts_3857_prod.xml ) diff <(xmllint --c14n wmts_2193_local.xml) <(xmllint --c14n wmts_2193_prod.xml) From 5508f39f33bc7102895e84b9a6e307d3ae6a9610 Mon Sep 17 00:00:00 2001 From: Wentao Kuang Date: Wed, 15 Mar 2023 13:58:12 +1300 Subject: [PATCH 14/17] Enable screenshots --- .github/workflows/screenshot.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/screenshot.yml b/.github/workflows/screenshot.yml index 42ce6b3c9..1eedf17e1 100644 --- a/.github/workflows/screenshot.yml +++ b/.github/workflows/screenshot.yml @@ -43,7 +43,7 @@ jobs: # Wait for the server to start timeout 30 bash -c 'while [[ "$(curl -s -o /dev/null -w ''%{http_code}'' http://localhost:5000/v1/version)" != "200" ]]; do sleep 0.5; done' || false - # docker run --rm --network="host" -v $PWD:$PWD ghcr.io/linz/basemaps-screenshot/cli:v1 --url http://localhost:5000 --output $PWD/.artifacts/visual-snapshots + docker run --rm --network="host" -v $PWD:$PWD ghcr.io/linz/basemaps-screenshot/cli:v1 --url http://localhost:5000 --output $PWD/.artifacts/visual-snapshots - name: (Smoke Test) Attribution validation id: attribution From 58abfe8fef6f9b5b8394b33ed4178bc993ef9eb2 Mon Sep 17 00:00:00 2001 From: Wentao Kuang Date: Wed, 15 Mar 2023 14:09:58 +1300 Subject: [PATCH 15/17] Remove the timeout for wmts --- .github/workflows/screenshot.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/screenshot.yml b/.github/workflows/screenshot.yml index 1eedf17e1..dfd9ad2b5 100644 --- a/.github/workflows/screenshot.yml +++ b/.github/workflows/screenshot.yml @@ -62,13 +62,13 @@ jobs: id: wmts continue-on-error: true run: | + sudo apt-get install libxml2-utils curl -s -X GET http://localhost:5000/v1/tiles/aerial/WebMercatorQuad/WMTSCapabilities.xml?api=${{ secrets.BASEMAPS_API_KEY }} > wmts_3857_local.xml curl -s -X GET https://basemaps.linz.govt.nz/v1/tiles/aerial/WebMercatorQuad/WMTSCapabilities.xml?api=${{ secrets.BASEMAPS_API_KEY }} > wmts_3857_prod.xml curl -s -X GET http://localhost:5000/v1/tiles/aerial/NZTM2000Quad/WMTSCapabilities.xml?api=${{ secrets.BASEMAPS_API_KEY }} > wmts_2193_local.xml - curl --connect-timeout 100 -s -X GET https://basemaps.linz.govt.nz/v1/tiles/aerial/NZTM2000Quad/WMTSCapabilities.xml?api=?api=${{ secrets.BASEMAPS_API_KEY }} > wmts_2193_prod.xml + curl -s -X GET https://basemaps.linz.govt.nz/v1/tiles/aerial/NZTM2000Quad/WMTSCapabilities.xml?api=${{ secrets.BASEMAPS_API_KEY }} > wmts_2193_prod.xml - sudo apt-get install libxml2-utils # Replace the localhost in the resource url before comparison sed -i -e 's,http://localhost:5000,https://basemaps.linz.govt.nz,g' wmts_3857_local.xml sed -i -e 's,http://localhost:5000,https://basemaps.linz.govt.nz,g' wmts_2193_local.xml From cb5c140ab33c91a58e2f57ece07e156c5fd6f954 Mon Sep 17 00:00:00 2001 From: Wentao Kuang Date: Wed, 15 Mar 2023 15:47:54 +1300 Subject: [PATCH 16/17] Remove the smoke test and move this into screenshot cli --- .github/workflows/screenshot.yml | 38 -------------------------------- 1 file changed, 38 deletions(-) diff --git a/.github/workflows/screenshot.yml b/.github/workflows/screenshot.yml index dfd9ad2b5..a9bf6d4d0 100644 --- a/.github/workflows/screenshot.yml +++ b/.github/workflows/screenshot.yml @@ -11,13 +11,9 @@ jobs: runs-on: ubuntu-latest env: BASEMAPS_BUCKET: linz-basemaps - GH_TOKEN: ${{ github.token }} - PR_NUMBER: ${{ github.event.number }} permissions: id-token: write contents: read - issues: write # This permission shouldn't needed as there is a bug currently for gh pr edit. https://github.com/cli/cli/issues/4631 - pull-requests: write steps: - uses: linz/action-typescript@v2 @@ -45,40 +41,6 @@ jobs: docker run --rm --network="host" -v $PWD:$PWD ghcr.io/linz/basemaps-screenshot/cli:v1 --url http://localhost:5000 --output $PWD/.artifacts/visual-snapshots - - name: (Smoke Test) Attribution validation - id: attribution - continue-on-error: true - run: | - curl -s -X GET http://localhost:5000/v1/tiles/aerial/WebMercatorQuad/attribution.json?api=${{ secrets.BASEMAPS_API_KEY }} > attribution_3857_local.json - curl --connect-timeout 100 -s -X GET https://basemaps.linz.govt.nz/v1/tiles/aerial/WebMercatorQuad/attribution.json?api=${{ secrets.BASEMAPS_API_KEY }} > attribution_3857_prod.json # Give longer timeout as production have performance issue now. - - curl -s -X GET http://localhost:5000/v1/tiles/aerial/NZTM2000Quad/attribution.json?api=${{ secrets.BASEMAPS_API_KEY }} > attribution_2193_local.json - curl --connect-timeout 100 -s -X GET https://basemaps.linz.govt.nz/v1/tiles/aerial/NZTM2000Quad/attribution.json?api=${{ secrets.BASEMAPS_API_KEY }} > attribution_2193_prod.json # Give longer timeout as production have performance issue now. - - diff <(jq --sort-keys . attribution_3857_local.json) <(jq --sort-keys . attribution_3857_prod.json) - diff <(jq --sort-keys . attribution_2193_local.json) <(jq --sort-keys . attribution_2193_prod.json) - - - name: (Smoke Test) WMTS validation - id: wmts - continue-on-error: true - run: | - sudo apt-get install libxml2-utils - curl -s -X GET http://localhost:5000/v1/tiles/aerial/WebMercatorQuad/WMTSCapabilities.xml?api=${{ secrets.BASEMAPS_API_KEY }} > wmts_3857_local.xml - curl -s -X GET https://basemaps.linz.govt.nz/v1/tiles/aerial/WebMercatorQuad/WMTSCapabilities.xml?api=${{ secrets.BASEMAPS_API_KEY }} > wmts_3857_prod.xml - - curl -s -X GET http://localhost:5000/v1/tiles/aerial/NZTM2000Quad/WMTSCapabilities.xml?api=${{ secrets.BASEMAPS_API_KEY }} > wmts_2193_local.xml - curl -s -X GET https://basemaps.linz.govt.nz/v1/tiles/aerial/NZTM2000Quad/WMTSCapabilities.xml?api=${{ secrets.BASEMAPS_API_KEY }} > wmts_2193_prod.xml - - # Replace the localhost in the resource url before comparison - sed -i -e 's,http://localhost:5000,https://basemaps.linz.govt.nz,g' wmts_3857_local.xml - sed -i -e 's,http://localhost:5000,https://basemaps.linz.govt.nz,g' wmts_2193_local.xml - diff <(xmllint --c14n wmts_3857_local.xml) <(xmllint --c14n wmts_3857_prod.xml ) - diff <(xmllint --c14n wmts_2193_local.xml) <(xmllint --c14n wmts_2193_prod.xml) - - - name: API validation - if: steps.attribution.outcome != 'success' || steps.wmts.outcome != 'success' - run: gh pr comment ${PR_NUMBER} --body "API validation failure." - - name: Save snapshots uses: getsentry/action-visual-snapshot@v2 with: From 390f3c002089f03658334e45d373a64abaac687a Mon Sep 17 00:00:00 2001 From: Wentao Kuang Date: Wed, 15 Mar 2023 15:49:07 +1300 Subject: [PATCH 17/17] Fix the formatting --- .github/workflows/screenshot.yml | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/.github/workflows/screenshot.yml b/.github/workflows/screenshot.yml index a9bf6d4d0..0383b2da4 100644 --- a/.github/workflows/screenshot.yml +++ b/.github/workflows/screenshot.yml @@ -1,6 +1,6 @@ name: screenshot -on: +on: pull_request: push: branches: @@ -11,6 +11,7 @@ jobs: runs-on: ubuntu-latest env: BASEMAPS_BUCKET: linz-basemaps + permissions: id-token: write contents: read @@ -23,7 +24,7 @@ jobs: npx lerna run bundle --stream npm pack --workspaces env: - NODE_ENV: 'production' + NODE_ENV: "production" - name: (NonProd) Configure AWS Credentials uses: aws-actions/configure-aws-credentials@v1.6.1 @@ -31,16 +32,16 @@ jobs: aws-region: ap-southeast-2 mask-aws-account-id: true role-to-assume: ${{ secrets.AWS_ROLE_SCREENSHOT }} - + - name: (Screenshot) Screenshot Pull Request Changes run: | ./packages/cli/bin/bmc.js serve --config s3://linz-basemaps/config/config-latest.json.gz & - + # Wait for the server to start timeout 30 bash -c 'while [[ "$(curl -s -o /dev/null -w ''%{http_code}'' http://localhost:5000/v1/version)" != "200" ]]; do sleep 0.5; done' || false - + docker run --rm --network="host" -v $PWD:$PWD ghcr.io/linz/basemaps-screenshot/cli:v1 --url http://localhost:5000 --output $PWD/.artifacts/visual-snapshots - + - name: Save snapshots uses: getsentry/action-visual-snapshot@v2 with: @@ -69,5 +70,5 @@ jobs: id: visual-snapshots-diff uses: blacha/action-visual-snapshot@v2 with: - storage-prefix: 's3://linz-basemaps-screenshot' - storage-url: 'https://d25mfjh9syaxsr.cloudfront.net' + storage-prefix: "s3://linz-basemaps-screenshot" + storage-url: "https://d25mfjh9syaxsr.cloudfront.net"