-
Notifications
You must be signed in to change notification settings - Fork 736
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* 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
1 parent
5c17db1
commit dcdcc36
Showing
3 changed files
with
99 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }} |