Skip to content

Commit

Permalink
chore: git info and ci preview (#33)
Browse files Browse the repository at this point in the history
  • Loading branch information
hugomrdias authored Jul 26, 2023
1 parent 41a04b9 commit 0b4e492
Show file tree
Hide file tree
Showing 5 changed files with 189 additions and 15 deletions.
58 changes: 44 additions & 14 deletions .github/workflows/publish-demo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,11 @@ name: Publish Demo
env:
CI: true
FORCE_COLOR: 1
on:
push:
branches:
- master
paths:
- 'examples/demo/**'
- '.github/workflows/publish-demo.yml'
- 'pnpm-lock.yaml'
pull_request:
paths:
- 'packages/demo/**'
- '.github/workflows/publish-demo.yml'
- 'pnpm-lock.yaml'
on: [push]
jobs:
publish:
runs-on: ubuntu-latest
if: github.ref_name == 'master'
steps:
- uses: actions/checkout@v3
- uses: pnpm/[email protected]
Expand All @@ -29,7 +18,48 @@ jobs:
cache: 'pnpm'
- run: pnpm install
- run: pnpm -r --filter demo run build
- uses: fission-suite/[email protected]
- uses: fission-suite/publish-action@feat/cid-output
id: fission
with:
machine_key: ${{ secrets.FISSION_MACHINE_KEY }}
workdir: 'examples/demo'
- name: Add url to GITHUB_STEP_SUMMARY
run: |
echo "
### App URL 🌐
https://dweb.link/ipfs/${{ steps.fission.outputs.app_cid }}
" >> $GITHUB_STEP_SUMMARY
preview:
runs-on: ubuntu-latest
if: github.ref_name != 'master'
steps:
- uses: actions/checkout@v3
- uses: pnpm/[email protected]
with:
version: 8
- uses: actions/setup-node@v3
with:
node-version: 18
cache: 'pnpm'
- run: pnpm install
- run: pnpm -r --filter demo run build
env:
GITHUB_WORKFLOW_ID: ${{ github.run_id }}
- name: Add report to web3.storage
uses: web3-storage/add-to-web3@v2
id: add_to_web3_storage
with:
path_to_add: examples/demo/dist
web3_token: ${{ secrets.WEB3_TOKEN }}
- name: Add url to GITHUB_STEP_SUMMARY
run: |
echo "
### Preview URL 🌐
${{ steps.add_to_web3_storage.outputs.url }}
" >> $GITHUB_STEP_SUMMARY
- uses: mshick/add-pr-comment@v2
with:
message-id: 'preview-url'
message: |
### Preview URL 🌐
${{ steps.add_to_web3_storage.outputs.url }}
2 changes: 2 additions & 0 deletions examples/demo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
"@acab/reset.css": "^0.5.3",
"@preact/signals": "^1.1.5",
"clsx": "^2.0.0",
"dns-over-http-resolver": "^2.1.1",
"filsnap-adapter": "workspace:^",
"iso-base": "^1.1.1",
"iso-filecoin": "^2.0.1",
Expand All @@ -65,6 +66,7 @@
"@playwright/test": "^1.36.1",
"@preact/preset-vite": "^2.5.0",
"@types/node": "^20.4.4",
"tiny-git-rev-sync": "^0.1.0",
"vite": "^4.4.7"
},
"eslintConfig": {
Expand Down
73 changes: 73 additions & 0 deletions examples/demo/src/app.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,30 @@ import SignMessage from './components/sign-message.jsx'
import { useFilsnapContext } from './hooks/filsnap.js'
import ConnectFEVM from './components/connect-fevm.jsx'
import Forward from './components/forward.tsx'
import { useEffect, useState } from 'preact/hooks'
import Resolver from 'dns-over-http-resolver'

export function App() {
const { isConnected } = useFilsnapContext()
const [cid, setCid] = /** @type {typeof useState<string>} */ (useState)()
useEffect(() => {
async function main() {
try {
if (window.location.host.includes('ipfs.dweb.link')) {
const cid = window.location.host.split('.')[0]
setCid(cid)
return
}
const dnsRecord = await new Resolver().resolve(
`_dnslink.${window.location.host}`,
'TXT'
)
setCid(dnsRecord[0][0].replace('dnslink=/ipfs/', ''))
} catch {}
}

main()
}, [])

return (
<main class="App">
Expand Down Expand Up @@ -53,6 +74,58 @@ export function App() {
github.com/filecoin-project/filsnap
</a>
</li>
<li>
{' '}
CID:{' '}
<a
target="_blank"
href={`https://${cid}.ipfs.dweb.link/`}
rel="noreferrer"
>
{cid || 'unknown'}
</a>
</li>
<li>
{' '}
Release Job:{' '}
<a
target="_blank"
href={`https://github.com/filecoin-project/filsnap/actions/runs/${
import.meta.env.GITHUB_WORKFLOW_ID
}`}
rel="noreferrer"
>
{import.meta.env.GITHUB_WORKFLOW_ID || 'unknown'}
</a>
</li>
<li>
{' '}
Git:{' '}
<code>
{import.meta.env.GIT_BRANCH}{' '}
<a
title="Commit hash"
target="_blank"
href={`https://github.com/filecoin-project/filsnap/commit/${
import.meta.env.GIT_COMMIT_HASH
}`}
rel="noreferrer"
>
{import.meta.env.GIT_COMMIT_HASH.slice(0, 7)}
</a>{' '}
<a
title="Release tag"
target="_blank"
href={`https://github.com/filecoin-project/filsnap/releases/tag/${
import.meta.env.GIT_TAG
}`}
rel="noreferrer"
>
{import.meta.env.GIT_TAG}
</a>{' '}
{import.meta.env.GIT_DATE}
</code>
</li>
</ul>
</div>
</div>
Expand Down
13 changes: 13 additions & 0 deletions examples/demo/vite.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,19 @@
import { defineConfig } from 'vite'
import preact from '@preact/preset-vite'
import * as child from 'child_process'
import * as git from 'tiny-git-rev-sync'

const commitHash = child.execSync('git rev-parse HEAD').toString()

export default defineConfig({
define: {
'import.meta.env.GIT_COMMIT_HASH': JSON.stringify(commitHash),
'import.meta.env.GIT_BRANCH': JSON.stringify(git.gitBranch()),
'import.meta.env.GIT_DATE': JSON.stringify(git.gitDate()),
'import.meta.env.GIT_TAG': JSON.stringify(git.gitTag()),
'import.meta.env.GITHUB_WORKFLOW_ID': JSON.stringify(
process.env.GITHUB_WORKFLOW_ID
),
},
plugins: [preact()],
})
58 changes: 57 additions & 1 deletion pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 0b4e492

Please sign in to comment.