-
Notifications
You must be signed in to change notification settings - Fork 0
95 lines (85 loc) · 3.28 KB
/
Copy pathsync-docs.yaml
File metadata and controls
95 lines (85 loc) · 3.28 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
name: Sync Docs to Central Repo
on:
workflow_dispatch:
push:
branches:
- main
- staging
paths:
- 'squadcastv1/docs/**'
- 'squadcastv1/*.md'
jobs:
sync-docs:
runs-on: ubuntu-latest
env:
SDK_LANG: python
DOCS_PATH: squadcastv1/docs
CENTRAL_REPO: bhattu-gauravv/squadcast-sdk-docs
steps:
- name: Checkout SDK repo
uses: actions/checkout@v4
- name: Checkout central docs repo
uses: actions/checkout@v4
with:
repository: ${{ env.CENTRAL_REPO }}
token: ${{ secrets.DOCS_REPO_PAT }}
path: central-docs
fetch-depth: 0
- name: Create branch and sync docs
id: sync
run: |
# Target staging in central repo when triggered from staging, else main
if [[ "${{ github.ref_name }}" == "staging" ]]; then
BASE_BRANCH="staging"
else
BASE_BRANCH="main"
fi
BRANCH="docs-sync/${SDK_LANG}-${BASE_BRANCH}-${{ github.sha }}"
cd central-docs
git config user.name "speakeasy-docs-bot"
git config user.email "docs-bot@solarwinds.com"
# Ensure base branch exists in central repo; create from main if not
git fetch origin
if git ls-remote --exit-code --heads origin "$BASE_BRANCH" > /dev/null 2>&1; then
git checkout -b "$BASE_BRANCH" "origin/$BASE_BRANCH"
else
git checkout -b "$BASE_BRANCH"
git push origin "$BASE_BRANCH"
fi
git checkout -b "$BRANCH"
rm -rf "${SDK_LANG}/"
mkdir -p "${SDK_LANG}"
cp -r "../${DOCS_PATH}" "${SDK_LANG}/docs"
SDK_ROOT=$(dirname "../${DOCS_PATH}")
find "${SDK_ROOT}" -maxdepth 1 -name "*.md" -exec cp {} "${SDK_LANG}/" \;
git add .
if git diff --staged --quiet; then
echo "No doc changes to sync. Skipping."
echo "has_changes=false" >> "$GITHUB_OUTPUT"
exit 0
fi
git commit -m "docs(${SDK_LANG}): sync from squadcast-sdk-${SDK_LANG} @ ${{ github.sha }}"
git push --force origin "$BRANCH"
echo "has_changes=true" >> "$GITHUB_OUTPUT"
- name: Create Pull Request
if: steps.sync.outputs.has_changes == 'true'
run: |
if [[ "${{ github.ref_name }}" == "staging" ]]; then
BASE_BRANCH="staging"
else
BASE_BRANCH="main"
fi
BRANCH="docs-sync/${SDK_LANG}-${BASE_BRANCH}-${{ github.sha }}"
EXISTING_PR=$(gh pr list --repo "${CENTRAL_REPO}" --head "$BRANCH" --json number --jq '.[0].number' 2>/dev/null || echo "")
if [[ -n "$EXISTING_PR" ]]; then
echo "PR #${EXISTING_PR} already exists for branch $BRANCH, skipping creation."
else
gh pr create \
--repo "${CENTRAL_REPO}" \
--head "$BRANCH" \
--base "$BASE_BRANCH" \
--title "docs(${SDK_LANG}): sync from squadcast-sdk-${SDK_LANG}" \
--body "Automated docs sync triggered by commit [${{ github.sha }}](https://github.com/solarwinds/squadcast-sdk-${SDK_LANG}/commit/${{ github.sha }}) in \`squadcast-sdk-${SDK_LANG}\`."
fi
env:
GH_TOKEN: ${{ secrets.DOCS_REPO_PAT }}