sync-embedded #510
This file contains hidden or 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 embedded sub-projects | |
| on: | |
| repository_dispatch: | |
| types: [sync-embedded] | |
| # Serialize sync runs so concurrent dispatches don't fight over `git push`. | |
| # Without this, two dispatches checked out at the same SHA and one push wins | |
| # while the other gets a non-fast-forward rejection. | |
| concurrency: | |
| group: sync-embedded | |
| cancel-in-progress: false | |
| permissions: | |
| contents: write | |
| jobs: | |
| sync: | |
| runs-on: ubuntu-latest | |
| env: | |
| SOURCE_REPO: ${{ github.event.client_payload.source_repo }} | |
| steps: | |
| - name: Checkout main site | |
| uses: actions/checkout@v4 | |
| with: | |
| token: ${{ secrets.SYNC_PAT }} | |
| - name: Resolve embedded folder name | |
| id: resolve | |
| run: | | |
| # Map repo names to embedded folder names where they differ | |
| case "$SOURCE_REPO" in | |
| reflections-grid) FOLDER="reflections" ;; | |
| *) FOLDER="$SOURCE_REPO" ;; | |
| esac | |
| echo "folder=$FOLDER" >> $GITHUB_OUTPUT | |
| - name: Clone source repo and sync | |
| run: | | |
| FOLDER="${{ steps.resolve.outputs.folder }}" | |
| # Clone the source repo (shallow, just the latest) | |
| git clone --depth 1 "https://github.com/actionresearchprojects/${SOURCE_REPO}.git" /tmp/source | |
| # Remove build/config files that shouldn't be in embedded | |
| cd /tmp/source | |
| rm -rf .git .github .gitignore __pycache__ \ | |
| *.py *.md data/ .aider* .claude .DS_Store | |
| cd - | |
| # Clear the existing embedded folder and copy fresh output | |
| rm -rf "embedded/${FOLDER}" | |
| mkdir -p "embedded/${FOLDER}" | |
| cp -r /tmp/source/* "embedded/${FOLDER}/" 2>/dev/null || true | |
| cp -r /tmp/source/.* "embedded/${FOLDER}/" 2>/dev/null || true | |
| - name: Commit and push if changed | |
| run: | | |
| FOLDER="${{ steps.resolve.outputs.folder }}" | |
| git config user.name "actionresearchprojects" | |
| git config user.email "actionresearchprojects@users.noreply.github.com" | |
| git add "embedded/${FOLDER}/" | |
| if git diff --cached --quiet; then | |
| echo "No changes to sync" | |
| exit 0 | |
| fi | |
| git commit -m "sync embedded/${FOLDER} from ${SOURCE_REPO}" | |
| # Retry push up to 5 times — concurrency:group serialises sync runs, | |
| # but other workflows (e.g. linkedin-post) can also commit to main. | |
| for i in 1 2 3 4 5; do | |
| if git push; then | |
| echo "Push succeeded on attempt $i" | |
| exit 0 | |
| fi | |
| echo "Push attempt $i failed; rebasing onto remote and retrying" | |
| git pull --rebase origin main | |
| done | |
| echo "Push failed after 5 attempts" | |
| exit 1 |