Skip to content

Commit

Permalink
feat: Publish static reports via github pages (#68)
Browse files Browse the repository at this point in the history
* Update build-and-publish-reports.yml

* Update build-and-publish-reports.yml

* Update build-and-publish-reports.yml

* Update build-and-publish-reports.yml

* Update build-and-publish-reports.yml

* Update build-and-publish-reports.yml

* Update build-and-publish-reports.yml

* Update build-and-publish-reports.yml

* Update build-and-publish-reports.yml

* Update build-and-publish-reports.yml

* attempt to use github cache

* Update build-and-publish-reports.yml

* Update build-and-publish-reports.yml

* Update build-and-publish-reports.yml

* fix: md->html conversion requires extra newline

* fix: render body as multiline json in reports

* chore: remove extraneous comments

* feat: add date and revision to report output

* chore: use more explicit github action job names

* fix: do not squash gh-pages history

* feat: Link to headers from summary, cleanup revision markdown

* fix: attempt to catch git-rev error

* fix: Remove hardcoded delay for pinata

* feat: gh-pages has informative commit messages

* chore: Reports with no changes from previous will create commit

* feat: add report history link

* Also handles failures when there is no git history now

* fix: Remove previous revision from header

* chore: rename and hide joi schema failures when empty

temporary solution until #78 is done

* fix: UX improvement for pass/fail/error icons

fixes #76

* fix: add json identifier to code in markdown

fixes #77

* fix: Error output uses icon and header

It will not show if there are no errors

* feat: fix json highlighting in reports

fixes #77

* style: change body order raw→json→parsed

This makes things easier to reason about:
In this order, each step has more strictness.

Co-authored-by: Marcin Rataj <[email protected]>
  • Loading branch information
SgtPooki and lidel authored Jun 14, 2022
1 parent ff48f3b commit 5a6a7f5
Show file tree
Hide file tree
Showing 21 changed files with 386 additions and 100 deletions.
166 changes: 128 additions & 38 deletions .github/workflows/build-and-publish-reports.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
name: Build and publish compliance reports
on:
workflow_dispatch:
inputs:
type:
description: 'Emulate either schedule, push, or pull_request'
required: true
default: 'schedule'
type: choice
options:
- schedule
- push
- pull_request
schedule:
- cron: "0 0 * * 6" # Run at 00:00 on every saturday
push:
Expand All @@ -10,57 +20,137 @@ on:
pull_request:
branches: [ main ]
jobs:
build-and-publish:
if: secrets.PINATA_API_ENDPOINT != null && secrets.PINATA_API_TOKEN != null && secrets.ESTUARY_API_ENDPOINT != null && secrets.ESTUARY_API_TOKEN != null && secrets.NFT_API_ENDPOINT != null && secrets.NFT_API_TOKEN != null && secrets.WEB3_API_ENDPOINT != null && secrets.PINATA_API_TOKEN != null
strategy:
fail-fast: false
matrix:
service: [pinata, estuary, nft, web3]
include:
- service: pinata
endpoint: ${{ secrets.PINATA_API_ENDPOINT }}
token: ${{secrets.PINATA_API_TOKEN}}
- service: estuary
endpoint: ${{ secrets.ESTUARY_API_ENDPOINT }}
token: ${{secrets.ESTUARY_API_TOKEN}}
- service: nft
endpoint: ${{ secrets.NFT_API_ENDPOINT }}
token: ${{secrets.NFT_API_TOKEN}}
- service: web3
endpoint: ${{ secrets.WEB3_API_ENDPOINT }}
token: ${{secrets.WEB3_API_TOKEN}}
checkout:
runs-on: ubuntu-latest
steps:
- name: Checkout 🛎️
uses: actions/checkout@v3
- uses: ipfs/aegir/actions/cache-node-modules@master

concurrency: ci-${{ github.ref }} # Recommended if you intend to make multiple deployments in quick succession.
check-pinata-compliance:
runs-on: ubuntu-latest
needs: [checkout]
steps:
- name: Checkout 🛎️
uses: actions/checkout@v3
- uses: ipfs/aegir/actions/cache-node-modules@master
- name: Reports Cache
uses: actions/cache@v3
with:
path: docs
key: ${{ github.sha }}-pinata
- run: npm run dev-start -- -s ${{ secrets.PINATA_API_ENDPOINT }} ${{secrets.PINATA_API_TOKEN}}
- uses: actions/upload-artifact@v2
with:
name: pinata-logs
path: docs/api.pinata.cloud
- uses: actions/upload-artifact@v2
with:
name: pinata-report
path: docs/api.pinata.cloud.md

- name: Install dependencies
run: npm ci
check-estuary-compliance:
runs-on: ubuntu-latest
needs: [checkout]
steps:
- name: Checkout 🛎️
uses: actions/checkout@v3
- uses: ipfs/aegir/actions/cache-node-modules@master
- name: Reports Cache
uses: actions/cache@v3
with:
path: docs
key: ${{ github.sha }}-estuary
- run: npm run dev-start -- -s ${{ secrets.ESTUARY_API_ENDPOINT }} ${{secrets.ESTUARY_API_TOKEN}}
- uses: actions/upload-artifact@v2
with:
name: estuary-logs
path: docs/api.estuary.tech
- uses: actions/upload-artifact@v2
with:
name: estuary-report
path: docs/api.estuary.tech.md

# Migrate reports to use npx
- name: Generate reports
run: npm dev-start -- -s ${{ secrets[matrix.endpoint] }} ${{ secrets[matrix.token] }}
check-nft-dot-storage-compliance:
runs-on: ubuntu-latest
needs: [checkout]
steps:
- name: Checkout 🛎️
uses: actions/checkout@v3
- uses: ipfs/aegir/actions/cache-node-modules@master
- name: Reports Cache
uses: actions/cache@v3
with:
path: docs
key: ${{ github.sha }}-nft
- run: npm run dev-start -- -s ${{ secrets.NFT_API_ENDPOINT }} ${{secrets.NFT_API_TOKEN}}
- uses: actions/upload-artifact@v2
with:
name: nft-logs
path: docs/nft.storage
- uses: actions/upload-artifact@v2
with:
name: nft-report
path: docs/nft.storage.md

# Deploy to gh pages branch
check-web3-dot-storage-compliance:
runs-on: ubuntu-latest
needs: [checkout]
steps:
- name: Checkout 🛎️
uses: actions/checkout@v3
- uses: ipfs/aegir/actions/cache-node-modules@master
- name: Reports Cache
uses: actions/cache@v3
with:
path: docs
key: ${{ github.sha }}-web3
- run: npm run dev-start -- -s ${{ secrets.WEB3_API_ENDPOINT }} ${{secrets.WEB3_API_TOKEN}}
- uses: actions/upload-artifact@v2
with:
name: web3-logs
path: docs/api.web3.storage
- uses: actions/upload-artifact@v2
with:
name: web3-report
path: docs/api.web3.storage.md

# Deploy to gh pages branch

## Cron jobs
## Cron jobs
deploy-from-schedule:
if: success() && (github.event.schedule != null || github.event.pusher != null || github.event.inputs.type == 'schedule' || github.event.inputs.type == 'push')
runs-on: ubuntu-latest
needs: [check-pinata-compliance, check-estuary-compliance, check-nft-dot-storage-compliance, check-web3-dot-storage-compliance]
concurrency: ci-${{ github.ref }} # Recommended if you intend to make multiple deployments in quick succession.
steps:
- name: Reports Cache
uses: actions/cache@v3
with:
path: docs
key: ${{ github.sha }}-pinata
- name: Reports Cache
uses: actions/cache@v3
with:
path: docs
key: ${{ github.sha }}-estuary
- name: Reports Cache
uses: actions/cache@v3
with:
path: docs
key: ${{ github.sha }}-nft
- name: Reports Cache
uses: actions/cache@v3
with:
path: docs
key: ${{ github.sha }}-web3
- name: Scheduled deployment
if: success() && (github.event.schedule != null || github.event.pusher != null)
uses: s0/git-publish-subdir-action@399aab378450f99b7de6767f62b0d1dbfcb58b53
env:
REPO: self
BRANCH: gh-pages
FOLDER: docs
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

## PRs should push to branch other than primary `gh-pages` branch
- name: Deployment for PR
if: success() && github.event.pull_request != null
uses: s0/git-publish-subdir-action@399aab378450f99b7de6767f62b0d1dbfcb58b53
env:
REPO: self
BRANCH: gh-pages-${github.sha}
FOLDER: docs
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SQUASH_HISTORY: false
MESSAGE: "Update published reports with changes from {sha} with message:\n{msg}"
SKIP_EMPTY_COMMITS: false
24 changes: 24 additions & 0 deletions package-lock.json

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

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@
"rebuild": "npm run clean && npm install && npm run build"
},
"devDependencies": {
"@types/git-rev": "^0.2.0",
"@types/hapi__joi": "^17.1.8",
"@types/marked": "^4.0.3",
"@types/marked-terminal": "^3.1.3",
Expand All @@ -146,6 +147,7 @@
"@hapi/joi": "^17.1.1",
"@ipfs-shipyard/pinning-service-client": "^1.0.1",
"fetch-ponyfill": "^7.1.0",
"git-rev": "^0.2.1",
"go-ipfs": "^0.12.1",
"ipfs": "^0.62.3",
"ipfs-core": "^0.14.3",
Expand Down
12 changes: 10 additions & 2 deletions src/ApiCall.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { Icons } from './utils/constants.js'
import { globalReport } from './utils/report.js'
import { isError } from './guards/isError.js'
import { getTextAndJson } from './utils/fetchSafe/getTextAndJson.js'
import { isResponse } from './guards/isResponse.js'

interface ApiCallOptions<T extends PinsApiResponseTypes, P extends PinsApiResponseTypes> {
pair: ServiceAndTokenPair
Expand Down Expand Up @@ -115,12 +116,19 @@ class ApiCall<T extends PinsApiResponseTypes, P extends PinsApiResponseTypes = n
// eslint-disable-next-line @typescript-eslint/return-await
return await fn(this.client)
} catch (err) {
const error = isError(err) ? err : new Error(err as string)
let error: Error
if (isResponse(err)) {
error = new Error('Invalid response caused unexpected error in pinning-service-client')
} else if (isError(err)) {
error = err
} else {
error = new Error(err as string)
}
this.errors.push({
title: 'Error running primary ApiCall fn',
error
})
throw err
throw error
}
}).then((result) => {
this.result = result
Expand Down
8 changes: 2 additions & 6 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,10 @@ const main = async () => {
}

const getUncaughtListener = (type: 'unhandledRejection' | 'uncaughtException' | 'uncaughtExceptionMonitor'): NodeJS.UncaughtExceptionListener => (err, origin) => {
logger.error(type, { error: err })
logger.error(type, err, origin)
writeSync(
process.stderr.fd,
`Caught exception: ${JSON.stringify(err, null, 2)}\n`
)
writeSync(
process.stdout.fd,
`Caught exception: ${JSON.stringify(err, null, 2)}\n`
`Caught exception: ${JSON.stringify({ err, origin }, null, 2)}\n`
)
}
process.on('uncaughtExceptionMonitor', getUncaughtListener('uncaughtExceptionMonitor'))
Expand Down
9 changes: 9 additions & 0 deletions src/output/complianceCheckHeader.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { Icons } from '../utils/constants.js'

interface ComplianceCheckHeaderProps {
title: string
successful: boolean
}
const complianceCheckHeader = ({ title, successful }: ComplianceCheckHeaderProps) => `${title} - ${successful ? `${Icons.SUCCESS} SUCCESS` : `${Icons.FAILURE} FAILED`}`

export { complianceCheckHeader }
19 changes: 19 additions & 0 deletions src/output/getErrorsMarkdown.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { inspect } from 'util'

import { Icons } from '../utils/constants.js'

const errorToMarkdown = (error: Error) => {
let errorOutput = ''
if (error.stack != null) {
errorOutput = `
${Icons.ERROR} ${error.stack}`
} else if (error.name != null && error.message != null) {
errorOutput = `${Icons.ERROR} ${error.name} - ${error.message}`
} else {
errorOutput = `${Icons.ERROR} ${inspect(error)}`
}
return errorOutput
}
const getErrorsMarkdown = (errors: Error[]) => errors.map(errorToMarkdown).join('\n')

export { getErrorsMarkdown }
7 changes: 4 additions & 3 deletions src/output/getExpectationsMarkdown.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { ComplianceCheckDetails, PinsApiResponseTypes } from '../types.js'
import { Icons } from '../utils/constants.js'

const getExpectationsMarkdown = <T extends PinsApiResponseTypes>(details: ComplianceCheckDetails<T>): string => {
let checks = 0
Expand All @@ -7,14 +8,14 @@ const getExpectationsMarkdown = <T extends PinsApiResponseTypes>(details: Compli
checks++
if (success) {
successes++
return ` ${title} (success)`
return `${Icons.SUCCESS} ${title} (success)`
}
return ` ${title} (failure)`
return `${Icons.FAILURE} ${title} (failure)`
})

return `### Expectations (${successes}/${checks} successful)
${lineItems.join('\n ')}
${lineItems.join('\n\n ')}
`
}

Expand Down
Loading

0 comments on commit 5a6a7f5

Please sign in to comment.