|
| 1 | +name: Finalize Copybara Sync |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - 'copybara/v*' |
| 7 | + |
| 8 | +concurrency: |
| 9 | + group: copybara-sync-${{ github.ref }} |
| 10 | + cancel-in-progress: true |
| 11 | + |
| 12 | +jobs: |
| 13 | + finalize: |
| 14 | + runs-on: ubuntu-latest |
| 15 | + permissions: |
| 16 | + contents: write |
| 17 | + pull-requests: write |
| 18 | + |
| 19 | + steps: |
| 20 | + - name: Extract version from branch name |
| 21 | + id: version |
| 22 | + run: | |
| 23 | + VERSION=$(echo "$GITHUB_REF" | sed 's|refs/heads/copybara/||') |
| 24 | + echo "version=$VERSION" >> $GITHUB_OUTPUT |
| 25 | +
|
| 26 | + - uses: actions/checkout@v6 |
| 27 | + with: |
| 28 | + ref: ${{ github.ref }} |
| 29 | + fetch-depth: 0 |
| 30 | + |
| 31 | + - name: Extract original commit author |
| 32 | + id: author |
| 33 | + run: | |
| 34 | + AUTHOR_EMAIL=$(git log -1 --format='%ae' --author='^(?!.*actions@github.com)' --perl-regexp 2>/dev/null || git log -1 --format='%ae') |
| 35 | + AUTHOR_NAME=$(git log -1 --format='%an' --author='^(?!.*actions@github.com)' --perl-regexp 2>/dev/null || git log -1 --format='%an') |
| 36 | + echo "email=$AUTHOR_EMAIL" >> $GITHUB_OUTPUT |
| 37 | + echo "name=$AUTHOR_NAME" >> $GITHUB_OUTPUT |
| 38 | +
|
| 39 | + if [[ "$AUTHOR_EMAIL" =~ ^([^@]+)@users\.noreply\.github\.com$ ]]; then |
| 40 | + GITHUB_USER=$(echo "${BASH_REMATCH[1]}" | sed 's/^[0-9]*+//') |
| 41 | + echo "github_user=$GITHUB_USER" >> $GITHUB_OUTPUT |
| 42 | + else |
| 43 | + echo "github_user=" >> $GITHUB_OUTPUT |
| 44 | + fi |
| 45 | +
|
| 46 | + - name: Create Pull Request |
| 47 | + env: |
| 48 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 49 | + VERSION: ${{ steps.version.outputs.version }} |
| 50 | + AUTHOR_NAME: ${{ steps.author.outputs.name }} |
| 51 | + AUTHOR_EMAIL: ${{ steps.author.outputs.email }} |
| 52 | + GITHUB_USER: ${{ steps.author.outputs.github_user }} |
| 53 | + run: | |
| 54 | + PR_BODY="## Copybara Sync - Release ${VERSION} |
| 55 | +
|
| 56 | + This PR was automatically created by Copybara, syncing changes from the [overmindtech/workspace](https://github.com/overmindtech/workspace) monorepo. |
| 57 | +
|
| 58 | + **Original author:** ${AUTHOR_NAME} (${AUTHOR_EMAIL}) |
| 59 | +
|
| 60 | + ### What happens when this PR is merged? |
| 61 | +
|
| 62 | + 1. The \`tag-on-merge\` workflow will automatically create the \`${VERSION}\` tag on main |
| 63 | + 2. Terraform Registry will detect the tag via webhook and publish the module |
| 64 | +
|
| 65 | + ### Review Checklist |
| 66 | +
|
| 67 | + - [ ] Changes look correct and match the expected monorepo sync |
| 68 | + " |
| 69 | +
|
| 70 | + PR_URL=$(gh pr create \ |
| 71 | + --base main \ |
| 72 | + --head "${{ github.ref_name }}" \ |
| 73 | + --title "Release ${VERSION}" \ |
| 74 | + --body "$PR_BODY") |
| 75 | +
|
| 76 | + echo "Created PR: $PR_URL" |
| 77 | +
|
| 78 | + if [ -n "$GITHUB_USER" ]; then |
| 79 | + echo "Requesting review from original author: $GITHUB_USER" |
| 80 | + gh pr edit "$PR_URL" --add-reviewer "$GITHUB_USER" || true |
| 81 | + fi |
| 82 | +
|
| 83 | + echo "Requesting review from Engineering team" |
| 84 | + gh pr edit "$PR_URL" --add-reviewer "overmindtech/Engineering" || true |
0 commit comments