Skip to content

Commit

Permalink
wip: github publish ci
Browse files Browse the repository at this point in the history
  • Loading branch information
alecdwm committed Sep 22, 2023
1 parent da44ce9 commit ea4f1f6
Show file tree
Hide file tree
Showing 5 changed files with 109 additions and 2 deletions.
54 changes: 54 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Talisman Chaindata CI
name: Chaindata Validate

on:
push:
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,5 @@ yarn-debug.log*
yarn-error.log*
.pnpm-debug.log*
yarn-error.log*

dist
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
50 changes: 50 additions & 0 deletions scripts/publish.js
Original file line number Diff line number Diff line change
@@ -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`<html>
<head>
<meta name="color-scheme" content="light dark" />
<style>
html {
font-family: sans-serif;
}
a {
text-decoration: none;
}
</style>
</head>
<body>
<pre style="word-wrap: break-word; white-space: pre-wrap;">
<h3>Chaindata</h3>
${filesList.map((file) => html`<a href="${file}">${file}</a>`).join('\n')}
</pre>
</body>
</html>`
)

0 comments on commit ea4f1f6

Please sign in to comment.