Skip to content

Sync from Public Repo #85

Sync from Public Repo

Sync from Public Repo #85

name: Sync from Public Repo
on:
schedule:
- cron: '0 */6 * * *' # Every 6 hours
workflow_dispatch: # Manual trigger via Actions tab
permissions:
contents: write
pull-requests: write
jobs:
sync:
runs-on: ubuntu-latest
steps:
- name: Generate GitHub App Token
id: app-token
uses: actions/create-github-app-token@v1
with:
app-id: ${{ vars.APP_ID }}
private-key: ${{ secrets.APP_PRIVATE_KEY }}
- uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ steps.app-token.outputs.token }}
- name: Configure Git
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
- name: Fetch public main
run: |
git remote add public https://github.com/aws/agentcore-cli.git
git fetch public main
- name: Sync main with public/main
run: |
git checkout -B main origin/main
# Check if public/main is already merged
if git merge-base --is-ancestor public/main HEAD; then
echo "✅ main is already up to date with public/main"
exit 0
fi
# Merge but exclude .github/workflows/ (GITHUB_TOKEN lacks workflow permission)
if git merge public/main --no-commit --no-ff; then
git checkout HEAD -- .github/workflows/ 2>/dev/null || true
git commit -m "chore: sync main with public/main"
git push origin main
echo "✅ main synced successfully"
else
echo "⚠️ Conflict detected in main"
# Capture conflicted files before aborting
conflicted_files=$(git diff --name-only --diff-filter=U 2>/dev/null || echo "Unable to determine conflicted files")
git merge --abort
# Check if a sync PR already exists
existing_pr=$(gh pr list --base "main" --search "Merge public/main" --state open --json number --jq '.[0].number' 2>/dev/null || echo "")
if [ -n "$existing_pr" ]; then
echo "ℹ️ PR #$existing_pr already exists, skipping"
exit 0
fi
conflict_branch="sync-conflict-main-$(date +%Y%m%d-%H%M%S)"
git checkout -b "$conflict_branch"
git merge public/main --no-commit --no-ff || true
git checkout HEAD -- .github/workflows/ 2>/dev/null || true
git add -A
git commit -m "chore: sync main with public/main (conflicts present)
This automated sync detected merge conflicts that require manual resolution.
Source: public/main (https://github.com/aws/agentcore-cli)
Target: main
Please resolve conflicts and merge this PR." || true
git push origin "$conflict_branch"
gh pr create \
--title "🔀 [Sync Conflict] Merge public/main → main" \
--body "## Automated Sync Conflict
This PR was automatically created because merging \`public/main\` into \`main\` encountered conflicts.
**Source:** \`main\` from [aws/agentcore-cli](https://github.com/aws/agentcore-cli)
**Target:** \`main\`
### Action Required
1. \`git fetch origin && git checkout $conflict_branch\`
2. Resolve merge conflicts
3. \`git add . && git commit\`
4. \`git push origin $conflict_branch\`
5. Merge this PR
### Files with Conflicts
\`\`\`
$conflicted_files
\`\`\`" \
--base "main" \
--head "$conflict_branch" || echo "⚠️ Failed to create PR"
fi
env:
GH_TOKEN: ${{ steps.app-token.outputs.token }}
sync-preview:
runs-on: ubuntu-latest
steps:
- name: Generate GitHub App Token
id: app-token
uses: actions/create-github-app-token@v1
with:
app-id: ${{ vars.APP_ID }}
private-key: ${{ secrets.APP_PRIVATE_KEY }}
- uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ steps.app-token.outputs.token }}
- name: Configure Git
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
- name: Fetch public preview
run: |
git remote add public https://github.com/aws/agentcore-cli.git
git fetch public preview
- name: Sync preview with public/preview
run: |
git checkout -B preview origin/preview
# Check if public/preview is already merged
if git merge-base --is-ancestor public/preview HEAD; then
echo "✅ preview is already up to date with public/preview"
exit 0
fi
# Merge but exclude .github/workflows/ (GITHUB_TOKEN lacks workflow permission)
if git merge public/preview --no-commit --no-ff; then
git checkout HEAD -- .github/workflows/ 2>/dev/null || true
git commit -m "chore: sync preview with public/preview"
git push origin preview
echo "✅ preview synced successfully"
else
echo "⚠️ Conflict detected in preview"
# Capture conflicted files before aborting
conflicted_files=$(git diff --name-only --diff-filter=U 2>/dev/null || echo "Unable to determine conflicted files")
git merge --abort
# Check if a sync PR already exists
existing_pr=$(gh pr list --base "preview" --search "Merge public/preview" --state open --json number --jq '.[0].number' 2>/dev/null || echo "")
if [ -n "$existing_pr" ]; then
echo "ℹ️ PR #$existing_pr already exists, skipping"
exit 0
fi
conflict_branch="sync-conflict-preview-$(date +%Y%m%d-%H%M%S)"
git checkout -b "$conflict_branch"
git merge public/preview --no-commit --no-ff || true
git checkout HEAD -- .github/workflows/ 2>/dev/null || true
git add -A
git commit -m "chore: sync preview with public/preview (conflicts present)
This automated sync detected merge conflicts that require manual resolution.
Source: public/preview (https://github.com/aws/agentcore-cli)
Target: preview
Please resolve conflicts and merge this PR." || true
git push origin "$conflict_branch"
gh pr create \
--title "🔀 [Sync Conflict] Merge public/preview → preview" \
--body "## Automated Sync Conflict
This PR was automatically created because merging \`public/preview\` into \`preview\` encountered conflicts.
**Source:** \`preview\` from [aws/agentcore-cli](https://github.com/aws/agentcore-cli)
**Target:** \`preview\`
### Action Required
1. \`git fetch origin && git checkout $conflict_branch\`
2. Resolve merge conflicts
3. \`git add . && git commit\`
4. \`git push origin $conflict_branch\`
5. Merge this PR
### Files with Conflicts
\`\`\`
$conflicted_files
\`\`\`" \
--base "preview" \
--head "$conflict_branch" || echo "⚠️ Failed to create PR"
fi
env:
GH_TOKEN: ${{ steps.app-token.outputs.token }}