Skip to content

Commit

Permalink
chore(docs): compare PRs against next branch instead of current (#4904)
Browse files Browse the repository at this point in the history
* chore(docs): compare PRs against next branch instead of current

- fixes token mismatch when deleting dataset
- better message when no changes to documentation

* chore(docs): add next branch to the allow list
  • Loading branch information
binoy14 authored Sep 7, 2023
1 parent b99e332 commit c27ee3e
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 51 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/docReport.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ on:
pull_request:
# Build on commits pushed to branches without a PR if it's in the allowlist
push:
branches: [current]
branches: [current, next]

jobs:
report:
Expand Down Expand Up @@ -40,11 +40,11 @@ jobs:
env:
NODE_OPTIONS: --max_old_space_size=8192

- name: Create Docs Report on current
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/current' }}
- name: Create Docs Report on current or next
if: ${{ github.event_name == 'push' && (github.ref == 'refs/heads/current' || github.ref == 'refs/heads/next') }}
env:
DOCS_REPORT_TOKEN: ${{ secrets.DOCS_REPORT_DATASET_TOKEN }}
DOCS_REPORT_DATASET: production
DOCS_REPORT_DATASET: ${{ github.ref == 'refs/heads/current' && 'production' || 'next'}}
run: yarn docs:report:create

- name: Create Docs Report on PR
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/docReportTeardown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,6 @@ jobs:

- name: Remove datasets for closed PRs
env:
DOCS_REPORT_TOKEN: ${{ secrets.PERF_TEST_SANITY_TOKEN }}
DOCS_REPORT_TOKEN: ${{ secrets.DOCS_REPORT_DATASET_TOKEN }}
DOCS_REPORT_DATASET: ${{ github.ref_name }}
run: yarn docs:report:cleanup
98 changes: 53 additions & 45 deletions scripts/doc-report/docReport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ interface TransformResult {
}

const studioMetricsClient = createDocClient(readEnv('DOCS_REPORT_DATASET'))
const studioMetricsClientProduction = createDocClient('production')
const studioMetricsClientProduction = createDocClient('next')

function getDocumentationReport(symbols: ExportSymbol[]): Report[] {
const obj = groupBy(symbols, 'package')
Expand Down Expand Up @@ -92,52 +92,60 @@ combineLatest([
}),
)
.subscribe(async (res) => {
// convert the result to a markdown table with heading
const table = `
| Package | Documentation Change |
| ------- | ----------------- |
${res
.sort((a, b) => b.documentedChange - a.documentedChange)
.filter((r) => r.documentedChange !== 0)
.map(
(r) =>
`| ${r.package} | ${
r.documentedChange > 0 ? `+${r.documentedChange}` : r.documentedChange
}% |`,
)
.join('\n')}
<details>
<summary>Full Report</summary>
${res
.sort((a, b) => b.documentedChange - a.documentedChange)
.map(
(r) =>
`<details>
<summary>${r.package}</summary>
<table>
<tr>
<th>This branch</th>
<th>Current release</th>
</tr>
<tr>
<td>${r.branchDocumented} documented</td>
<td>${r.prodDocumented} documented</td>
</tr>
<tr>
<td>${r.branchNotDocumented} not documented</td>
<td>${r.prodNotDocumented} not documented</td>
</tr>
</table>
</details>
`,
)
.join('\n')}
</details>
`
const result = res.filter((r) => r.documentedChange !== 0)

let report = ''

if (result.length === 0) {
report = 'No changes to documentation'
} else {
// convert the result to a markdown table with heading
report = `
| Package | Documentation Change |
| ------- | ----------------- |
${res
.sort((a, b) => b.documentedChange - a.documentedChange)
.filter((r) => r.documentedChange !== 0)
.map(
(r) =>
`| ${r.package} | ${
r.documentedChange > 0 ? `+${r.documentedChange}` : r.documentedChange
}% |`,
)
.join('\n')}
<details>
<summary>Full Report</summary>
${res
.sort((a, b) => b.documentedChange - a.documentedChange)
.map(
(r) =>
`<details>
<summary>${r.package}</summary>
<table>
<tr>
<th>This branch</th>
<th>Next branch</th>
</tr>
<tr>
<td>${r.branchDocumented} documented</td>
<td>${r.prodDocumented} documented</td>
</tr>
<tr>
<td>${r.branchNotDocumented} not documented</td>
<td>${r.prodNotDocumented} not documented</td>
</tr>
</table>
</details>
`,
)
.join('\n')}
</details>
`
}

// save it to a file
await fs.writeFile(path.resolve(path.join(__dirname, '..', 'docs-report.md')), table, 'utf8')
await fs.writeFile(path.resolve(path.join(__dirname, '..', 'docs-report.md')), report, 'utf8')

timer.end()
})
2 changes: 1 addition & 1 deletion scripts/doc-report/docReportCleanup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ studioMetricsClient.datasets
}
})
.catch((err) => {
console.error(`Something went wrong! ${err?.response?.body?.message}`)
throw new Error(`Something went wrong! ${err?.response?.body?.message}`)
})

2 comments on commit c27ee3e

@vercel
Copy link

@vercel vercel bot commented on c27ee3e Sep 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

performance-studio – ./

performance-studio-git-next.sanity.build
performance-studio.sanity.build

@vercel
Copy link

@vercel vercel bot commented on c27ee3e Sep 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

test-studio – ./

test-studio-git-next.sanity.build
test-studio.sanity.build

Please sign in to comment.