Skip to content
Closed
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
13 changes: 8 additions & 5 deletions src/commands/build.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import path from "path";
import chalk from "chalk";
import { CommandModule } from "yargs";
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";
Expand All @@ -14,6 +12,7 @@ import { defaultComposeFileName, defaultDir } from "../params";
interface CliCommandOptions extends CliGlobalOptions {
provider: string;
upload_to: UploadTo;
build_dir: string;
timeout?: string;
skip_save?: boolean;
skip_upload?: boolean;
Expand All @@ -37,6 +36,11 @@ export const build: CommandModule<CliGlobalOptions, CliCommandOptions> = {
choices: ["ipfs", "swarm"] as UploadTo[],
default: "ipfs" as UploadTo
},
build_dir: {
description: "Target directory to write build files",
default: "./build",
normalize: true
},
timeout: {
alias: "t",
description: `Overrides default build timeout: "15h", "20min 15s", "5000". Specs npmjs.com/package/timestring`,
Expand Down Expand Up @@ -74,6 +78,7 @@ export async function buildHandler({
provider,
timeout,
upload_to,
build_dir,
skip_save,
skip_upload,
require_git_data,
Expand All @@ -91,13 +96,11 @@ export async function buildHandler({
const skipSave = skip_save;
const skipUpload = skip_save || skip_upload;
const composeFileName = compose_file_name;
const nextVersion = getCurrentLocalVersion({ dir });
const buildDir = path.join(dir, `build_${nextVersion}`);

const buildTasks = new Listr(
buildAndUpload({
dir,
buildDir,
buildDir: build_dir,
contentProvider,
uploadTo,
userTimeout,
Expand Down
2 changes: 2 additions & 0 deletions src/commands/githubActions/build/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ export async function gaBuildHandler({
await buildHandler({
provider: "dappnode",
upload_to: "ipfs",
build_dir: "build",
skip_save: true,
verbose: true
});
Expand All @@ -99,6 +100,7 @@ export async function buildAndComment({
const { releaseMultiHash } = await buildHandler({
provider: "pinata",
upload_to: "ipfs",
build_dir: "build",
require_git_data: true,
delete_old_pins: true,
verbose: true
Expand Down
46 changes: 0 additions & 46 deletions src/commands/increase.ts

This file was deleted.

62 changes: 62 additions & 0 deletions src/commands/list.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import { CommandModule } from "yargs";
import { CliGlobalOptions } from "../types";
import { defaultDir } from "../params";
import { readManifest } from "../utils/manifest";
import { getPM } from "../providers/pm";

interface CliCommandOptions extends CliGlobalOptions {
provider: string;
tag?: string;
}

export const list: CommandModule<CliGlobalOptions, CliCommandOptions> = {
command: "list [tag]",
describe: "List package version tags",

builder: yargs =>
yargs
.positional("tag", {
description: "tag to print version of",
type: "string"
})
.option("provider", {
description: `Specify an eth provider: "dappnode" (default), "infura", "localhost:8545"`,
default: "dappnode",
type: "string"
}),

handler: async (args): Promise<void> => {
const tagsWithVersions = await listHandler(args);

if (args.tag) {
// Output result: "0.1.8"
const version = tagsWithVersions[args.tag];
if (!version) {
throw Error(`Tag ${args.tag} not found`);
} else {
console.log(version);
}
} else {
for (const [tag, version] of Object.entries(tagsWithVersions)) {
// Output result: "latest: 0.1.8"
console.log(`${tag}: ${version}`);
}
}
}
};

/**
* Common handler for CLI and programatic usage
*/
export async function listHandler({
provider,
dir = defaultDir
}: CliCommandOptions): Promise<Record<string, string>> {
const { manifest } = readManifest({ dir });

const pm = getPM(provider);

return {
latest: await pm.getLatestVersion(manifest.name)
};
}
56 changes: 0 additions & 56 deletions src/commands/next.ts

This file was deleted.

59 changes: 21 additions & 38 deletions src/commands/publish.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import path from "path";
import Listr from "listr";
import chalk from "chalk";
import { CommandModule } from "yargs";
Expand All @@ -7,14 +6,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 { 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 { readManifest } from "../utils/manifest";

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

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

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

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

console.log(`
${chalk.green(`DNP (DAppNode Package) published (version ${nextVersion})`)}
${chalk.green(`DNP (DAppNode Package) published (version ${version})`)}
Release hash : ${releaseMultiHash}
${getInstallDnpLink(releaseMultiHash)}

Expand All @@ -113,7 +114,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 All @@ -140,8 +141,9 @@ export async function publishHanlder({
silent,
verbose
}: CliCommandOptions): Promise<{
version: string;
txData: TxData;
nextVersion: string;
txPublishLink: string;
releaseMultiHash: string;
}> {
// Parse optionsalias: "release",
Expand All @@ -159,6 +161,10 @@ export async function publishHanlder({
const tag = process.env.TRAVIS_TAG || process.env.GITHUB_REF;
const typeFromEnv = process.env.RELEASE_TYPE;

// Target version to build
const { manifest } = readManifest({ dir });
const version = manifest.version;

/**
* Specific set of options used for internal DAppNode releases.
* Caution: options may change without notice.
Expand Down Expand Up @@ -199,30 +205,7 @@ export async function publishHanlder({

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;
}
ctx.nextVersion = nextVersion;
ctx.buildDir = path.join(dir, `build_${nextVersion}`);
task.title = task.title + ` (next version: ${nextVersion})`;
}
},

// 2. Build and upload
// Build and upload
{
title: "Build and upload",
task: ctx =>
Expand All @@ -241,7 +224,7 @@ export async function publishHanlder({
)
},

// 3. Generate transaction
// Generate transaction
{
title: "Generate transaction",
task: ctx =>
Expand All @@ -256,7 +239,7 @@ export async function publishHanlder({
})
},

// 4. Create github release
// Create github release
// [ONLY] add the Release task if requested
{
title: "Release on github",
Expand All @@ -276,6 +259,6 @@ export async function publishHanlder({
);

const tasksFinalCtx = await publishTasks.run();
const { txData, nextVersion, releaseMultiHash } = tasksFinalCtx;
return { txData, nextVersion, releaseMultiHash };
const { releaseMultiHash, txData, txPublishLink } = tasksFinalCtx;
return { version, releaseMultiHash, txData, txPublishLink };
}
Loading