Skip to content

Commit

Permalink
ci: publish beta releases of create-cloudflare to npm (#3458)
Browse files Browse the repository at this point in the history
* ci: publish beta releases of create-cloudflare to npm

* Add repository_dispatch event
  • Loading branch information
petebacondarwin authored Jun 14, 2023
1 parent 5cfb94c commit 03133ee
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 16 deletions.
45 changes: 29 additions & 16 deletions .github/version-script.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,35 @@
const fs = require("fs");
const { exec } = require("child_process");
/**
* Update the package.json version property for the given package
*
* Usage:
*
* ```
* node ./.github/version-script.js <package-name>
* ```
*
* `<package-name>` defaults to `wrangler` if not provided.
*/

const { readFileSync, writeFileSync } = require("fs");
const { execSync } = require("child_process");

try {
const package = JSON.parse(
fs.readFileSync("./packages/wrangler/package.json")
);
exec("git rev-parse --short HEAD", (err, stdout) => {
if (err) {
console.log(err);
process.exit(1);
}
package.version = "0.0.0-" + stdout.trim();
fs.writeFileSync(
"./packages/wrangler/package.json",
JSON.stringify(package, null, "\t") + "\n"
);
});
const packageName = getArgs()[0] ?? "wrangler";
const packageJsonPath = `./packages/${packageName}/package.json`;
const package = JSON.parse(readFileSync(packageJsonPath));
const stdout = execSync("git rev-parse --short HEAD", { encoding: "utf8" });
package.version = "0.0.0-" + stdout.trim();
writeFileSync(packageJsonPath, JSON.stringify(package, null, "\t") + "\n");
} catch (error) {
console.error(error);
process.exit(1);
}

/**
* Get the command line args, stripping `node` and script filename, etc.
*/
function getArgs() {
const args = Array.from(process.argv);
while (args.shift() !== module.filename) {}
return args;
}
49 changes: 49 additions & 0 deletions .github/workflows/prerelease-create-cloudflare.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name: Prerelease create-cloudflare

on:
repository_dispatch:
types: [pre-release-create-cloudflare]
push:
branches:
- main

jobs:
prerelease:
if: ${{ github.repository_owner == 'cloudflare' }}
name: Build & Publish a beta release of create-cloudflare to NPM
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: Modify package.json version
run: node .github/version-script.js create-cloudflare

- name: Build packages
run: npm run build
env:
NODE_ENV: "production"

- name: Publish Beta to NPM
run: npm publish -w create-cloudflare --tag beta
env:
NPM_PUBLISH_TOKEN: ${{ secrets.NPM_PUBLISH_TOKEN }}

0 comments on commit 03133ee

Please sign in to comment.