Skip to content

Commit 7f6c11d

Browse files
authored
check before create (#120)
1 parent 7a8b805 commit 7f6c11d

File tree

1 file changed

+27
-5
lines changed

1 file changed

+27
-5
lines changed

.github/workflows/check-emulator-version.yaml

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -159,25 +159,49 @@ jobs:
159159
github-token: ${{ secrets.GITHUB_TOKEN }}
160160
script: |
161161
const nextVersion = process.env.NEXT_VERSION;
162+
const issueTitle = `Emulator version update verification failed: ${nextVersion}`;
163+
164+
console.log(`Checking for existing issues for version: ${nextVersion}`);
165+
166+
// Search for existing open issues with the same title
167+
const existingIssues = await github.rest.search.issuesAndPullRequests({
168+
q: `repo:${context.repo.owner}/${context.repo.repo} is:issue is:open "${issueTitle}"`
169+
});
170+
171+
if (existingIssues.data.total_count > 0) {
172+
console.log(`Found existing issue for version ${nextVersion}, skipping creation`);
173+
return;
174+
}
162175
163176
console.log(`Creating issue for failed version: ${nextVersion}`);
164177
165178
await github.rest.issues.create({
166179
owner: context.repo.owner,
167180
repo: context.repo.repo,
168-
title: `Emulator version update verification failed: ${nextVersion}`,
181+
title: issueTitle,
169182
body: `The verification of the next emulator version ${nextVersion} failed. Please check the [workflow run](${process.env.GITHUB_SERVER_URL}/${context.repo.owner}/${context.repo.repo}/actions/runs/${process.env.GITHUB_RUN_ID}) for details.`
170183
});
171184
env:
172185
NEXT_VERSION: ${{ steps.version-check.outputs.next_version }}
173186

174-
- name: Create Pull Request
187+
- name: Check for existing PRs and create new one if needed
175188
if: steps.process-versions.outputs.updated == 'true'
176189
env:
177190
GH_TOKEN: ${{ secrets.CREATE_PR_PAT }}
178191
CURRENT_VERSION: ${{ steps.version-check.outputs.current_version }}
179192
UPDATED_VERSION: ${{ steps.process-versions.outputs.updated_version }}
180193
run: |
194+
# Check for existing PRs with the same title
195+
PR_TITLE="chore: update emulator version to $UPDATED_VERSION"
196+
EXISTING_PR=$(gh pr list --state open --search "$PR_TITLE" --json number --jq '.[0].number')
197+
198+
if [ -n "$EXISTING_PR" ]; then
199+
echo "Found existing PR #$EXISTING_PR with the same title, skipping PR creation"
200+
exit 0
201+
fi
202+
203+
echo "No existing PR found, creating a new one"
204+
181205
# Create and checkout a new branch
182206
git branch -d bump-base-version &>/dev/null || true
183207
git checkout -b bump-base-version
@@ -192,11 +216,9 @@ jobs:
192216
193217
# Create the PR
194218
gh pr create \
195-
--title "chore: update emulator version to $UPDATED_VERSION" \
219+
--title "$PR_TITLE" \
196220
--body "This PR updates the Cloud Spanner emulator version from $CURRENT_VERSION to $UPDATED_VERSION.
197221
Original Release Notes: https://github.com/GoogleCloudPlatform/cloud-spanner-emulator/releases/tag/v$UPDATED_VERSION
198222
199223
This PR was automatically generated by the check-emulator-version workflow." \
200224
--base master
201-
202-

0 commit comments

Comments
 (0)