forked from aws/aws-durable-execution-sdk-python-testing
-
Notifications
You must be signed in to change notification settings - Fork 0
189 lines (161 loc) · 7.05 KB
/
create-emulator-pr.yml
File metadata and controls
189 lines (161 loc) · 7.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
name: Create Emulator PR
on:
pull_request:
branches: [ main ]
types: [opened, synchronize, closed]
permissions:
contents: read
pull-requests: write
issues: write
jobs:
cleanup-emulator-pr:
if: github.event.action == 'closed'
runs-on: ubuntu-latest
steps:
- uses: webfactory/ssh-agent@v0.9.1
with:
ssh-private-key: ${{ secrets.EMULATOR_KEY }}
- name: Delete emulator branch
run: |
PR_NUMBER="${{ github.event.pull_request.number }}"
EMULATOR_BRANCH="testing-sdk-pr-${PR_NUMBER}-sync"
git clone git@github.com:aws/aws-durable-execution-emulator.git
cd aws-durable-execution-emulator
git push origin --delete "$EMULATOR_BRANCH" || echo "Branch may not exist"
create-emulator-pr:
if: github.event.action == 'opened' || github.event.action == 'synchronize'
runs-on: ubuntu-latest
steps:
- name: Checkout testing SDK repo
uses: actions/checkout@v5
with:
path: testing-sdk
- name: Set up Python
uses: actions/setup-python@v6
with:
python-version: "3.13"
- name: Install uv
uses: astral-sh/setup-uv@v4
- uses: webfactory/ssh-agent@v0.9.1
with:
ssh-private-key: |
${{ secrets.EMULATOR_PRIVATE_KEY }}
${{ secrets.SDK_KEY }}
- name: Checkout emulator repo
run: |
git clone git@github.com:aws/aws-durable-execution-emulator.git 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 }}"
PR_NUMBER="${{ github.event.pull_request.number }}"
EMULATOR_BRANCH="testing-sdk-pr-${PR_NUMBER}-sync"
# 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 local testing SDK (temporary, not committed)
TESTING_SDK_PATH="$(realpath ../testing-sdk)"
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 @ file://${TESTING_SDK_PATH}|" 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
if git commit -m "Lock testing SDK branch: $BRANCH_NAME (PR #$PR_NUMBER)"; then
echo "Changes committed successfully"
git push --force-with-lease origin "$EMULATOR_BRANCH"
echo "Branch pushed successfully"
else
echo "No changes to commit"
# Still need to push the branch even if no changes
git push --force-with-lease origin "$EMULATOR_BRANCH" || git push origin "$EMULATOR_BRANCH"
fi
- name: Create or update PR in emulator repo
uses: actions/github-script@v7
with:
github-token: ${{ secrets.EMULATOR_REPO_TOKEN }}
script: |
const fs = require('fs');
const pr = context.payload.pull_request;
const branch_name = pr.head.ref;
const emulator_branch = `testing-sdk-pr-${pr.number}-sync`;
// Wait a moment for branch to be available
await new Promise(resolve => setTimeout(resolve, 2000));
// Read and populate PR template
const template = fs.readFileSync('testing-sdk/.github/workflows/emulator-pr-template.md', 'utf8');
const pr_body = template
.replace(/{{PR_NUMBER}}/g, pr.number)
.replace(/{{BRANCH_NAME}}/g, branch_name);
try {
// Check if PR already exists
let existingPR = null;
try {
const prs = await github.rest.pulls.list({
owner: 'aws',
repo: 'aws-durable-execution-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-durable-execution-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
console.log("Creating an emulator PR")
const response = await github.rest.pulls.create({
owner: 'aws',
repo: 'aws-durable-execution-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}`);
console.log(`Error status: ${error.status}`);
console.log(`Error response: ${JSON.stringify(error.response?.data)}`);
core.setFailed(`Failed to manage emulator PR: ${error.message}`);
}