Skip to content

Commit f68909b

Browse files
authored
Automatically backport Wrangler patches to v3 (#7400)
* Add v3 maintenance mechanic * Update open-v3-pr.ts * address comments
1 parent f5fb510 commit f68909b

File tree

2 files changed

+76
-0
lines changed

2 files changed

+76
-0
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
name: v3 Maintenance
2+
3+
on: pull_request
4+
5+
jobs:
6+
open-pr:
7+
if: ${{ github.repository_owner == 'cloudflare' }}
8+
name: Open backport PR for patches
9+
runs-on: macos-latest
10+
concurrency:
11+
group: ${{ github.workflow }}-${{ github.ref }}
12+
cancel-in-progress: true
13+
timeout-minutes: 30
14+
steps:
15+
- name: Checkout Repo
16+
uses: actions/checkout@v4
17+
with:
18+
fetch-depth: 0
19+
20+
- name: Install Dependencies
21+
uses: ./.github/actions/install-dependencies
22+
23+
- uses: Ana06/[email protected]
24+
id: files
25+
with:
26+
format: "json"
27+
28+
- run: node -r esbuild-register tools/deployments/open-v3-pr.ts
29+
env:
30+
FILES: ${{ steps.files.outputs.all }}
31+
PR_NUMBER: ${{ github.event.number }}
32+
GH_TOKEN: ${{ secrets.GH_ACCESS_TOKEN }}
33+
LABELS: ${{ toJson(github.event.pull_request.labels.*.name) }}

tools/deployments/open-v3-pr.ts

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import { execSync } from "node:child_process";
2+
import { readFileSync } from "node:fs";
3+
import parseChangeset from "@changesets/parse";
4+
5+
/* eslint-disable turbo/no-undeclared-env-vars */
6+
if (require.main === module) {
7+
const parsedLabels = JSON.parse(process.env.LABELS as string) as string[];
8+
if (
9+
isWranglerPatch(process.env.FILES as string) &&
10+
!parsedLabels.includes("skip-v3-pr")
11+
) {
12+
// Create a new branch for the v3 maintenance PR
13+
execSync(`git checkout -b v3-maintenance-${process.env.PR_NUMBER} -f`);
14+
15+
execSync(`git push origin HEAD --force`);
16+
17+
try {
18+
// Open PR
19+
execSync(
20+
`gh pr create --base main --head v3-maintenance-${process.env.PR_NUMBER} --label "skip-pr-description-validation" --label "skip-v3-pr" --title "Backport #${process.env.PR_NUMBER} to Wrangler v3" --body "This is an automatically opened PR to backport patch changes from #${process.env.PR_NUMBER} to Wrangler v3"`
21+
);
22+
} catch {
23+
// Ignore "PR already created failures"
24+
}
25+
}
26+
}
27+
28+
export function isWranglerPatch(changedFilesJson: string) {
29+
const changedFiles = JSON.parse(changedFilesJson) as string[];
30+
const changesets = changedFiles
31+
.filter((f) => f.startsWith(".changeset/"))
32+
.map((c) => parseChangeset(readFileSync(c, "utf8")));
33+
34+
let hasWranglerPatch = false;
35+
for (const changeset of changesets) {
36+
for (const release of changeset.releases) {
37+
if (release.name === "wrangler" && release.type === "patch") {
38+
hasWranglerPatch = true;
39+
}
40+
}
41+
}
42+
return hasWranglerPatch;
43+
}

0 commit comments

Comments
 (0)