Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Publish static reports via github pages #68

Merged
merged 33 commits into from
Jun 14, 2022
Merged
Show file tree
Hide file tree
Changes from 31 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
91a37f7
Update build-and-publish-reports.yml
SgtPooki May 31, 2022
b6543ac
Update build-and-publish-reports.yml
SgtPooki Jun 1, 2022
34f16fd
Update build-and-publish-reports.yml
SgtPooki Jun 1, 2022
95182ee
Update build-and-publish-reports.yml
SgtPooki Jun 1, 2022
38e68f9
Update build-and-publish-reports.yml
SgtPooki Jun 1, 2022
369c29d
Update build-and-publish-reports.yml
SgtPooki Jun 1, 2022
07a9314
Update build-and-publish-reports.yml
SgtPooki Jun 1, 2022
3fbf1f7
Update build-and-publish-reports.yml
SgtPooki Jun 1, 2022
de1c3d7
Update build-and-publish-reports.yml
SgtPooki Jun 1, 2022
59750e5
Update build-and-publish-reports.yml
SgtPooki Jun 1, 2022
6bb0d70
attempt to use github cache
SgtPooki Jun 1, 2022
081e0a3
Update build-and-publish-reports.yml
SgtPooki Jun 1, 2022
2bd87c4
Update build-and-publish-reports.yml
SgtPooki Jun 1, 2022
acbccbe
Update build-and-publish-reports.yml
SgtPooki Jun 1, 2022
d08a8f3
fix: md->html conversion requires extra newline
SgtPooki Jun 1, 2022
715e404
fix: render body as multiline json in reports
SgtPooki Jun 1, 2022
2b4ce75
chore: remove extraneous comments
SgtPooki Jun 6, 2022
b81ffb2
feat: add date and revision to report output
SgtPooki Jun 6, 2022
7bf0131
chore: use more explicit github action job names
SgtPooki Jun 6, 2022
e62c17d
fix: do not squash gh-pages history
SgtPooki Jun 6, 2022
acd9fbc
feat: Link to headers from summary, cleanup revision markdown
SgtPooki Jun 7, 2022
e0780c6
fix: attempt to catch git-rev error
SgtPooki Jun 7, 2022
6fd6b98
fix: Remove hardcoded delay for pinata
SgtPooki Jun 7, 2022
1196d41
feat: gh-pages has informative commit messages
SgtPooki Jun 7, 2022
16a5774
chore: Reports with no changes from previous will create commit
SgtPooki Jun 7, 2022
eda2a20
feat: add report history link
SgtPooki Jun 7, 2022
2d1ce30
fix: Remove previous revision from header
SgtPooki Jun 7, 2022
9dfaf6c
chore: rename and hide joi schema failures when empty
SgtPooki Jun 7, 2022
6e74e3b
fix: UX improvement for pass/fail/error icons
SgtPooki Jun 8, 2022
0782e44
fix: add json identifier to code in markdown
SgtPooki Jun 8, 2022
933fbc6
fix: Error output uses icon and header
SgtPooki Jun 8, 2022
0251812
feat: fix json highlighting in reports
SgtPooki Jun 13, 2022
a5f8eff
style: change body order raw→json→parsed
lidel Jun 14, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
lidel marked this conversation as resolved.
Show resolved Hide resolved
- 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