Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automatically backport Wrangler patches to v3 #7400

Open
wants to merge 9 commits into
base: next
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions .github/workflows/open-v3-maintenance-prs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
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/[email protected]
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 }}
LABELS: ${{ toJson(github.event.pull_request.labels.*.name) }}
43 changes: 43 additions & 0 deletions tools/deployments/open-v3-pr.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
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) {
const parsedLabels = JSON.parse(process.env.LABELS as string) as string[];
if (
isWranglerPatch(process.env.FILES as string) &&
!parsedLabels.includes("skip-backport")
) {
// 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`);

try {
// Open PR
execSync(
`gh pr create --base next --head v3-maintenance-${process.env.PR_NUMBER} --label "skip-pr-description-validation" --label "skip-backport" --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"`
);
} catch {
// Ignore "PR already created failures"
}
}
}

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;
}
Loading