Skip to content

Commit 88d5eb7

Browse files
authored
Create main.yml
1 parent 3bd2666 commit 88d5eb7

File tree

1 file changed

+70
-0
lines changed

1 file changed

+70
-0
lines changed

.github/workflows/main.yml

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
name: Update Documentation
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
paths:
8+
- 'README.md'
9+
10+
jobs:
11+
update-docs:
12+
runs-on: ubuntu-latest
13+
14+
steps:
15+
- name: Checkout the sample-playmaker-server-python-thrift repository
16+
uses: actions/checkout@v3
17+
18+
- name: Set up Git
19+
run: |
20+
git config --global user.name 'GitHub Actions Bot'
21+
git config --global user.email '[email protected]'
22+
23+
- name: Check if README was updated
24+
run: |
25+
if git diff --name-only HEAD^ HEAD | grep 'README.md'; then
26+
echo "README.md has changed"
27+
else
28+
echo "README.md has not changed" && exit 0
29+
fi
30+
31+
- name: Generate random number for branch name
32+
id: random
33+
run: echo "::set-output name=random_number::$(shuf -i 1000-9999 -n 1)"
34+
35+
- name: Clone the CLSFramework.github.io repository
36+
run: |
37+
git clone https://github.com/CLSFramework/CLSFramework.github.io.git cls-repo
38+
cd cls-repo
39+
40+
# Copy updated README to target directory in the CLSFramework.github.io repository
41+
cp ../README.md docs/2-sampleserver/0-sample-python-base-code-thrift/index.md
42+
43+
# Create a new branch with a random number appended
44+
git checkout -b update-readme-thrift-${{ steps.random.outputs.random_number }}
45+
46+
- name: Add front matter to index.md before committing
47+
run: |
48+
cd cls-repo
49+
# Add the custom_edit_url to the index.md file
50+
sed -i '1s/^/---\ncustom_edit_url: '\''https:\/\/github.com\/CLSFramework\/sample-playmaker-server-python-thrift\/blob\/main\/README.md'\''\n---\n\n/' docs/2-sampleserver/0-sample-python-base-code-thrift/index.md
51+
52+
- name: Set up authentication using PAT for CLSFramework.github.io
53+
run: |
54+
cd cls-repo
55+
git remote set-url origin https://x-access-token:${{ secrets.GH_TOKEN }}@github.com/CLSFramework/CLSFramework.github.io.git
56+
57+
- name: Commit and Push Changes to CLSFramework.github.io
58+
run: |
59+
cd cls-repo
60+
git add docs/2-sampleserver/0-sample-python-base-code-thrift/index.md
61+
git commit -m "Update sample server documentation from README"
62+
git push origin update-readme-thrift-${{ steps.random.outputs.random_number }}
63+
64+
- name: Create Pull Request in CLSFramework.github.io using GitHub API
65+
run: |
66+
PR_RESPONSE=$(curl -X POST -H "Authorization: token ${{ secrets.GH_TOKEN }}" \
67+
-H "Accept: application/vnd.github.v3+json" \
68+
https://api.github.com/repos/CLSFramework/CLSFramework.github.io/pulls \
69+
-d '{"title":"Update sample server documentation","head":"update-readme-thrift-${{ steps.random.outputs.random_number }}","base":"main","body":"This PR updates the sample server documentation based on changes made in README.md."}')
70+
echo "Pull request created: $PR_RESPONSE"

0 commit comments

Comments
 (0)