Skip to content

Commit

Permalink
Check available ETH provider on first attempt
Browse files Browse the repository at this point in the history
  • Loading branch information
dappnodedev committed Mar 19, 2024
1 parent 9b517ee commit f322199
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 18 deletions.
20 changes: 6 additions & 14 deletions src/commands/githubActions/bumpUpstream/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import {
writeCompose
} from "../../../files/index.js";
import { getNextVersionFromApm } from "../../../utils/versions/getNextVersionFromApm.js";
import { getFirstAvailableEthProvider } from "../../../utils/tryEthProviders.js";
import { Compose } from "@dappnode/types";
import { isEmpty } from "lodash-es";
import { UpstreamSettings, UpstreamRepoMap, VersionsToUpdate } from "./types.js";
Expand Down Expand Up @@ -58,9 +57,9 @@ async function gaBumpUpstreamHandler({
use_fallback: useFallback,
}: CliCommandOptions): Promise<void> {

const { upstreamSettings, manifestData: { manifest, format }, compose, gitSettings, ethProviders } = await readInitialSetup({ dir, userEthProvider, useFallback });
const { upstreamSettings, manifestData: { manifest, format }, compose, gitSettings, ethProvider } = await readInitialSetup({ dir, userEthProvider, useFallback });

printSettings(upstreamSettings, gitSettings, manifest, compose, ethProviders);
printSettings(upstreamSettings, gitSettings, manifest, compose, ethProvider);

const upstreamRepoVersions = await getUpstreamRepoVersions(upstreamSettings);

Expand All @@ -85,14 +84,7 @@ async function gaBumpUpstreamHandler({

manifest.upstreamVersion = getUpstreamVersionTag(versionsToUpdate);

const ethProviderAvailable = await getFirstAvailableEthProvider({
providers: ethProviders
});

if (!ethProviderAvailable)
throw Error(`No eth provider available. Tried: ${ethProviders.join(", ")}`);

manifest.version = await getNewManifestVersion({ dir, ethProviderAvailable });
manifest.version = await getNewManifestVersion({ dir, ethProvider });

writeManifest(manifest, format, { dir });
writeCompose(compose, { dir });
Expand Down Expand Up @@ -209,16 +201,16 @@ function getVersionsToUpdate(compose: Compose, upstreamRepoVersions: UpstreamRep
}

async function getNewManifestVersion({
ethProviderAvailable,
ethProvider,
dir
}: {
ethProviderAvailable: string;
ethProvider: string;
dir: string;
}): Promise<string> {
try {
return await getNextVersionFromApm({
type: "patch",
ethProvider: ethProviderAvailable,
ethProvider,
dir
});
} catch (e) {
Expand Down
14 changes: 11 additions & 3 deletions src/commands/githubActions/bumpUpstream/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { arrIsUnique } from "../../../utils/array";
import { parseCsv } from "../../../utils/csv";
import { readBuildSdkEnvFileNotThrow } from "../../../utils/readBuildSdkEnv";
import { GitSettings, InitialSetupData, UpstreamSettings } from "./types";
import { getFirstAvailableEthProvider } from "../../../utils/tryEthProviders";

export async function readInitialSetup({ dir, userEthProvider, useFallback }: { dir: string, userEthProvider: string, useFallback: boolean }): Promise<InitialSetupData> {
const envFileArgs = readBuildSdkEnvFileNotThrow(dir);
Expand All @@ -29,12 +30,19 @@ export async function readInitialSetup({ dir, userEthProvider, useFallback }: {

const ethProviders = getEthProviders(useFallback, userEthProvider);

const ethProviderAvailable = await getFirstAvailableEthProvider({
providers: ethProviders
});

if (!ethProviderAvailable)
throw Error(`No eth provider available. Tried: ${ethProviders.join(", ")}`);

return {
upstreamSettings,
manifestData: { manifest, format },
compose,
gitSettings,
ethProviders,
ethProvider: ethProviderAvailable,
};
}

Expand Down Expand Up @@ -73,7 +81,7 @@ export function validateUpstreamData(upstreamRepos: string[], upstreamArgs: stri
}


export function printSettings(upstreamSettings: UpstreamSettings[], gitSettings: GitSettings, manifest: Manifest, compose: Compose, ethProviders: string[]): void {
export function printSettings(upstreamSettings: UpstreamSettings[], gitSettings: GitSettings, manifest: Manifest, compose: Compose, ethProvider: string): void {

console.log(`
Expand All @@ -85,7 +93,7 @@ export function printSettings(upstreamSettings: UpstreamSettings[], gitSettings:
Compose - ${JSON.stringify(compose, null, 2)}
ETH Providers - ${JSON.stringify(ethProviders, null, 2)}
ETH Provider - ${ethProvider}
`);
}
2 changes: 1 addition & 1 deletion src/commands/githubActions/bumpUpstream/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export interface InitialSetupData {
};
compose: Compose;
gitSettings: GitSettings;
ethProviders: string[];
ethProvider: string;
}

export type UpstreamRepo = {
Expand Down

0 comments on commit f322199

Please sign in to comment.