Updated npm/clones shield counters in root README #416
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: Sync README.md between <pkg>/ and <pkg>/docs | |
on: | |
push: | |
branches: [main] | |
paths: ["**/README.md"] | |
jobs: | |
build: | |
if: (github.repository == 'adamlui/js-utils') && (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: auto-sync@kudoai.com | |
steps: | |
- name: Checkout adamlui/js-utils | |
uses: actions/checkout@v4 | |
with: | |
token: ${{ secrets.REPO_SYNC_PAT }} | |
repository: adamlui/js-utils | |
path: adamlui/js-utils | |
fetch-depth: 2 | |
- name: Sync README.md between <pkg>/ and <pkg>/docs | |
id: sync_readmes | |
run: | | |
cd ${{ github.workspace }}/adamlui/js-utils | |
# Init pkg paths | |
pkg_roots=($(find . -type d -name "docs" `# paths to docs/` \ | |
! -path "*/node_modules/*" `# exclude node_modules` \ | |
! -path "*/minify.js|scss-to-css/*" `# exclude multi-platform pkgs w/ own sync scripts` \ | |
-exec dirname {} \; | # get parent dir of found docs/ | |
grep -Ev "^\.$")) # exclude repo root | |
# Sync READMEs per pkg | |
for pkg_root in "${pkg_roots[@]}" ; do | |
# Init paths/content/mod timestamps | |
root_readme=$pkg_root"/README.md" | |
root_readme_content=$(git show HEAD:"$root_readme") | |
root_readme_modified=$(git log -1 --format="%ct" -- "$root_readme") | |
docs_readme=$pkg_root"/docs/README.md" | |
docs_readme_content=$(git show HEAD:"$docs_readme") | |
docs_readme_modified=$(git log -1 --format="%ct" -- "$docs_readme") | |
# Perform syncs of diff READMEs | |
if [[ "$root_readme_content" != "$docs_readme_content" ]] ; then | |
if [[ $root_readme_modified -gt $docs_readme_modified ]] ; then | |
cp -f "$root_readme" "$docs_readme" | |
echo "Copied $root_readme to $docs_readme" | |
src_folder="/${pkg_root#./}" | |
elif [[ $docs_readme_modified -gt $root_readme_modified ]] ; then | |
cp -f "$docs_readme" "$root_readme" | |
echo "Copied $docs_readme to $root_readme" | |
src_folder="/${pkg_root#./}/docs" | |
fi | |
fi | |
done | |
# Store sync src for commit msg in next step | |
echo "sync_src=$src_folder" >> $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 adamlui/js-utils | |
run: | | |
cd ${{ github.workspace }}/adamlui/js-utils | |
git add . | |
git commit -n -m "$ESCAPED_MSG ↞ [auto-sync from \`${{ steps.sync_readmes.outputs.sync_src }}\`]" || true | |
git push |