-
Notifications
You must be signed in to change notification settings - Fork 688
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ci: publish beta releases of create-cloudflare to npm (#3458)
* ci: publish beta releases of create-cloudflare to npm * Add repository_dispatch event
- Loading branch information
1 parent
5cfb94c
commit 03133ee
Showing
2 changed files
with
78 additions
and
16 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
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; | ||
} |
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,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 }} |