Skip to content

Updated git clones shield counters in READMEs #119

Updated git clones shield counters in READMEs

Updated git clones shield counters in READMEs #119

name: Sync changes between English readmes in root + docs/
on:
push:
branches: [main]
paths:
- README.md
- docs/README.md
jobs:
build:
if: (github.repository == 'KudoAI/chatgpt.js') && (github.event.commits[0].committer.username != 'kudo-sync-bot')
runs-on: ubuntu-latest
env:
GIT_AUTHOR_NAME: ${{ github.event.commits[0].author.name }}
GIT_AUTHOR_EMAIL: ${{ github.event.commits[0].author.email }}
GIT_COMMITTER_NAME: kudo-sync-bot
GIT_COMMITTER_EMAIL: [email protected]
steps:
- name: Checkout KudoAI/chatgpt.js
uses: actions/checkout@v4
with:
token: ${{ secrets.REPO_SYNC_PAT }}
repository: KudoAI/chatgpt.js
path: KudoAI/chatgpt.js
fetch-depth: 2
- name: Sync README.md between root & docs/
id: sync_readmes
run: |
cd "${{ github.workspace }}/KudoAI/chatgpt.js"
root_readme_modified=$(git log -1 --format="%ct" -- "README.md")
docs_readme_modified=$(git log -1 --format="%ct" -- "docs/README.md")
if [ "$root_readme_modified" -gt "$docs_readme_modified" ] ; then cp -f "README.md" "docs/README.md" ; sync_src="root"
elif [ "$docs_readme_modified" -gt "$root_readme_modified" ] ; then cp -f "docs/README.md" "README.md" ; sync_src="docs" ; fi
# Store sync src for commit msg in next step
echo "sync_src=$sync_src" >> $GITHUB_OUTPUT
- name: Escape backticks in commit msg
env:
COMMIT_MSG: ${{ github.event.head_commit.message }}
run: |
echo "ESCAPED_MSG<<EOF" >> $GITHUB_ENV
echo "$COMMIT_MSG" | sed 's/`/\`/g' >> $GITHUB_ENV
echo "EOF" >> $GITHUB_ENV
- name: Push changes to KudoAI/chatgpt.js
run: |
cd ${{ github.workspace }}/KudoAI/chatgpt.js
git add .
git commit -n -m "$ESCAPED_MSG ↞ [auto-sync from \`${{ steps.sync_readmes.outputs.sync_src }}\`]" || true
git push