Skip to content

Commit

Permalink
C3 dependabot improvements (#3829)
Browse files Browse the repository at this point in the history
* slightly improving the dependabot configs

* add a workflow that generates a proper changeset for such PRs

---------

Co-authored-by: Rahul Sethi <[email protected]>
  • Loading branch information
dario-piotrowicz and RamIdeas authored Aug 25, 2023
1 parent 5c17db1 commit dcdcc36
Show file tree
Hide file tree
Showing 3 changed files with 99 additions and 0 deletions.
9 changes: 9 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,16 @@ updates:
#  being to test the efficacy of the solution, we shall set it
# to "weekly" after a testing period of 1/2 weeks
interval: "daily"
versioning-strategy: increase
# the following is used to add the [C3] prefix to the PR title,
# we override the commit message but setting a prefix like this
# makes it so that also the PR title gets such prefix
commit-message:
prefix: "[C3] "
assignees:
- "@cloudflare/c3"
reviewers:
- "@cloudflare/c3"
labels:
- "C3"
- "dependencies"
64 changes: 64 additions & 0 deletions .github/generate-c3-dependabot-pr-changeset.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import { execSync } from "child_process";
import { writeFileSync } from "fs";

const diff = execSync(
"git diff HEAD~1 packages/create-cloudflare/src/frameworks/package.json"
).toString();

const changedPackages =
diff
.match(/-\s*".*?":\s".*?",?/g)
?.map((match) => match.match(/-\s*"(.*)":/)?.[1])
.filter(Boolean) ?? [];

const changes = changedPackages.map((pkg) => {
const getPackageChangeRegex = (addition) =>
new RegExp(`${addition ? "\\+" : "-"}\\s*"${pkg}":\\s"(.*)",?`);

const from = diff.match(getPackageChangeRegex(false))?.[1];
const to = diff.match(getPackageChangeRegex(true))?.[1];

if (!from || !to) {
throw new Error(
`Unexpected changes for package ${pkg} (could not determine upgrade)`
);
}

return {
package: pkg,
from,
to,
};
});

if (!changes.length) {
console.warn("No changes detected!");
} else {
const prNumber = process.argv[2];

writeFileSync(
`.changeset/c3-frameworks-update-${prNumber}.md`,
`---
"dependabot-testing": patch
---
Framework CLI versions updated in C3
The following framework CLI versions have been updated in C3:
${[
"| package | from | to |",
"|---------|------|----|",
...changes.map(
({ package: pkg, from, to }) => `| \`${pkg}\` | \`${from}\` | \`${to}\` |`
),
]
.map((str) => ` ${str}`)
.join("\n")}
`
);

execSync("git add .changeset");
execSync("git commit --amend -m '[C3] Update frameworks cli dependencies'");
execSync("git push -f");
}
26 changes: 26 additions & 0 deletions .github/workflows/c3-dependabot-versioning-prs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# workflow to update the framework cli versioning PRs we get
# from dependabot for C3

name: "C3: Generate changeset for dependabot PRs"
on:
pull_request_target:
paths:
- "packages/create-cloudflare/src/frameworks/package.json"

jobs:
generate-changeset:
runs-on: ubuntu-latest
if: |
github.event.pull_request.user.login == 'dependabot[bot]'
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 2
ref: ${{ github.head_ref }}
- name: Configure Git
run: |
git config --global user.email [email protected]
git config --global user.name 'Wrangler automated PR updater'
- name: Generate changeset
run: node .github/generate-c3-dependabot-pr-changeset.mjs ${{ github.event.number }}

0 comments on commit dcdcc36

Please sign in to comment.