Update README.md #4
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Update Documentation | |
on: | |
push: | |
branches: | |
- main | |
paths: | |
- 'README.md' | |
jobs: | |
update-docs: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout the py2d repository | |
uses: actions/checkout@v3 | |
- name: Set up Git | |
run: | | |
git config --global user.name 'GitHub Actions Bot' | |
git config --global user.email '[email protected]' | |
- name: Check if README was updated | |
run: | | |
if git diff --name-only HEAD^ HEAD | grep 'README.md'; then | |
echo "README.md has changed" | |
else | |
echo "README.md has not changed" && exit 0 | |
fi | |
- name: Generate random number for branch name | |
id: random | |
run: echo "::set-output name=random_number::$(shuf -i 1000-9999 -n 1)" | |
- name: Clone the CLSFramework.github.io repository | |
run: | | |
git clone https://github.com/CLSFramework/CLSFramework.github.io.git cls-repo | |
cd cls-repo | |
# Copy updated README to target directory in the CLSFramework.github.io repository | |
cp ../README.md docs/6-basecode/py2d/index.md | |
# Create a new branch with a random number appended | |
git checkout -b update-README-py2d-${{ steps.random.outputs.random_number }} | |
- name: Add front matter to index.md before committing | |
run: | | |
cd cls-repo | |
# Add the custom_edit_url to the index.md file | |
sed -i '1s/^/---\ncustom_edit_url: '\''https:\/\/github.com\/CLSFramework\/py2d\/blob\/main\/README.md'\''\n---\n\n/' docs/6-basecode/py2d/index.md | |
- name: Set up authentication using PAT for CLSFramework.github.io | |
run: | | |
cd cls-repo | |
git remote set-url origin https://x-access-token:${{ secrets.GH_TOKEN }}@github.com/CLSFramework/CLSFramework.github.io.git | |
- name: Commit and Push Changes to CLSFramework.github.io | |
run: | | |
cd cls-repo | |
git add docs/6-basecode/py2d/index.md | |
git commit -m "Update py2d documentation from README" | |
git push origin update-README-py2d-${{ steps.random.outputs.random_number }} | |
- name: Create Pull Request in CLSFramework.github.io using GitHub API | |
run: | | |
PR_RESPONSE=$(curl -X POST -H "Authorization: token ${{ secrets.GH_TOKEN }}" \ | |
-H "Accept: application/vnd.github.v3+json" \ | |
https://api.github.com/repos/CLSFramework/CLSFramework.github.io/pulls \ | |
-d '{"title":"Update py2d documentation","head":"update-README-py2d-${{ steps.random.outputs.random_number }}","base":"main","body":"This PR updates the py2d documentation based on changes made in README.md."}') | |
echo "Pull request created: $PR_RESPONSE" |