forked from kubestellar/kubestellar
-
Notifications
You must be signed in to change notification settings - Fork 0
66 lines (62 loc) · 2.83 KB
/
check-docs-pr-preview.yml
File metadata and controls
66 lines (62 loc) · 2.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# This workflow checks that PRs modifying website docs include a preview link in the PR description.
# It enforces KubeStellar's documentation PR best practices.
name: Check Docs PR Preview Link
on:
pull_request:
types: [opened, edited, synchronize]
paths:
- 'docs/content/**'
- 'docs/README.md'
- 'docs/mkdocs.yml'
- 'docs/overrides/**'
- 'docs/scripts/**'
- 'docs/requirements.txt'
- 'docs/main.py'
- 'SECURITY.md'
- 'CODE_OF_CONDUCT.md'
- 'GOVERNANCE.md'
- 'ONBOARDING.md'
jobs:
check-preview-link:
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8
- name: Check for Preview Link in PR Description (bash)
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PR_NUMBER: ${{ github.event.pull_request.number }}
REPO: ${{ github.repository }}
BRANCH: ${{ github.head_ref }}
run: |
set -e
BODY=$(gh pr view "$PR_NUMBER" --json body -q '.body')
DOC_BRANCH_REGEX='^doc-'
OWNER=$(gh pr view "$PR_NUMBER" --json headRepositoryOwner -q '.headRepositoryOwner.login')
REPO_NAME=$(gh pr view "$PR_NUMBER" --json headRepository -q '.headRepository.name')
GITHUB_PAGES_URL="https://${OWNER}.github.io/${REPO_NAME}/${BRANCH}"
GREEN=$'\033[0;32m'
RED=$'\033[0;31m'
YELLOW=$'\033[1;33m'
NC=$'\033[0m' # No Color
if ! PREVIEW_LINE=$(echo "$BODY" | grep -iE '^\s*Preview.*https?://') ; then
echo "${RED}[ERROR] Docs PR: No preview link found. Please include a line starting with 'Preview' and a valid GitHub Pages URL for your changes.${NC}"
echo "👉 For instructions on how to create a preview, see:"
echo " https://docs.kubestellar.io/unreleased-development/contribution-guidelines/operations/document-management/#rendering-and-previewing-modifications-to-the-website"
echo
exit 1
else
if [[ "$PREVIEW_LINE" == *"$GITHUB_PAGES_URL"* ]]; then
if [[ "$BRANCH" =~ $DOC_BRANCH_REGEX ]]; then
echo "${GREEN}[OK] Docs PR: doc- branch and preview link format matches expected GitHub Pages URL.${NC}"
else
echo "${YELLOW}[WARN] Docs PR: Preview link format is good, but branch does not start with doc-. Consider renaming to enable automatic previews.${NC}"
fi
else
echo "${YELLOW}[WARN] Docs PR: Preview link found, but it does not match the expected GitHub Pages URL."
PREVIEW_URL=$(echo "$PREVIEW_LINE" | grep -oE 'https?://[^ ]*' || true)
echo "Expected: ${GITHUB_PAGES_URL}"
echo "Found: ${PREVIEW_URL}${NC}"
fi
fi
echo