Sync from Monorepo #1
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 from Monorepo | |
on: | |
repository_dispatch: | |
types: [portal-frontend-update] | |
workflow_dispatch: | |
inputs: | |
source_sha: | |
description: 'Source commit SHA (optional)' | |
required: false | |
source_ref: | |
description: 'Source ref (optional)' | |
required: false | |
jobs: | |
sync: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Setup Git | |
run: | | |
git config --global user.name 'github-actions[bot]' | |
git config --global user.email 'github-actions[bot]@users.noreply.github.com' | |
# Determine source ref | |
- name: Set source ref | |
id: set-ref | |
run: | | |
SOURCE_SHA="${{ github.event.client_payload.source_sha || github.event.inputs.source_sha }}" | |
if [ -z "$SOURCE_SHA" ]; then | |
echo "ref=develop" >> $GITHUB_OUTPUT | |
echo "source_desc=develop branch" >> $GITHUB_OUTPUT | |
else | |
echo "ref=$SOURCE_SHA" >> $GITHUB_OUTPUT | |
echo "source_desc=commit $SOURCE_SHA" >> $GITHUB_OUTPUT | |
fi | |
- name: Clone and prepare monorepo | |
run: | | |
# Full clone to preserve history | |
git clone https://x-access-token:${{ secrets.PAT_TOKEN }}@github.com/lumeweb/web source | |
cd source | |
# Checkout desired ref | |
git checkout ${{ steps.set-ref.outputs.ref }} | |
# Extract portal-frontend history to a branch | |
git subtree split -P apps/portal-frontend -b portal-frontend-split | |
# Create a temporary remote | |
cd .. | |
git remote add monorepo ./source | |
git fetch monorepo portal-frontend-split | |
- name: Sync changes | |
id: sync | |
run: | | |
# Always work on the sync branch | |
git checkout sync/portal-frontend 2>/dev/null || git checkout -b sync/portal-frontend | |
# Try to merge the subtree while preserving history | |
if git merge --no-commit --allow-unrelated-histories monorepo/portal-frontend-split; then | |
# Check if there are actual changes | |
if git status --porcelain | grep .; then | |
echo "changes_detected=true" >> $GITHUB_OUTPUT | |
# Complete the merge | |
git add . | |
git commit -m "sync: Update from monorepo ${{ steps.set-ref.outputs.source_desc }}" | |
else | |
git merge --abort | |
echo "changes_detected=false" >> $GITHUB_OUTPUT | |
fi | |
else | |
git merge --abort | |
echo "changes_detected=false" >> $GITHUB_OUTPUT | |
fi | |
- name: Push changes and update PR | |
if: steps.sync.outputs.changes_detected == 'true' | |
run: | | |
git push -f origin sync/portal-frontend | |
- name: Create or Update Pull Request | |
if: steps.sync.outputs.changes_detected == 'true' | |
uses: peter-evans/create-pull-request@v5 | |
with: | |
title: "chore: sync portal-frontend from upstream" | |
body: | | |
Automated sync from monorepo ${{ steps.set-ref.outputs.source_desc }} | |
This PR includes all related commit history from the portal-frontend directory. | |
This is an automatically updating PR that keeps the portal-frontend in sync with upstream. | |
branch: "sync/portal-frontend" | |
delete-branch: false | |
base: main | |
labels: | | |
sync | |
automated |