Skip to content

Commit e438743

Browse files
authored
feat(ci-cd): add sync-docs action (#171)
to automatically raise pull request on arc-docs for any documentation updates GH-170
1 parent d2e0c5e commit e438743

File tree

1 file changed

+97
-0
lines changed

1 file changed

+97
-0
lines changed

.github/workflows/sync-docs.yaml

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
name: Sync Docs to arc-docs repo
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
8+
env:
9+
DOCS_REPO: sourcefuse/arc-docs
10+
BRANCH_PREFIX: automated-docs-sync/
11+
GITHUB_TOKEN: ${{secrets.ARC_DOCS_API_TOKEN_GITHUB}}
12+
CONFIG_USERNAME: ${{ vars.GIT_COMMIT_USERNAME }}
13+
CONFIG_EMAIL: ${{ vars.GIT_COMMIT_EMAIL }}
14+
15+
jobs:
16+
sync-docs:
17+
runs-on: ubuntu-latest
18+
19+
steps:
20+
- name: Checkout Extension Code
21+
uses: actions/checkout@v3
22+
with:
23+
token: ${{env.GITHUB_TOKEN}}
24+
path: './extension/'
25+
26+
- name: Checkout Docs Repository
27+
uses: actions/checkout@v3
28+
with:
29+
token: ${{env.GITHUB_TOKEN}}
30+
repository: ${{env.DOCS_REPO}}
31+
path: './arc-docs/'
32+
33+
- name: Configure GIT
34+
id: configure_git
35+
working-directory: arc-docs
36+
run: |
37+
git config --global user.email $CONFIG_EMAIL
38+
git config --global user.name $CONFIG_USERNAME
39+
40+
extension_branch="${{env.BRANCH_PREFIX}}$(basename $GITHUB_REPOSITORY)"
41+
echo "extension_branch=$extension_branch" >> $GITHUB_OUTPUT
42+
43+
- name: Update Files
44+
id: update_files
45+
working-directory: arc-docs
46+
run: |
47+
extension_branch="${{ steps.configure_git.outputs.extension_branch }}"
48+
49+
# Create a new branch if it doesn't exist, or switch to it if it does
50+
git checkout -B $extension_branch || git checkout $extension_branch
51+
52+
# Copy README from the extension repo
53+
cp ../extension/README.md docs/arc-api-docs/extensions/$(basename $GITHUB_REPOSITORY)/
54+
git add .
55+
56+
if git diff --quiet --cached; then
57+
have_changes="false";
58+
else
59+
have_changes="true";
60+
fi
61+
62+
echo "Have Changes to be commited: $have_changes"
63+
echo "have_changes=$have_changes" >> $GITHUB_OUTPUT
64+
65+
- name: Commit Changes
66+
id: commit
67+
working-directory: arc-docs
68+
if: steps.update_files.outputs.have_changes == 'true'
69+
run: |
70+
git commit -m "sync $(basename $GITHUB_REPOSITORY) docs"
71+
- name: Push Changes
72+
id: push_branch
73+
if: steps.update_files.outputs.have_changes == 'true'
74+
working-directory: arc-docs
75+
run: |
76+
extension_branch="${{ steps.configure_git.outputs.extension_branch }}"
77+
git push https://oauth2:${GITHUB_TOKEN}@github.com/${{env.DOCS_REPO}}.git HEAD:$extension_branch --force
78+
79+
- name: Check PR Status
80+
id: pr_status
81+
if: steps.update_files.outputs.have_changes == 'true'
82+
working-directory: arc-docs
83+
run: |
84+
extension_branch="${{ steps.configure_git.outputs.extension_branch }}"
85+
gh pr status --json headRefName >> "${{github.workspace}}/pr-status.json"
86+
pr_exists="$(jq --arg extension_branch "$extension_branch" '.createdBy[].headRefName == $extension_branch' "${{github.workspace}}/pr-status.json")"
87+
echo "PR Exists: $pr_exists"
88+
echo "pr_exists=$pr_exists" >> $GITHUB_OUTPUT
89+
90+
- name: Create Pull Request
91+
id: create_pull_request
92+
if: steps.pr_status.outputs.pr_exists != 'true' && steps.update_files.outputs.have_changes == 'true'
93+
working-directory: arc-docs
94+
run: |
95+
extension_branch="${{ steps.configure_git.outputs.extension_branch }}"
96+
97+
gh pr create --head $(git branch --show-current) --title "Sync ${{ github.event.repository.name }} Docs" --body "This Pull Request has been created by the 'sync-docs' action within the '${{ github.event.repository.name }}' repository, with the purpose of updating markdown files."

0 commit comments

Comments
 (0)