forked from cloudflare/workers-sdk
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'cloudflare:main' into main
- Loading branch information
Showing
185 changed files
with
4,228 additions
and
1,304 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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,35 @@ | ||
name: "Install Dependencies" | ||
description: "Install dependencies, fetching from cache when possible" | ||
runs: | ||
using: "composite" | ||
steps: | ||
- name: Use Node.js ${{ env.node-version }} | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: ${{ env.node-version }} | ||
cache: "npm" # cache ~/.npm in case 'npm ci' needs to run | ||
|
||
- name: ESlint and Typescript caching | ||
uses: actions/cache@v3 | ||
id: eslint-cache | ||
with: | ||
path: | | ||
.eslintcache | ||
tsconfig.tsbuildinfo | ||
key: ${{ matrix.os }}-eslint-tsbuildinfo-${{ hashFiles('**/*.ts','**/*.js', 'package.json', 'tsconfig.json') }} | ||
|
||
# Attempt to cache all the node_modules directories based on the OS and package lock. | ||
- name: Cache node_modules | ||
id: npm-cache | ||
uses: actions/cache@v3 | ||
env: | ||
cache-name: cache-node-modules | ||
with: | ||
key: ${{ runner.os }}-${{ env.node-version }}-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }} | ||
path: "**/node_modules" | ||
|
||
# If the cache missed then install using `npm ci` to follow package lock exactly | ||
- if: ${{ steps.npm-cache.outputs.cache-hit != 'true'}} | ||
shell: bash | ||
name: Install NPM Dependencies | ||
run: npm ci |
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,24 @@ | ||
version: 2 | ||
updates: | ||
# Automatically check for updates in framework CLIs for C3 | ||
- package-ecosystem: "npm" | ||
directory: "/packages/create-cloudflare/src/frameworks" | ||
schedule: | ||
# Note: this interval is likely going to be too short and create | ||
# too much noise, we are just setting it as daily for the time | ||
# 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" |
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,68 @@ | ||
import assert from "node:assert"; | ||
import { existsSync } from "node:fs"; | ||
import fs from "node:fs/promises"; | ||
import module from "node:module"; | ||
import path from "node:path"; | ||
import url from "node:url"; | ||
|
||
/** | ||
* @param {string} from | ||
* @returns {string | undefined} | ||
*/ | ||
function findClosestPackageJson(from) { | ||
while (true) { | ||
const packageJsonPath = path.join(from, "package.json"); | ||
if (existsSync(packageJsonPath)) return packageJsonPath; | ||
const parent = path.dirname(from); | ||
if (parent === from) return; | ||
from = parent; | ||
} | ||
} | ||
|
||
const __filename = url.fileURLToPath(import.meta.url); | ||
const __dirname = path.dirname(__filename); | ||
|
||
// 1. Load `wrangler` `package.json`, getting `wrangler` version and `miniflare` version constraint | ||
const wranglerPackagePath = path.resolve(__dirname, "../packages/wrangler"); | ||
const wranglerPackageJsonPath = path.join(wranglerPackagePath, "package.json"); | ||
const wranglerPackageJson = await fs.readFile(wranglerPackageJsonPath, "utf8"); | ||
const wranglerPackage = JSON.parse(wranglerPackageJson); | ||
const wranglerVersion = wranglerPackage.version; | ||
const miniflareVersionConstraint = wranglerPackage.dependencies.miniflare; | ||
|
||
// 2. Load `miniflare` `package.json`, getting `miniflare` version and `workerd` version constraint | ||
const wranglerRequire = module.createRequire(wranglerPackagePath); | ||
const miniflareMainPath = wranglerRequire.resolve("miniflare"); | ||
const miniflarePackageJsonPath = findClosestPackageJson(miniflareMainPath); | ||
assert(miniflarePackageJsonPath !== undefined); | ||
const miniflarePackagePath = path.dirname(miniflarePackageJsonPath); | ||
const miniflarePackageJson = await fs.readFile( | ||
miniflarePackageJsonPath, | ||
"utf8" | ||
); | ||
const miniflarePackage = JSON.parse(miniflarePackageJson); | ||
const miniflareVersion = miniflarePackage.version; | ||
const workerdVersionConstraint = miniflarePackage.dependencies.workerd; | ||
|
||
// 3. Load `workerd` `package.json`, getting `workerd` version | ||
const miniflareRequire = module.createRequire(miniflarePackagePath); | ||
const workerdMainPath = miniflareRequire.resolve("workerd"); | ||
const workerdPackageJsonPath = findClosestPackageJson(workerdMainPath); | ||
assert(workerdPackageJsonPath !== undefined); | ||
const workerdPackageJson = await fs.readFile(workerdPackageJsonPath, "utf8"); | ||
const workerdPackage = JSON.parse(workerdPackageJson); | ||
const workerdVersion = workerdPackage.version; | ||
|
||
// 4. Write basic markdown report | ||
const report = [ | ||
`\`wrangler@${wranglerVersion}\` includes the following runtime dependencies:`, | ||
"", | ||
"|Package|Constraint|Resolved|", | ||
"|-------|----------|--------|", | ||
`|\`miniflare\`|${miniflareVersionConstraint}|${miniflareVersion}|`, | ||
`|\`workerd\`|${workerdVersionConstraint}|${workerdVersion}|`, | ||
"", | ||
"Please ensure constraints are pinned, and `miniflare`/`workerd` minor versions match.", | ||
"", | ||
].join("\n"); | ||
await fs.writeFile("runtime-versions.md", report); |
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,75 @@ | ||
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 | ||
--- | ||
${generateChangesetBody(changes)} | ||
` | ||
); | ||
|
||
execSync("git add .changeset"); | ||
execSync("git commit --amend -m '[C3] Update frameworks cli dependencies'"); | ||
execSync("git push -f"); | ||
} | ||
|
||
function generateChangesetBody(changes) { | ||
if (changes.length === 1) { | ||
const { package: pkg, from, to } = changes[0]; | ||
return `C3: Bumped \`${pkg}\` from \`${from}\` to \`${to}\``; | ||
} | ||
|
||
return `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")} | ||
} | ||
`; | ||
} |
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 }} |
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,45 @@ | ||
name: Playground Preview Worker | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
jobs: | ||
publish_worker: | ||
if: ${{ github.repository_owner == 'cloudflare' }} | ||
name: Publish Worker | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout Repo | ||
uses: actions/checkout@v3 | ||
with: | ||
fetch-depth: 0 | ||
|
||
- name: Use Node.js 16.13 | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: 16.13 | ||
cache: "npm" # cache ~/.npm in case 'npm ci' needs to run | ||
|
||
- name: Install workerd Dependencies | ||
if: ${{ runner.os == 'Linux' }} | ||
run: | | ||
export DEBIAN_FRONTEND=noninteractive | ||
sudo apt-get update | ||
sudo apt-get install -y libc++1 | ||
- name: Install NPM Dependencies | ||
run: npm ci | ||
|
||
- name: Build wrangler | ||
run: npm run build | ||
env: | ||
NODE_ENV: "production" | ||
|
||
- name: Build & Publish Worker | ||
run: npm run deploy | ||
env: | ||
NODE_ENV: "production" | ||
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }} | ||
working-directory: packages/playground-preview-worker |
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
Oops, something went wrong.