From ea4f1f69c3ada8cf32afc9884349f7772703ad60 Mon Sep 17 00:00:00 2001 From: alecdwm Date: Fri, 22 Sep 2023 03:52:22 +0000 Subject: [PATCH] wip: github publish ci --- .github/workflows/publish.yml | 54 ++++++++++++++++++++++ .github/workflows/{ci.yml => validate.yml} | 2 +- .gitignore | 2 + package.json | 3 +- scripts/publish.js | 50 ++++++++++++++++++++ 5 files changed, 109 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/publish.yml rename .github/workflows/{ci.yml => validate.yml} (97%) create mode 100644 scripts/publish.js diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 0000000000..67b254613a --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,54 @@ +name: Chaindata Publish + +on: + # runs on each commit pushed to the `main` branch + push: + branches: [main] + # runs at `0 minutes past the hour, every 6 hours`, starting at midnight UTC + schedule: + - cron: '0 0/6 * * *' + # can be run manually from the `Actions` tab + workflow_dispatch: + +# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages +permissions: + contents: read + pages: write + id-token: write + +concurrency: + # only run 1 job per branch/pr/etc at a time + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: ${{ github.event_name == 'pull_request' }} + +jobs: + publish: + name: 'Collate & publish chaindata to GitHub Pages' + timeout-minutes: 15 + runs-on: ubuntu-latest + + environment: + name: github-pages + url: ${{ steps.deployment.outputs.page_url }} + + steps: + - name: Checkout repo + uses: actions/checkout@v3 + - name: Setup Pages + uses: actions/configure-pages@v3 + - name: Setup Node.js environment + uses: actions/setup-node@v3 + with: + node-version: 18 + cache: yarn + - name: Install dependencies + run: yarn --immutable + - name: Collate chaindata + run: node scripts/publish.js + - name: Upload pages artifact + uses: actions/upload-pages-artifact@v2 + with: + path: 'dist' + - name: Deploy to GitHub Pages + id: deployment + uses: actions/deploy-pages@v2 diff --git a/.github/workflows/ci.yml b/.github/workflows/validate.yml similarity index 97% rename from .github/workflows/ci.yml rename to .github/workflows/validate.yml index 1b2b1f9c13..86910509e8 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/validate.yml @@ -1,4 +1,4 @@ -name: Talisman Chaindata CI +name: Chaindata Validate on: push: diff --git a/.gitignore b/.gitignore index a8fca6e486..afaf99636c 100644 --- a/.gitignore +++ b/.gitignore @@ -20,3 +20,5 @@ yarn-debug.log* yarn-error.log* .pnpm-debug.log* yarn-error.log* + +dist diff --git a/package.json b/package.json index e2af578958..e3f0960188 100644 --- a/package.json +++ b/package.json @@ -22,7 +22,8 @@ "update": "yarn update-pjs && yarn update-pjs-recursive && yarn dedupe && yarn import-pjs-config", "update-pjs": "yarn up '@polkadot/*'", "update-pjs-recursive": "yarn up -R '@polkadot/*'", - "import-pjs-config": "node scripts/import-pjs-config.js" + "import-pjs-config": "node scripts/import-pjs-config.js", + "clean": "rm -r dist" }, "devDependencies": { "@polkadot/apps-config": "^0.132.1", diff --git a/scripts/publish.js b/scripts/publish.js new file mode 100644 index 0000000000..45ddde1dd1 --- /dev/null +++ b/scripts/publish.js @@ -0,0 +1,50 @@ +import fs from 'fs' + +// Can be used for nicer vscode syntax highlighting & auto formatting +// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals#raw_strings +const html = (strings, ...values) => String.raw({ raw: strings }, ...values) + +const chaindata = JSON.parse(fs.readFileSync('chaindata.json')) + +const filesList = [] + +fs.rmSync('dist', { recursive: true, force: true }) +fs.mkdirSync('dist') + +filesList.push('chaindata.json') +fs.writeFileSync('dist/chaindata.json', JSON.stringify(chaindata, null, 2)) + +fs.mkdirSync('dist/chains/byId', { recursive: true }) +for (const chain of chaindata) { + if (!Array.isArray(chain.rpcs) || chain.rpcs.length < 1) continue + + if (typeof chain.id !== 'string') continue + filesList.push(`chains/byId/${chain.id}.json`) + fs.writeFileSync( + `dist/chains/byId/${chain.id}.json`, + JSON.stringify(chain, null, 2) + ) +} + +fs.writeFileSync( + 'dist/index.html', + html` + + + + + +
+

Chaindata

+${filesList.map((file) => html`${file}`).join('\n')} +
+ + ` +)