Skip to content

Commit 1eb7e4e

Browse files
committed
ci: create PR in emulator repo to build preview emulator binaries on testing SDK changes
1 parent 3850837 commit 1eb7e4e

File tree

1 file changed

+189
-0
lines changed

1 file changed

+189
-0
lines changed
Lines changed: 189 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,189 @@
1+
name: Create Emulator PR
2+
3+
on:
4+
pull_request:
5+
branches: [ main ]
6+
types: [opened, synchronize, closed]
7+
8+
permissions:
9+
contents: read
10+
11+
jobs:
12+
cleanup-emulator-pr:
13+
if: github.event.action == 'closed'
14+
runs-on: ubuntu-latest
15+
steps:
16+
- name: Delete emulator branch
17+
uses: actions/github-script@v7
18+
with:
19+
github-token: ${{ secrets.EMULATOR_REPO_TOKEN }}
20+
script: |
21+
const branch_name = context.payload.pull_request.head.ref;
22+
const emulator_branch = `testing-sdk-${branch_name}`;
23+
24+
try {
25+
await github.rest.git.deleteRef({
26+
owner: 'aws',
27+
repo: 'aws-lambda-durable-functions-emulator',
28+
ref: `heads/${emulator_branch}`
29+
});
30+
console.log(`Deleted emulator branch: ${emulator_branch}`);
31+
} catch (error) {
32+
console.log(`Branch ${emulator_branch} may not exist or already deleted`);
33+
}
34+
35+
create-emulator-pr:
36+
if: github.event.action == 'opened' || github.event.action == 'synchronize'
37+
runs-on: ubuntu-latest
38+
steps:
39+
- name: Set up Python
40+
uses: actions/setup-python@v6
41+
with:
42+
python-version: "3.13"
43+
44+
- name: Install uv
45+
uses: astral-sh/setup-uv@v4
46+
47+
- name: Checkout emulator repo
48+
uses: actions/checkout@v5
49+
with:
50+
repository: aws/aws-lambda-durable-functions-emulator
51+
token: ${{ secrets.EMULATOR_REPO_TOKEN }}
52+
path: emulator
53+
54+
- name: Create branch and update uv.lock
55+
working-directory: emulator
56+
run: |
57+
# Configure git
58+
git config user.name "github-actions[bot]"
59+
git config user.email "github-actions[bot]@users.noreply.github.com"
60+
61+
# Get PR info
62+
BRANCH_NAME="${{ github.event.pull_request.head.ref }}"
63+
EMULATOR_BRANCH="testing-sdk-${BRANCH_NAME}"
64+
PR_NUMBER="${{ github.event.pull_request.number }}"
65+
TESTING_SDK_URL="git+ssh://git@github.com/${{ github.repository }}.git@${BRANCH_NAME}"
66+
67+
# Create or update branch
68+
git fetch origin
69+
if git show-ref --verify --quiet refs/remotes/origin/"$EMULATOR_BRANCH"; then
70+
git checkout "$EMULATOR_BRANCH"
71+
git reset --hard origin/main
72+
else
73+
git checkout -b "$EMULATOR_BRANCH"
74+
fi
75+
76+
# Update pyproject.toml to use the testing SDK branch (temporary, not committed)
77+
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
78+
rm pyproject.toml.bak
79+
80+
# Generate new uv.lock with the specific testing SDK commit
81+
uv lock
82+
83+
# Show what changed
84+
echo "=== Changes to be committed ==="
85+
git diff --name-status
86+
git diff uv.lock || echo "uv.lock is a new file"
87+
88+
# Restore original pyproject.toml (don't commit the temporary change)
89+
git checkout pyproject.toml
90+
91+
# Commit and push only the uv.lock file
92+
git add uv.lock
93+
git commit -m "Lock testing SDK branch: $BRANCH_NAME (PR #$PR_NUMBER)" || echo "No changes to commit"
94+
git push origin "$EMULATOR_BRANCH"
95+
96+
- name: Create or update PR in emulator repo
97+
uses: actions/github-script@v7
98+
with:
99+
github-token: ${{ secrets.EMULATOR_REPO_TOKEN }}
100+
script: |
101+
const pr = context.payload.pull_request;
102+
const branch_name = pr.head.ref;
103+
const emulator_branch = `testing-sdk-${branch_name}`;
104+
105+
const pr_body = `*Issue #, if available:* Related to aws/aws-durable-execution-sdk-python-testing#${pr.number}
106+
107+
*Description of changes:* Testing changes from testing SDK branch \`${branch_name}\`
108+
109+
## Dependencies
110+
This PR locks the testing SDK to a specific commit from branch \`${branch_name}\` using uv.lock for reproducible builds.
111+
112+
**Testing SDK Dependency:** \`git+https://github.com/${context.repo.owner}/${context.repo.repo}.git@${branch_name}\`
113+
114+
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}.
115+
116+
## Testing
117+
118+
- [ ] Binaries created successfully with locked dependencies
119+
- [ ] Emulator functionality verified with new testing SDK changes
120+
121+
## Checklist
122+
123+
- [ ] Code follows project style guidelines
124+
- [ ] Self-review completed
125+
- [ ] Changes are backward compatible (or breaking changes documented)
126+
127+
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.`;
128+
129+
try {
130+
// Check if PR already exists
131+
let existingPR = null;
132+
try {
133+
const prs = await github.rest.pulls.list({
134+
owner: 'aws',
135+
repo: 'aws-lambda-durable-functions-emulator',
136+
head: `aws:${emulator_branch}`,
137+
state: 'open'
138+
});
139+
existingPR = prs.data[0];
140+
} catch (e) {
141+
console.log('No existing PR found');
142+
}
143+
144+
if (existingPR) {
145+
// Update existing PR
146+
await github.rest.pulls.update({
147+
owner: 'aws',
148+
repo: 'aws-lambda-durable-functions-emulator',
149+
pull_number: existingPR.number,
150+
title: `Lock testing SDK branch: ${branch_name} (PR #${pr.number})`,
151+
body: pr_body
152+
});
153+
154+
console.log(`Updated emulator PR: ${existingPR.html_url}`);
155+
156+
// Comment on original PR about update
157+
await github.rest.issues.createComment({
158+
owner: context.repo.owner,
159+
repo: context.repo.repo,
160+
issue_number: pr.number,
161+
body: `🔄 **Emulator PR Updated**\n\nThe emulator PR has been updated with locked dependencies:\n\n➡️ ${existingPR.html_url}`
162+
});
163+
} else {
164+
// Create new PR
165+
const response = await github.rest.pulls.create({
166+
owner: 'aws',
167+
repo: 'aws-lambda-durable-functions-emulator',
168+
title: `Lock testing SDK branch: ${branch_name} (PR #${pr.number})`,
169+
head: emulator_branch,
170+
base: 'main',
171+
body: pr_body,
172+
draft: true
173+
});
174+
175+
console.log(`Created emulator PR: ${response.data.html_url}`);
176+
177+
// Comment on original PR
178+
await github.rest.issues.createComment({
179+
owner: context.repo.owner,
180+
repo: context.repo.repo,
181+
issue_number: pr.number,
182+
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.`
183+
});
184+
}
185+
186+
} catch (error) {
187+
console.log(`Error managing PR: ${error.message}`);
188+
core.setFailed(`Failed to manage emulator PR: ${error.message}`);
189+
}

0 commit comments

Comments
 (0)