Skip to content

Commit 2c2d4f3

Browse files
authored
Merge pull request #764 from callstack-internal/feat/check-if-api-docs-are-updated
feat: Validate API docs
2 parents 1370696 + c210fb2 commit 2c2d4f3

2 files changed

Lines changed: 53 additions & 0 deletions

File tree

.github/scripts/verifyDocs.sh

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/bin/bash
2+
#
3+
# Re-generates API docs and verifies that there is no diff,
4+
# because that would indicate that the PR author forgot to run `npm run build:docs`
5+
# and commit the updated API.md and API-INTERNAL.md files.
6+
7+
declare -r GREEN='\033[0;32m'
8+
declare -r RED='\033[0;31m'
9+
declare -r NC='\033[0m'
10+
11+
printf '\nRebuilding API docs...\n'
12+
if ! npm run build:docs; then
13+
echo -e "${RED}Error: \`npm run build:docs\` failed. Please fix the build errors before continuing.${NC}"
14+
exit 1
15+
fi
16+
17+
DIFF_OUTPUT=$(git diff --exit-code API.md API-INTERNAL.md)
18+
EXIT_CODE=$?
19+
20+
if [[ EXIT_CODE -eq 0 ]]; then
21+
echo -e "${GREEN}API docs are up to date!${NC}"
22+
exit 0
23+
else
24+
echo -e "${RED}Error: Diff found when API docs were rebuilt. Did you forget to run \`npm run build:docs\` after making changes?${NC}"
25+
echo "$DIFF_OUTPUT"
26+
exit 1
27+
fi

.github/workflows/validateDocs.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: Validate API Docs
2+
3+
on:
4+
pull_request:
5+
types: [opened, synchronize]
6+
paths: ['lib/**', 'buildDocs.ts', 'API.md', 'API-INTERNAL.md', '.github/workflows/validateDocs.yml', '.github/scripts/verifyDocs.sh']
7+
8+
jobs:
9+
verify:
10+
runs-on: ubuntu-latest
11+
steps:
12+
# v5.0.0
13+
- uses: actions/checkout@ff7abcd0c3c05ccf6adc123a8cd1fd4fb30fb493
14+
15+
- name: Setup Node
16+
# v4.4.0
17+
uses: actions/setup-node@cdca7365b2dadb8aad0a33bc7601856ffabcc48e
18+
with:
19+
node-version-file: ".nvmrc"
20+
cache: npm
21+
cache-dependency-path: package-lock.json
22+
23+
- run: npm ci
24+
25+
- name: Verify API Docs Are Up To Date
26+
run: ./.github/scripts/verifyDocs.sh

0 commit comments

Comments
 (0)