From 1adb845a0a923370b84c792517b67ff914c34463 Mon Sep 17 00:00:00 2001 From: Kyle Hensel Date: Sat, 21 Dec 2024 12:04:12 +1300 Subject: [PATCH] remove azure CDN The output file is now deployed to github pages --- .github/workflows/sync.yml | 33 +++++- .github/workflows/{ci.yml => test.yml} | 10 +- .gitignore | 2 +- client/src/App.tsx | 6 +- package.json | 3 +- src/core/constants.ts | 2 +- src/main.ts | 7 +- src/upload/upload.ts | 34 ------ yarn.lock | 154 +------------------------ 9 files changed, 42 insertions(+), 209 deletions(-) rename .github/workflows/{ci.yml => test.yml} (72%) delete mode 100644 src/upload/upload.ts diff --git a/.github/workflows/sync.yml b/.github/workflows/sync.yml index 957e97a..610203a 100644 --- a/.github/workflows/sync.yml +++ b/.github/workflows/sync.yml @@ -6,6 +6,11 @@ on: # at 06:06am on Thursday NZST workflow_dispatch: +permissions: + contents: read + pages: write + id-token: write + jobs: sync: runs-on: ubuntu-latest @@ -30,10 +35,32 @@ jobs: - name: ⏬ Install run: | yarn - touch .env.local - name: 🚚 Run the conflation run: | yarn start - env: - AZ_CON: ${{ secrets.AZ_CON }} + + # we have to deploy the client & data together, so + # rebuild the client + - name: 🛠 Build Client + id: build + run: | + cd client + yarn build + + - name: 🚀 Upload dist folder + id: deployment + uses: actions/upload-pages-artifact@v3 + with: + path: client/dist/ + + deploy: + environment: + name: github-pages + url: ${{ steps.deployment.outputs.page_url }} + runs-on: ubuntu-latest + needs: sync + steps: + - name: 🚀 Deploy to GitHub Pages + id: deployment + uses: actions/deploy-pages@v4 diff --git a/.github/workflows/ci.yml b/.github/workflows/test.yml similarity index 72% rename from .github/workflows/ci.yml rename to .github/workflows/test.yml index 92e24cb..81c455f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/test.yml @@ -35,15 +35,9 @@ jobs: run: | yarn test + # this is just to check that it compiles + # the result is not deployed from here - name: 🛠 Build Client run: | cd client yarn build - - - name: ⚛ Deploy Client - if: ${{ github.ref == 'refs/heads/main' }} - uses: JamesIves/github-pages-deploy-action@v4.3.0 - with: - ACCESS_TOKEN: ${{ secrets.ACCESS_TOKEN }} - BRANCH: gh-pages - FOLDER: client/dist diff --git a/.gitignore b/.gitignore index 5a7ae48..79858a2 100644 --- a/.gitignore +++ b/.gitignore @@ -4,4 +4,4 @@ out dist coverage .yarn/* -.env.local +client/public/*.geo.json diff --git a/client/src/App.tsx b/client/src/App.tsx index a56348b..03b8a7c 100644 --- a/client/src/App.tsx +++ b/client/src/App.tsx @@ -10,16 +10,12 @@ import { Warnings } from './pages/Warnings'; import './main.css'; import { LayerInfo } from './pages/LayerInfo'; -const BASE_URL = localStorage.dev - ? 'http://localhost:3000' - : 'https://linz-addr-cdn.kyle.kiwi'; - export const App: React.FC = () => { const [data, setData] = useState(); const [error, setError] = useState(); useEffect(() => { - fetch(`${BASE_URL}/place-names.osmPatch.geo.json`) + fetch('./place-names.osmPatch.geo.json') .then((r) => r.json()) .then(setData) .catch(setError); diff --git a/package.json b/package.json index 724131c..5a32bdc 100644 --- a/package.json +++ b/package.json @@ -7,12 +7,11 @@ "client" ], "scripts": { - "start": "node --import tsx --env-file=.env.local src/main", + "start": "node --import tsx src/main", "lint": "eslint . && tsc", "test": "vitest" }, "dependencies": { - "@azure/storage-blob": "^12.23.0", "csv-parser": "^3.0.0", "typescript": "^5.4.5" }, diff --git a/src/core/constants.ts b/src/core/constants.ts index 8adbfa0..50416f4 100644 --- a/src/core/constants.ts +++ b/src/core/constants.ts @@ -21,5 +21,5 @@ export const configRawPath = path.join(tempFolder, 'raw-config.json'); export const outputFile = path.join( tempFolder, - 'place-names.osmPatch.geo.json', + '../client/public/place-names.osmPatch.geo.json', ); diff --git a/src/main.ts b/src/main.ts index d5f940b..6cb1d46 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,5 +1,6 @@ import { promises as fs } from 'node:fs'; -import { tempFolder } from './core/constants.js'; +import { dirname } from 'node:path'; +import { outputFile, tempFolder } from './core/constants.js'; import { fetchNzgb } from './api/nzgb.js'; import { fetchOsm } from './api/osm.js'; import { fetchWikidata } from './api/wikidata.js'; @@ -7,7 +8,6 @@ import { transformWikidata } from './transformer/wikidata.js'; import { transformOsm } from './transformer/osm.js'; import { transformNzgb } from './transformer/nzgb.js'; import { conflate } from './conflate/index.js'; -import { upload } from './upload/upload.js'; import { fetchConfig } from './api/config.js'; async function main() { @@ -24,7 +24,8 @@ async function main() { const result = await conflate({ nzgb, osm, wikidata, config }); - await upload(result); + await fs.mkdir(dirname(outputFile), { recursive: true }); + await fs.writeFile(outputFile, JSON.stringify(result, null, 2)); } await main(); diff --git a/src/upload/upload.ts b/src/upload/upload.ts deleted file mode 100644 index 84bf37e..0000000 --- a/src/upload/upload.ts +++ /dev/null @@ -1,34 +0,0 @@ -import { promises as fs } from 'node:fs'; -import path from 'node:path'; -import { BlobServiceClient } from '@azure/storage-blob'; -import type { Output } from '../core/types/output.def.js'; -import { outputFile } from '../core/constants.js'; - -const { AZ_CON, CI } = process.env; - -export async function upload(result: Output) { - await fs.writeFile(outputFile, JSON.stringify(result, null, 2)); - - if (!CI) { - console.log('🟢 Not uploading results.'); - return; - } - - console.log('🔵 Uploading...'); - if (!AZ_CON) { - throw new Error( - 'You need to create a file called ".env.local" in the root of the repository, and add the AZ_CON="..." variable', - ); - } - - const az = BlobServiceClient.fromConnectionString(AZ_CON); - const azContainer = az.getContainerClient('$web'); - - const fileClient = azContainer.getBlockBlobClient(path.basename(outputFile)); - await fileClient.uploadFile(outputFile); - await fileClient.setHTTPHeaders({ - blobContentType: 'application/json', - }); - - console.log('\tDone'); -} diff --git a/yarn.lock b/yarn.lock index b091cf4..a43c042 100644 --- a/yarn.lock +++ b/yarn.lock @@ -15,148 +15,6 @@ __metadata: languageName: node linkType: hard -"@azure/abort-controller@npm:^2.0.0, @azure/abort-controller@npm:^2.1.2": - version: 2.1.2 - resolution: "@azure/abort-controller@npm:2.1.2" - dependencies: - tslib: "npm:^2.6.2" - checksum: 10c0/3771b6820e33ebb56e79c7c68e2288296b8c2529556fbd29cf4cf2fbff7776e7ce1120072972d8df9f1bf50e2c3224d71a7565362b589595563f710b8c3d7b79 - languageName: node - linkType: hard - -"@azure/core-auth@npm:^1.4.0, @azure/core-auth@npm:^1.8.0": - version: 1.9.0 - resolution: "@azure/core-auth@npm:1.9.0" - dependencies: - "@azure/abort-controller": "npm:^2.0.0" - "@azure/core-util": "npm:^1.11.0" - tslib: "npm:^2.6.2" - checksum: 10c0/b7d8f33b81a8c9a76531acacc7af63d888429f0d763bb1ab8e28e91ddbf1626fc19cf8ca74f79c39b0a3e5acb315bdc4c4276fb979816f315712ea1bd611273d - languageName: node - linkType: hard - -"@azure/core-client@npm:^1.3.0, @azure/core-client@npm:^1.6.2": - version: 1.9.2 - resolution: "@azure/core-client@npm:1.9.2" - dependencies: - "@azure/abort-controller": "npm:^2.0.0" - "@azure/core-auth": "npm:^1.4.0" - "@azure/core-rest-pipeline": "npm:^1.9.1" - "@azure/core-tracing": "npm:^1.0.0" - "@azure/core-util": "npm:^1.6.1" - "@azure/logger": "npm:^1.0.0" - tslib: "npm:^2.6.2" - checksum: 10c0/4dab1f3b070f7c2c5a8390f81c7afdf31c030ad0599e75e16b9684959fb666cb57d34b63977639a60a7535f63f30a8a708210e8e48ff68a30732b7518044ebce - languageName: node - linkType: hard - -"@azure/core-http-compat@npm:^2.0.0": - version: 2.1.2 - resolution: "@azure/core-http-compat@npm:2.1.2" - dependencies: - "@azure/abort-controller": "npm:^2.0.0" - "@azure/core-client": "npm:^1.3.0" - "@azure/core-rest-pipeline": "npm:^1.3.0" - checksum: 10c0/e7b5374819d740c96c075956c756a753b7e9f6d7774bbadcc5000c3c4f808554e4d7146ccde7b94bcb21c39ed4a7e5b043b2a3b7d208b959310ea7e1440decca - languageName: node - linkType: hard - -"@azure/core-lro@npm:^2.2.0": - version: 2.7.2 - resolution: "@azure/core-lro@npm:2.7.2" - dependencies: - "@azure/abort-controller": "npm:^2.0.0" - "@azure/core-util": "npm:^1.2.0" - "@azure/logger": "npm:^1.0.0" - tslib: "npm:^2.6.2" - checksum: 10c0/bee809e47661b40021bbbedf88de54019715fdfcc95ac552b1d901719c29d78e293eeab51257b8f5155aac768eb4ea420715004d00d6e32109f5f97db5960d39 - languageName: node - linkType: hard - -"@azure/core-paging@npm:^1.1.1": - version: 1.6.2 - resolution: "@azure/core-paging@npm:1.6.2" - dependencies: - tslib: "npm:^2.6.2" - checksum: 10c0/c727782f8dc66eff50c03421af2ca55f497f33e14ec845f5918d76661c57bc8e3a7ca9fa3d39181287bfbfa45f28cb3d18b67c31fd36bbe34146387dbd07b440 - languageName: node - linkType: hard - -"@azure/core-rest-pipeline@npm:^1.10.1, @azure/core-rest-pipeline@npm:^1.3.0, @azure/core-rest-pipeline@npm:^1.9.1": - version: 1.18.1 - resolution: "@azure/core-rest-pipeline@npm:1.18.1" - dependencies: - "@azure/abort-controller": "npm:^2.0.0" - "@azure/core-auth": "npm:^1.8.0" - "@azure/core-tracing": "npm:^1.0.1" - "@azure/core-util": "npm:^1.11.0" - "@azure/logger": "npm:^1.0.0" - http-proxy-agent: "npm:^7.0.0" - https-proxy-agent: "npm:^7.0.0" - tslib: "npm:^2.6.2" - checksum: 10c0/e63d110f799a74ed20925e59ee70eced355f76130a2283393ce109b49365c97a436e8ddde29badee138c17cf0ecf33c26b9ce3cfbf64cf98b904ab50e6bdedff - languageName: node - linkType: hard - -"@azure/core-tracing@npm:^1.0.0, @azure/core-tracing@npm:^1.0.1, @azure/core-tracing@npm:^1.1.2": - version: 1.2.0 - resolution: "@azure/core-tracing@npm:1.2.0" - dependencies: - tslib: "npm:^2.6.2" - checksum: 10c0/7cd114b3c11730a1b8b71d89b64f9d033dfe0710f2364ef65645683381e2701173c08ff8625a0b0bc65bb3c3e0de46c80fdb2735e37652425489b65a283f043d - languageName: node - linkType: hard - -"@azure/core-util@npm:^1.11.0, @azure/core-util@npm:^1.2.0, @azure/core-util@npm:^1.6.1": - version: 1.11.0 - resolution: "@azure/core-util@npm:1.11.0" - dependencies: - "@azure/abort-controller": "npm:^2.0.0" - tslib: "npm:^2.6.2" - checksum: 10c0/245c93ec7fb3f2cb3a0b2f3a3be8d02ee401acba3cdd71620aa9e4e3ca50d831849f692332327bdbe1238ab979a76218f16a5166488ee31d5b67004298d110a3 - languageName: node - linkType: hard - -"@azure/core-xml@npm:^1.4.3": - version: 1.4.4 - resolution: "@azure/core-xml@npm:1.4.4" - dependencies: - fast-xml-parser: "npm:^4.4.1" - tslib: "npm:^2.6.2" - checksum: 10c0/92c643a9b80272b27a7bf9b756627f21beec5289995f3188099f056d255de702e1f8959bfc0f14d7445a1f6da4d037957ba47d757545ade5e77f610c4124c3fa - languageName: node - linkType: hard - -"@azure/logger@npm:^1.0.0": - version: 1.1.4 - resolution: "@azure/logger@npm:1.1.4" - dependencies: - tslib: "npm:^2.6.2" - checksum: 10c0/5bc7792ef334e18f4893814e83cc61780a0effb927ba898095c75df1a01e1f3093dc7a63b6de549694cef76c25f43db850b82a48ec0fab5f9f1c1d2053af791d - languageName: node - linkType: hard - -"@azure/storage-blob@npm:^12.23.0": - version: 12.26.0 - resolution: "@azure/storage-blob@npm:12.26.0" - dependencies: - "@azure/abort-controller": "npm:^2.1.2" - "@azure/core-auth": "npm:^1.4.0" - "@azure/core-client": "npm:^1.6.2" - "@azure/core-http-compat": "npm:^2.0.0" - "@azure/core-lro": "npm:^2.2.0" - "@azure/core-paging": "npm:^1.1.1" - "@azure/core-rest-pipeline": "npm:^1.10.1" - "@azure/core-tracing": "npm:^1.1.2" - "@azure/core-util": "npm:^1.6.1" - "@azure/core-xml": "npm:^1.4.3" - "@azure/logger": "npm:^1.0.0" - events: "npm:^3.0.0" - tslib: "npm:^2.2.0" - checksum: 10c0/069b7a85dddb33ee793efd74fbc1a3377c6d14dbb11094c2ebae87e324f16d23292806d5dcdf04280456dafc4d960e847968f6f01e384039b47363d61faf1017 - languageName: node - linkType: hard - "@babel/code-frame@npm:^7.0.0, @babel/code-frame@npm:^7.25.9, @babel/code-frame@npm:^7.26.0": version: 7.26.2 resolution: "@babel/code-frame@npm:7.26.2" @@ -3245,13 +3103,6 @@ __metadata: languageName: node linkType: hard -"events@npm:^3.0.0": - version: 3.3.0 - resolution: "events@npm:3.3.0" - checksum: 10c0/d6b6f2adbccbcda74ddbab52ed07db727ef52e31a61ed26db9feb7dc62af7fc8e060defa65e5f8af9449b86b52cc1a1f6a79f2eafcf4e62add2b7a1fa4a432f6 - languageName: node - linkType: hard - "execa@npm:^8.0.1": version: 8.0.1 resolution: "execa@npm:8.0.1" @@ -3727,7 +3578,7 @@ __metadata: languageName: node linkType: hard -"https-proxy-agent@npm:^7.0.0, https-proxy-agent@npm:^7.0.1": +"https-proxy-agent@npm:^7.0.1": version: 7.0.5 resolution: "https-proxy-agent@npm:7.0.5" dependencies: @@ -4901,7 +4752,6 @@ __metadata: version: 0.0.0-use.local resolution: "place-name-conflation@workspace:." dependencies: - "@azure/storage-blob": "npm:^12.23.0" "@types/geojson": "npm:^7946.0.14" "@types/node": "npm:^20.14.0" csv-parser: "npm:^3.0.0" @@ -5870,7 +5720,7 @@ __metadata: languageName: node linkType: hard -"tslib@npm:^2.2.0, tslib@npm:^2.6.2, tslib@npm:^2.6.3": +"tslib@npm:^2.6.2, tslib@npm:^2.6.3": version: 2.8.1 resolution: "tslib@npm:2.8.1" checksum: 10c0/9c4759110a19c53f992d9aae23aac5ced636e99887b51b9e61def52611732872ff7668757d4e4c61f19691e36f4da981cd9485e869b4a7408d689f6bf1f14e62