Skip to content

Commit

Permalink
Merge branch 'cloudflare:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
Laurry-gee authored Aug 30, 2023
2 parents 2c3e306 + a2f71e6 commit 7ed43f7
Show file tree
Hide file tree
Showing 185 changed files with 4,228 additions and 1,304 deletions.
5 changes: 0 additions & 5 deletions .changeset/warm-students-provide.md

This file was deleted.

35 changes: 35 additions & 0 deletions .github/actions/install-dependencies/action.yml
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
24 changes: 24 additions & 0 deletions .github/dependabot.yml
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"
68 changes: 68 additions & 0 deletions .github/extract-runtime-versions.mjs
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);
75 changes: 75 additions & 0 deletions .github/generate-c3-dependabot-pr-changeset.mjs
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")}
}
`;
}
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 }}
9 changes: 9 additions & 0 deletions .github/workflows/create-pullrequest-prerelease.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,15 @@ jobs:
- name: Install NPM Dependencies
run: npm ci

- name: Extract runtime versions
run: node .github/extract-runtime-versions.mjs # extract versions before modifying version to include commit hash

- name: Upload runtime versions
uses: actions/upload-artifact@v3
with:
name: runtime-versions.md
path: runtime-versions.md

- name: Modify package.json version
run: node .github/version-script.js

Expand Down
45 changes: 45 additions & 0 deletions .github/workflows/playground-preview-worker.yml
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
7 changes: 7 additions & 0 deletions .github/workflows/pullrequests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,13 @@ jobs:
env:
NODE_ENV: "production"

- name: Build & Publish Testing Playground Worker
run: npm run deploy:testing
env:
NODE_ENV: "production"
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
working-directory: packages/playground-preview-worker

- name: Run tests & collect coverage
run: npm run test:ci
env:
Expand Down
Loading

0 comments on commit 7ed43f7

Please sign in to comment.