Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/commands/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import Listr from "listr";
// Tasks
import { buildAndUpload } from "../tasks/buildAndUpload";
// Utils
import { getCurrentLocalVersion } from "../utils/versions/getCurrentLocalVersion";
import { getInstallDnpLink } from "../utils/getLinks";
import { CliGlobalOptions } from "../types";
import { UploadTo } from "../releaseUploader";
import { defaultComposeFileName, defaultDir } from "../params";
import { readManifest } from "../utils/manifest";

interface CliCommandOptions extends CliGlobalOptions {
provider: string;
Expand Down Expand Up @@ -91,7 +91,7 @@ export async function buildHandler({
const skipSave = skip_save;
const skipUpload = skip_save || skip_upload;
const composeFileName = compose_file_name;
const nextVersion = getCurrentLocalVersion({ dir });
const nextVersion = readManifest({ dir }).manifest.version;
const buildDir = path.join(dir, `build_${nextVersion}`);

const buildTasks = new Listr(
Expand Down
35 changes: 28 additions & 7 deletions src/commands/increase.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
import { CommandModule } from "yargs";
import { increaseFromLocalVersion } from "../utils/versions/increaseFromLocalVersion";
import { CliGlobalOptions, ReleaseType } from "../types";
import semver, { ReleaseType } from "semver";
import { CliGlobalOptions } from "../types";
import { defaultComposeFileName, defaultDir } from "../params";
import { readManifest, writeManifest } from "../utils/manifest";
import {
readCompose,
updateComposeImageTags,
writeCompose
} from "../utils/compose";

export const command = "increase [type]";

Expand Down Expand Up @@ -38,9 +44,24 @@ export async function increaseHandler({
dir = defaultDir,
compose_file_name = defaultComposeFileName
}: CliCommandOptions): Promise<string> {
return await increaseFromLocalVersion({
type: type as ReleaseType,
dir,
compose_file_name
});
const composeFileName = compose_file_name;

// Load manifest
const { manifest, format } = readManifest({ dir });

const currentVersion = manifest.version;

// Increase the version
const nextVersion = semver.inc(currentVersion, type as ReleaseType);
if (!nextVersion) throw Error(`Invalid increase: ${currentVersion} ${type}`);
manifest.version = nextVersion;

// Mofidy and write the manifest and docker-compose
writeManifest(manifest, format, { dir });
const { name, version } = manifest;
const compose = readCompose({ dir, composeFileName });
const newCompose = updateComposeImageTags(compose, { name, version });
writeCompose(newCompose, { dir, composeFileName });

return nextVersion;
}
25 changes: 16 additions & 9 deletions src/commands/next.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { CommandModule } from "yargs";
import { getNextVersionFromApm } from "../utils/versions/getNextVersionFromApm";
import { verifyEthConnection } from "../utils/verifyEthConnection";
import semver from "semver";
import { CliGlobalOptions, ReleaseType } from "../types";
import { defaultDir } from "../params";
import { getPM, verifyEthConnection } from "../providers/pm";
import { readManifest } from "../utils/manifest";

interface CliCommandOptions extends CliGlobalOptions {
type: string;
Expand All @@ -11,7 +12,7 @@ interface CliCommandOptions extends CliGlobalOptions {

export const next: CommandModule<CliGlobalOptions, CliCommandOptions> = {
command: "next [type]",
describe: "Compute the next release version from local",
describe: "Compute the next release version from published repo",

builder: yargs =>
yargs
Expand Down Expand Up @@ -45,12 +46,18 @@ export async function nextHandler({
}: CliCommandOptions): Promise<string> {
const ethProvider = provider;

await verifyEthConnection(ethProvider);
const pm = getPM(ethProvider);
await verifyEthConnection(pm);

const { manifest } = readManifest({ dir });
const latestVersion = await pm.getLatestVersion(manifest.name);

const nextVersion = semver.inc(latestVersion, type as ReleaseType);
if (!nextVersion)
throw Error(
`Error computing next version, is this increase type correct? type: ${type}`
);

// Execute command
return await getNextVersionFromApm({
type: type as ReleaseType,
ethProvider,
dir
});
return nextVersion;
}
51 changes: 27 additions & 24 deletions src/commands/publish.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,13 @@ import { buildAndUpload } from "../tasks/buildAndUpload";
import { generatePublishTx } from "../tasks/generatePublishTx";
import { createGithubRelease } from "../tasks/createGithubRelease";
// Utils
import { getCurrentLocalVersion } from "../utils/versions/getCurrentLocalVersion";
import { increaseFromApmVersion } from "../utils/versions/increaseFromApmVersion";
import { verifyEthConnection } from "../utils/verifyEthConnection";
import { getInstallDnpLink, getPublishTxLink } from "../utils/getLinks";
import { increaseFromRemoteVersion } from "../utils/increaseFromRemoteVersion";
import { getInstallDnpLink } from "../utils/getLinks";
import { defaultComposeFileName, defaultDir, YargsError } from "../params";
import { CliGlobalOptions, ReleaseType, releaseTypes, TxData } from "../types";
import { printObject } from "../utils/print";
import { UploadTo } from "../releaseUploader";
import { getPM, verifyEthConnection } from "../providers/pm";

const typesList = releaseTypes.join(" | ");

Expand Down Expand Up @@ -88,9 +87,12 @@ export const publish: CommandModule<CliGlobalOptions, CliCommandOptions> = {
}),

handler: async args => {
const { txData, nextVersion, releaseMultiHash } = await publishHanlder(
args
);
const {
txData,
nextVersion,
releaseMultiHash,
txPublishLink
} = await publishHanlder(args);

if (!args.silent) {
const txDataToPrint = {
Expand All @@ -113,7 +115,7 @@ export const publish: CommandModule<CliGlobalOptions, CliCommandOptions> = {

${"You can also execute this transaction with Metamask by following this pre-filled link"}

${chalk.cyan(getPublishTxLink(txData))}
${chalk.cyan(txPublishLink)}
`);
}
}
Expand Down Expand Up @@ -143,6 +145,7 @@ export async function publishHanlder({
txData: TxData;
nextVersion: string;
releaseMultiHash: string;
txPublishLink: string;
}> {
// Parse optionsalias: "release",
let ethProvider = provider || eth_provider;
Expand Down Expand Up @@ -195,27 +198,22 @@ export async function publishHanlder({
`Invalid release type "${type}", must be: ${typesList}`
);

await verifyEthConnection(ethProvider);
const pm = getPM(ethProvider);
await verifyEthConnection(pm);

const publishTasks = new Listr(
[
// 1. Fetch current version from APM
{
title: "Fetch current version from APM",
task: async (ctx, task) => {
let nextVersion;
try {
nextVersion = await increaseFromApmVersion({
type: type as ReleaseType,
ethProvider,
dir,
composeFileName
});
} catch (e) {
if (e.message.includes("NOREPO"))
nextVersion = getCurrentLocalVersion({ dir });
else throw e;
}
const nextVersion = await increaseFromRemoteVersion({
type: type as ReleaseType,
pm,
dir,
composeFileName
});

ctx.nextVersion = nextVersion;
ctx.buildDir = path.join(dir, `build_${nextVersion}`);
task.title = task.title + ` (next version: ${nextVersion})`;
Expand Down Expand Up @@ -276,6 +274,11 @@ export async function publishHanlder({
);

const tasksFinalCtx = await publishTasks.run();
const { txData, nextVersion, releaseMultiHash } = tasksFinalCtx;
return { txData, nextVersion, releaseMultiHash };
const {
txData,
nextVersion,
releaseMultiHash,
txPublishLink
} = tasksFinalCtx;
return { txData, nextVersion, releaseMultiHash, txPublishLink };
}
File renamed without changes.
Loading