From 4ae841def716c10ae2a2be10f81b246805af8d31 Mon Sep 17 00:00:00 2001 From: Samuel Macleod Date: Mon, 2 Dec 2024 13:13:32 +0000 Subject: [PATCH 1/4] Add workflow --- .github/workflows/open-v3-maintenance-prs.yml | 32 +++++++++++++++++ tools/deployments/open-v3-pr.ts | 34 +++++++++++++++++++ 2 files changed, 66 insertions(+) create mode 100644 .github/workflows/open-v3-maintenance-prs.yml create mode 100644 tools/deployments/open-v3-pr.ts diff --git a/.github/workflows/open-v3-maintenance-prs.yml b/.github/workflows/open-v3-maintenance-prs.yml new file mode 100644 index 000000000000..cea05a329556 --- /dev/null +++ b/.github/workflows/open-v3-maintenance-prs.yml @@ -0,0 +1,32 @@ +name: v3 Maintenance + +on: pull_request + +jobs: + open-pr: + if: ${{ github.repository_owner == 'cloudflare' }} + name: Open backport PR for patches + runs-on: ubuntu-latest + concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + timeout-minutes: 30 + steps: + - name: Checkout Repo + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Install Dependencies + uses: ./.github/actions/install-dependencies + + - uses: Ana06/get-changed-files@v1.2 + id: files + with: + format: "json" + + - run: node -r esbuild-register tools/deployments/open-v3-pr.ts + env: + FILES: ${{ steps.files.outputs.all }} + PR_NUMBER: ${{ github.event.number }} + GH_TOKEN: ${{ secrets.GH_ACCESS_TOKEN }} diff --git a/tools/deployments/open-v3-pr.ts b/tools/deployments/open-v3-pr.ts new file mode 100644 index 000000000000..2fe2b3f3230d --- /dev/null +++ b/tools/deployments/open-v3-pr.ts @@ -0,0 +1,34 @@ +import { execSync } from "node:child_process"; +import { readFileSync } from "node:fs"; +import parseChangeset from "@changesets/parse"; + +/* eslint-disable turbo/no-undeclared-env-vars */ +if (require.main === module) { + if (isWranglerPatch(process.env.FILES as string)) { + // Create a new branch for the v3 maintenance PR + execSync(`git checkout -b v3-maintenance-${process.env.PR_NUMBER} -f`); + + execSync(`git push origin HEAD --force`); + + execSync( + `gh pr create --head v3-maintenance-${process.env.PR_NUMBER} --label "skip-pr-description-validation " --title "Backport #${process.env.PR_NUMBER} to Wrangler v3"` + ); + } +} + +export function isWranglerPatch(changedFilesJson: string) { + const changedFiles = JSON.parse(changedFilesJson) as string[]; + const changesets = changedFiles + .filter((f) => f.startsWith(".changeset/")) + .map((c) => parseChangeset(readFileSync(c, "utf8"))); + + let hasWranglerPatch = false; + for (const changeset of changesets) { + for (const release of changeset.releases) { + if (release.name === "wrangler" && release.type === "patch") { + hasWranglerPatch = true; + } + } + } + return hasWranglerPatch; +} From 1bec6e19ad949c25b4d3f875f2e594c0d2377535 Mon Sep 17 00:00:00 2001 From: Samuel Macleod Date: Mon, 2 Dec 2024 13:16:32 +0000 Subject: [PATCH 2/4] test changeset --- .changeset/thin-items-turn.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/thin-items-turn.md diff --git a/.changeset/thin-items-turn.md b/.changeset/thin-items-turn.md new file mode 100644 index 000000000000..0584b0a2aa9d --- /dev/null +++ b/.changeset/thin-items-turn.md @@ -0,0 +1,5 @@ +--- +"wrangler": patch +--- + +test patch bump backporting From d667899c71343240ac3e0d5722ad48237bcd7561 Mon Sep 17 00:00:00 2001 From: Samuel Macleod Date: Mon, 2 Dec 2024 13:18:50 +0000 Subject: [PATCH 3/4] add body --- tools/deployments/open-v3-pr.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/deployments/open-v3-pr.ts b/tools/deployments/open-v3-pr.ts index 2fe2b3f3230d..838473156ee0 100644 --- a/tools/deployments/open-v3-pr.ts +++ b/tools/deployments/open-v3-pr.ts @@ -11,7 +11,7 @@ if (require.main === module) { execSync(`git push origin HEAD --force`); execSync( - `gh pr create --head v3-maintenance-${process.env.PR_NUMBER} --label "skip-pr-description-validation " --title "Backport #${process.env.PR_NUMBER} to Wrangler v3"` + `gh pr create --head v3-maintenance-${process.env.PR_NUMBER} --label "skip-pr-description-validation " --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"` ); } } From 840197a2bd714a4afe0321b2c3f9ac242f66b957 Mon Sep 17 00:00:00 2001 From: Samuel Macleod Date: Mon, 2 Dec 2024 13:20:10 +0000 Subject: [PATCH 4/4] typo --- tools/deployments/open-v3-pr.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/deployments/open-v3-pr.ts b/tools/deployments/open-v3-pr.ts index 838473156ee0..0e29f35cbe3a 100644 --- a/tools/deployments/open-v3-pr.ts +++ b/tools/deployments/open-v3-pr.ts @@ -11,7 +11,7 @@ if (require.main === module) { execSync(`git push origin HEAD --force`); execSync( - `gh pr create --head v3-maintenance-${process.env.PR_NUMBER} --label "skip-pr-description-validation " --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"` + `gh pr create --head v3-maintenance-${process.env.PR_NUMBER} --label "skip-pr-description-validation" --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"` ); } }