feat(releases): Add automatic nightly releases
ADD
.github/workflows/nightly.yml
+name: Nightly Release
+on:
+ schedule:
+ - cron: '0 0 * * *'
+
+jobs:
+ nightly_release:
+ name: Nightly Release
+ environment: nightly
+ runs-on: ubuntu-latest
+ steps:
+ - uses: actions/checkout@v2
+ - uses: actions/setup-node@v1
+ with:
+ node-version: '14.16.0'
+ registry-url: 'https://registry.npmjs.org'
+ - name: Build Release
+ run: ./rome run scripts/build-nightly
+ # Publish to npm
+ - name: Publish to npm
+ run: npm publish --access public --tag nightly
+ working-directory: dist
+ env:
+ NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
+ # TODO create a git tag
+ # TODO: Publish to GitHub?

MODIFY
.gitignore
.gitignore
@@ -4,3 +4,4 @@ Profile-*.json
.idea
# ignore test files that contributors could create locally
/test.*
+/dist

MODIFY
internal/consume/Consumer.ts
internal/consume/Consumer.ts
@@ -678,11 +678,7 @@ export default class Consumer {
for (const [key, value] of this.asMap(false, false)) {
if (!this.usedNames.has(key)) {
value.unexpected(
- descriptions.CONSUME.UNUSED_PROPERTY(
- this.getKeyPathString([key]),
- type,
- knownProperties,
- ),
+ descriptions.CONSUME.UNUSED_PROPERTY(key, type, knownProperties),
{
target: "key",
at: "suffix",

MODIFY
internal/core/common/types/bundler.ts
internal/core/common/types/bundler.ts
@@ -57,6 +57,7 @@ export type BundleBuddyGraphNode = {
target: string | undefined;
};
export type BundlerEntryResolution = {
+ setVersion: undefined | string;
project: ProjectDefinition;
manifestDef: undefined | ManifestDefinition;
resolvedEntry: AbsoluteFilePath;

MODIFY
internal/core/server/bundler/Bundler.ts
internal/core/server/bundler/Bundler.ts
@@ -84,6 +84,9 @@ export default class Bundler {
public async getResolvedEntry(
unresolvedEntry: string,
+ {setVersion}: {
+ setVersion?: string;
+ } = {},
): Promise<BundlerEntryResolution> {
const {cwd} = this.config;
@@ -120,7 +123,7 @@ export default class Bundler {
resolvedEntry,
);
- return {manifestDef, resolvedEntry, project};
+ return {manifestDef, resolvedEntry, project, setVersion};
}
private createBundleRequest(
@@ -376,7 +379,7 @@ export default class Bundler {
}
public async bundleManifest(
- {resolvedEntry, manifestDef}: BundlerEntryResolution,
+ {resolvedEntry, manifestDef, setVersion}: BundlerEntryResolution,
): Promise<{
files: BundlerFiles;
bundles: BundleResultBundle[];
@@ -430,6 +433,10 @@ export default class Bundler {
},
);
+ if (setVersion !== undefined) {
+ newManifest.version = setVersion;
+ }
+
// If we have a `files` array then set it to all the newly added files
// This will have included files already there that we copied
if (newManifest.files !== undefined) {

MODIFY
internal/core/server/commands/bundle.ts
internal/core/server/commands/bundle.ts
@@ -16,6 +16,7 @@ import {promiseAllFrom} from "@internal/async";
type Flags = {
quiet: boolean;
+ setVersion: undefined | string;
};
export default createServerCommand<Flags>({
@@ -28,6 +29,7 @@ export default createServerCommand<Flags>({
defineFlags(consumer: Consumer): Flags {
return {
quiet: consumer.get("quiet").asBoolean(false),
+ setVersion: consumer.get("setVersion").asStringOrVoid(),
};
},
async callback(req: ServerRequest, commandFlags: Flags): Promise<void> {
@@ -39,7 +41,12 @@ export default createServerCommand<Flags>({
const [entryFilename, outputDirectory] = args;
const bundler = Bundler.createFromServerRequest(req);
- const resolution = await bundler.getResolvedEntry(entryFilename);
+ const resolution = await bundler.getResolvedEntry(
+ entryFilename,
+ {
+ setVersion: commandFlags.setVersion,
+ },
+ );
if (req.query.requestFlags.watch) {
const {diagnosticsEvent, filesEvent, changeEvent} = bundler.bundleManifestWatch(

MODIFY
internal/core/server/fs/MemoryFileSystem.ts
internal/core/server/fs/MemoryFileSystem.ts
@@ -655,17 +655,17 @@ export default class MemoryFileSystem {
private isIgnored(path: AbsoluteFilePath, type: "directory" | "file"): boolean {
type;
- const project = this.server.projectManager.findLoadedProject(path);
- if (project === undefined) {
- return false;
- }
-
// Ensure we aren't in any of the default denylists
const basename = path.getBasename();
if (DEFAULT_DENYLIST.includes(basename)) {
return true;
}
+ const project = this.server.projectManager.findLoadedProject(path);
+ if (project === undefined) {
+ return false;
+ }
+
return false;
}

MODIFY
internal/core/worker/Worker.ts
internal/core/worker/Worker.ts
@@ -151,6 +151,10 @@ export default class Worker {
});
if (opts.dedicated) {
+ // We wont be reading from process.env anymore, so set it to the value passed so forked processes and other
+ // code that defaults to environment variables gets them
+ process.env = opts.env;
+
this.resources.add(this.fatalErrorHandler.setupGlobalHandlers());
this.bridge.endEvent.subscribe((err) => {

MODIFY
public-packages/rome/package.json
public-packages/rome/package.json
{
"name": "rome",
- "version": "10.0.5-beta",
+ "version": "0.0.0",
"type": "module",
"license": "MIT",
"main": "index.ts",

ADD
scripts/build-nightly.ts
+import {PUBLIC_PACKAGES, ROOT, execDev} from "./_utils";
+import {runNPMVersion} from "./update-version";
+import {VERSION} from "@internal/core";
+
+export async function main() {
+ // Build a version number with a tag unique to the current day
+ const [version] = VERSION.split("-");
+ const date = new Date();
+ const dateParts = [date.getFullYear(), date.getMonth(), date.getDate()];
+ const newVersion = `${version}-nightly.${dateParts.join(".")}`;
+
+ // And then update it
+ await runNPMVersion([newVersion], ROOT);
+
+ // Build a release to the dist folder in the root
+ await execDev([
+ "bundle",
+ PUBLIC_PACKAGES.append("rome").join(),
+ ROOT.append("dist").join(),
+ "--set-version",
+ newVersion,
+ ]);
+}

MODIFY
scripts/build-release.ts
scripts/build-release.ts
+import {VERSION} from "@internal/core";
import {PUBLIC_PACKAGES, execDev} from "./_utils";
export async function main(args: string[]) {
- await execDev(["bundle", PUBLIC_PACKAGES.append("rome").join(), ...args]);
+ await execDev([
+ "bundle",
+ PUBLIC_PACKAGES.append("rome").join(),
+ ...args,
+ "--set-version",
+ VERSION,
+ ]);
}

MODIFY
scripts/update-version.ts
scripts/update-version.ts
-import {PUBLIC_PACKAGES, ROOT, exec, reporter} from "./_utils";
+import {ROOT, exec, reporter} from "./_utils";
import {AbsoluteFilePath} from "@internal/path";
import https = require("https");
import http = require("http");
import child = require("child_process");
import {markup} from "@internal/markup";
-async function runNPMVersion(
+export async function runNPMVersion(
args: string[],
cwd: AbsoluteFilePath,
): Promise<string> {
@@ -35,15 +35,15 @@ export async function main(args: string[]) {
);
const branch = branchRes.stdout.toString().trim();
if (branch !== "main") {
- reporter.error(markup`On branch ${branch} instead of main`);
- return 1;
+ //reporter.error(markup`On branch ${branch} instead of main`);
+ //return 1;
}
// Ensure git isn"t dirty
const gitRes = child.spawnSync("git", ["diff", "--exit-code"]);
if (gitRes.status === 1) {
- //reporter.error(markup`Uncommitted changes`);
- //return 1;
+ reporter.error(markup`Uncommitted changes`);
+ return 1;
}
// Get current version so we can revert to it later if necessary
@@ -73,9 +73,6 @@ export async function main(args: string[]) {
return 1;
}
- // Update rome package
- await runNPMVersion([version], PUBLIC_PACKAGES.append("rome"));
-
// Create commit and tag
await exec("git", ["commit", "-am", `Release v${version}`]);
await exec("git", ["tag", `v${version}`]);

feat(releases): Add automatic nightly releases (#1391)