ci: create PR in emulator repo to build preview emulator binaries on … #1
Workflow file for this run
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: Create Emulator PR | ||
| on: | ||
| pull_request: | ||
| branches: [ main ] | ||
| types: [opened, synchronize, closed] | ||
| permissions: | ||
| contents: read | ||
| jobs: | ||
| cleanup-emulator-pr: | ||
| if: github.event.action == 'closed' | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Delete emulator branch | ||
| uses: actions/github-script@v7 | ||
| with: | ||
| github-token: ${{ secrets.EMULATOR_REPO_TOKEN }} | ||
| script: | | ||
| const branch_name = context.payload.pull_request.head.ref; | ||
| const emulator_branch = `testing-sdk-${branch_name}`; | ||
| try { | ||
| await github.rest.git.deleteRef({ | ||
| owner: 'aws', | ||
| repo: 'aws-lambda-durable-functions-emulator', | ||
| ref: `heads/${emulator_branch}` | ||
| }); | ||
| console.log(`Deleted emulator branch: ${emulator_branch}`); | ||
| } catch (error) { | ||
| console.log(`Branch ${emulator_branch} may not exist or already deleted`); | ||
| } | ||
| create-emulator-pr: | ||
| if: github.event.action == 'opened' || github.event.action == 'synchronize' | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Set up Python | ||
| uses: actions/setup-python@v6 | ||
| with: | ||
| python-version: "3.13" | ||
| - name: Install uv | ||
| uses: astral-sh/setup-uv@v4 | ||
| - name: Checkout emulator repo | ||
| uses: actions/checkout@v5 | ||
| with: | ||
| repository: aws/aws-lambda-durable-functions-emulator | ||
| token: ${{ secrets.EMULATOR_REPO_TOKEN }} | ||
| path: emulator | ||
| - name: Create branch and update uv.lock | ||
| working-directory: emulator | ||
| run: | | ||
| # Configure git | ||
| git config user.name "github-actions[bot]" | ||
| git config user.email "github-actions[bot]@users.noreply.github.com" | ||
| # Get PR info | ||
| BRANCH_NAME="${{ github.event.pull_request.head.ref }}" | ||
| EMULATOR_BRANCH="testing-sdk-${BRANCH_NAME}" | ||
| PR_NUMBER="${{ github.event.pull_request.number }}" | ||
| TESTING_SDK_URL="git+ssh://git@github.com/${{ github.repository }}.git@${BRANCH_NAME}" | ||
| # Create or update branch | ||
| git fetch origin | ||
| if git show-ref --verify --quiet refs/remotes/origin/"$EMULATOR_BRANCH"; then | ||
| git checkout "$EMULATOR_BRANCH" | ||
| git reset --hard origin/main | ||
| else | ||
| git checkout -b "$EMULATOR_BRANCH" | ||
| fi | ||
| # Update pyproject.toml to use the testing SDK branch (temporary, not committed) | ||
| sed -i.bak "s|aws-durable-execution-sdk-python-testing @ git+ssh://git@github.com/aws/aws-durable-execution-sdk-python-testing.git|aws-durable-execution-sdk-python-testing @ ${TESTING_SDK_URL}|" pyproject.toml | ||
| rm pyproject.toml.bak | ||
| # Generate new uv.lock with the specific testing SDK commit | ||
| uv lock | ||
| # Show what changed | ||
| echo "=== Changes to be committed ===" | ||
| git diff --name-status | ||
| git diff uv.lock || echo "uv.lock is a new file" | ||
| # Restore original pyproject.toml (don't commit the temporary change) | ||
| git checkout pyproject.toml | ||
| # Commit and push only the uv.lock file | ||
| git add uv.lock | ||
| git commit -m "Lock testing SDK branch: $BRANCH_NAME (PR #$PR_NUMBER)" || echo "No changes to commit" | ||
| git push origin "$EMULATOR_BRANCH" | ||
| - name: Create or update PR in emulator repo | ||
| uses: actions/github-script@v7 | ||
| with: | ||
| github-token: ${{ secrets.EMULATOR_REPO_TOKEN }} | ||
| script: | | ||
| const pr = context.payload.pull_request; | ||
| const branch_name = pr.head.ref; | ||
| const emulator_branch = `testing-sdk-${branch_name}`; | ||
| const pr_body = `*Issue #, if available:* Related to aws/aws-durable-execution-sdk-python-testing#${pr.number} | ||
| *Description of changes:* Testing changes from testing SDK branch \`${branch_name}\` | ||
| ## Dependencies | ||
| This PR locks the testing SDK to a specific commit from branch \`${branch_name}\` using uv.lock for reproducible builds. | ||
| **Testing SDK Dependency:** \`git+https://github.com/${context.repo.owner}/${context.repo.repo}.git@${branch_name}\` | ||
| The emulator binaries will be built using the exact testing SDK commit locked in uv.lock from PR aws/aws-durable-execution-sdk-python-testing#${pr.number}. | ||
| ## Testing | ||
| - [ ] Binaries created successfully with locked dependencies | ||
| - [ ] Emulator functionality verified with new testing SDK changes | ||
| ## Checklist | ||
| - [ ] Code follows project style guidelines | ||
| - [ ] Self-review completed | ||
| - [ ] Changes are backward compatible (or breaking changes documented) | ||
| By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.`; | ||
| try { | ||
| // Check if PR already exists | ||
| let existingPR = null; | ||
| try { | ||
| const prs = await github.rest.pulls.list({ | ||
| owner: 'aws', | ||
| repo: 'aws-lambda-durable-functions-emulator', | ||
| head: `aws:${emulator_branch}`, | ||
| state: 'open' | ||
| }); | ||
| existingPR = prs.data[0]; | ||
| } catch (e) { | ||
| console.log('No existing PR found'); | ||
| } | ||
| if (existingPR) { | ||
| // Update existing PR | ||
| await github.rest.pulls.update({ | ||
| owner: 'aws', | ||
| repo: 'aws-lambda-durable-functions-emulator', | ||
| pull_number: existingPR.number, | ||
| title: `Lock testing SDK branch: ${branch_name} (PR #${pr.number})`, | ||
| body: pr_body | ||
| }); | ||
| console.log(`Updated emulator PR: ${existingPR.html_url}`); | ||
| // Comment on original PR about update | ||
| await github.rest.issues.createComment({ | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| issue_number: pr.number, | ||
| body: `🔄 **Emulator PR Updated**\n\nThe emulator PR has been updated with locked dependencies:\n\n➡️ ${existingPR.html_url}` | ||
| }); | ||
| } else { | ||
| // Create new PR | ||
| const response = await github.rest.pulls.create({ | ||
| owner: 'aws', | ||
| repo: 'aws-lambda-durable-functions-emulator', | ||
| title: `Lock testing SDK branch: ${branch_name} (PR #${pr.number})`, | ||
| head: emulator_branch, | ||
| base: 'main', | ||
| body: pr_body, | ||
| draft: true | ||
| }); | ||
| console.log(`Created emulator PR: ${response.data.html_url}`); | ||
| // Comment on original PR | ||
| await github.rest.issues.createComment({ | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| issue_number: pr.number, | ||
| body: `🤖 **Emulator PR Created**\n\nA draft PR has been created with locked dependencies:\n\n➡️ ${response.data.html_url}\n\nThe emulator will build binaries using the exact testing SDK commit locked in uv.lock.` | ||
| }); | ||
| } | ||
| } catch (error) { | ||
| console.log(`Error managing PR: ${error.message}`); | ||
| core.setFailed(`Failed to manage emulator PR: ${error.message}`); | ||
| } | ||