|
| 1 | +name: devnet-replicate-change |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - main # template repo main branch |
| 7 | + workflow_dispatch: |
| 8 | + |
| 9 | +env: |
| 10 | + SOURCE_REPOSITORY: conterra/mapapps-devnet-blueprint # template repo full name |
| 11 | + SOURCE_BRANCH: main |
| 12 | + TARGET_REPOS: | |
| 13 | + conterra/mapapps-weather-visualization |
| 14 | + GIT_BOT_NAME: 'GitHub Actions Bot' |
| 15 | + GIT_BOT_EMAIL: 'actions@github.com' |
| 16 | + |
| 17 | +jobs: |
| 18 | + sync: |
| 19 | + runs-on: ubuntu-latest |
| 20 | + steps: |
| 21 | + - name: Checkout Template Repo |
| 22 | + uses: actions/checkout@v4 |
| 23 | + with: |
| 24 | + repository: ${{ env.SOURCE_REPOSITORY }} |
| 25 | + ref: ${{ env.SOURCE_BRANCH }} |
| 26 | + token: ${{secrets.TECHNICAL_USER_RELEASE_TOKEN}} |
| 27 | + |
| 28 | + - name: Sync changes and create PRs |
| 29 | + env: |
| 30 | + PAT: ${{secrets.TECHNICAL_USER_RELEASE_TOKEN}} |
| 31 | + run: | |
| 32 | + while read -r target_repo; do |
| 33 | + echo "Processing $target_repo" |
| 34 | + repo_name=$(basename "$target_repo") |
| 35 | + git clone "https://x-access-token:${PAT}@github.com/$target_repo.git" |
| 36 | + cd "$repo_name" || exit 1 |
| 37 | +
|
| 38 | + # Copy changes from template repo (assumed checked out in ../) |
| 39 | + rsync -av --delete --exclude='.git' ../ "$repo_name/" |
| 40 | +
|
| 41 | + # Example placeholder replacement: |
| 42 | + grep -rl '__TARGET_REPO_NAME__' . | xargs sed -i "s/__TARGET_REPO_NAME__/$repo_name/g" |
| 43 | +
|
| 44 | + # Configure git user |
| 45 | + git config user.name "$GIT_BOT_NAME" |
| 46 | + git config user.email "$GIT_BOT_EMAIL" |
| 47 | +
|
| 48 | + # Create a new branch for the update |
| 49 | + BRANCH="template-sync-$(date +%Y%m%d%H%M%S)" |
| 50 | + git checkout -b "$BRANCH" |
| 51 | +
|
| 52 | + # Add and commit changes |
| 53 | + git add . |
| 54 | + if git diff --cached --quiet; then |
| 55 | + echo "No changes to commit for $repo_name" |
| 56 | + cd .. |
| 57 | + rm -rf "$repo_name" |
| 58 | + continue |
| 59 | + fi |
| 60 | + git commit -m "[Template Sync] Update from template repo" |
| 61 | +
|
| 62 | + # Push branch |
| 63 | + git push origin "$BRANCH" |
| 64 | +
|
| 65 | + # Create pull request using GitHub CLI (gh) |
| 66 | + gh auth login --with-token < "$PAT" |
| 67 | + gh pr create --title "[Template Sync] Update from template repo" \ |
| 68 | + --body "This PR synchronizes changes from the template repository." \ |
| 69 | + --head "$BRANCH" --base main --repo "$target_repo" |
| 70 | +
|
| 71 | + cd .. |
| 72 | + rm -rf "$repo_name" |
| 73 | + done <<< "${TARGET_REPOS}" |
0 commit comments