diff --git a/package.json b/package.json index 25f12146..c2b16569 100644 --- a/package.json +++ b/package.json @@ -36,9 +36,9 @@ }, "homepage": "https://github.com/dappnode/DAppNodeSDK#readme", "dependencies": { - "@dappnode/schemas": "^0.1.18", + "@dappnode/schemas": "^0.1.19", "@dappnode/toolkit": "^0.1.21", - "@dappnode/types": "^0.1.37", + "@dappnode/types": "^0.1.39", "@octokit/rest": "^18.0.12", "async-retry": "^1.2.3", "chalk": "^2.4.2", diff --git a/src/commands/githubActions/bumpUpstream/github/fetchGithubUpstreamVersion.ts b/src/commands/githubActions/bumpUpstream/github/fetchGithubUpstreamVersion.ts new file mode 100644 index 00000000..4abb6c16 --- /dev/null +++ b/src/commands/githubActions/bumpUpstream/github/fetchGithubUpstreamVersion.ts @@ -0,0 +1,32 @@ +import { Github } from "../../../../providers/github/Github.js"; +import { isValidRelease } from "./isValidRelease.js"; + +export async function fetchGithubUpstreamVersion(repo: string): Promise { + + try { + + const newVersion = await fetchGithubLatestTag(repo); + if (!isValidRelease(newVersion)) { + console.log(`This is not a valid release (probably a release candidate) - ${repo}: ${newVersion}`); + return null; + } + + console.log(`Fetch latest version(s) - ${repo}: ${newVersion}`); + return newVersion; + } catch (e) { + console.error("Error fetching upstream repo versions:", e); + throw e; + } +} + +async function fetchGithubLatestTag(repo: string): Promise { + const [owner, repoName] = repo.split("/"); + const githubRepo = new Github({ owner, repo: repoName }); + + const releases = await githubRepo.listReleases(); + const latestRelease = releases[0]; + if (!latestRelease) throw Error(`No release found for ${repo}`); + + return latestRelease.tag_name; + +} \ No newline at end of file diff --git a/src/commands/githubActions/bumpUpstream/github/getBumpPrBody.ts b/src/commands/githubActions/bumpUpstream/github/getBumpPrBody.ts index c78bca4f..3565f096 100644 --- a/src/commands/githubActions/bumpUpstream/github/getBumpPrBody.ts +++ b/src/commands/githubActions/bumpUpstream/github/getBumpPrBody.ts @@ -1,17 +1,15 @@ -import { ComposeVersionsToUpdate } from "../types.js"; +import { UpstreamSettings } from "../types.js"; -export function getBumpPrBody(versionsToUpdate: ComposeVersionsToUpdate): string { +export function getBumpPrBody(upstreamSettings: UpstreamSettings[]): string { return [ "Bumps upstream version", - Object.entries(versionsToUpdate) - .map(([repoSlug, { newVersion, currentVersion }]) => - `- [${repoSlug}](${getGitHubUrl({ repoSlug })}) from ${currentVersion} to [${newVersion}](${getGitHubUrl({ repoSlug, tag: newVersion })})` - ) - .join("\n") + upstreamSettings.flatMap(({ repo, githubVersion, manifestVersion }) => + `- [${repo}](${getGitHubUrl({ repo })}) from ${manifestVersion} to [${githubVersion}](${getGitHubUrl({ repo, tag: githubVersion })})` + ).join("\n") ].join("\n\n"); } -function getGitHubUrl({ repoSlug, tag = "" }: { repoSlug: string, tag?: string }): string { - const baseUrl = `https://github.com/${repoSlug}`; +function getGitHubUrl({ repo, tag = "" }: { repo: string, tag?: string }): string { + const baseUrl = `https://github.com/${repo}`; return tag ? `${baseUrl}/releases/tag/${tag}` : baseUrl; } \ No newline at end of file diff --git a/src/commands/githubActions/bumpUpstream/github/getGithubSettings.ts b/src/commands/githubActions/bumpUpstream/github/getGithubSettings.ts index 73d93ee7..0ca8e482 100644 --- a/src/commands/githubActions/bumpUpstream/github/getGithubSettings.ts +++ b/src/commands/githubActions/bumpUpstream/github/getGithubSettings.ts @@ -1,18 +1,18 @@ import { branchNameRoot } from "../../../../params.js"; import { Github } from "../../../../providers/github/Github.js"; -import { UpstreamRepoMap, GithubSettings, GitBranch } from "../types.js"; +import { GithubSettings, GitBranch, UpstreamSettings } from "../types.js"; -export async function getGithubSettings(dir: string, upstreamVersions: UpstreamRepoMap): Promise { +export async function getGithubSettings(dir: string, upstreamSettings: UpstreamSettings[]): Promise { const thisRepo = Github.fromLocal(dir); const repoData = await thisRepo.getRepo(); - const branch = getBumpBranch(upstreamVersions); + const branch = getBumpBranch(upstreamSettings); return { repo: thisRepo, repoData, ...branch }; } -function getBumpBranch(upstreamVersions: UpstreamRepoMap): GitBranch { +function getBumpBranch(upstreamSettings: UpstreamSettings[]): GitBranch { const branchName = branchNameRoot + - Array.from(Object.values(upstreamVersions)) - .map(({ repo, newVersion }) => `${repo}@${newVersion}`) + Array.from(Object.values(upstreamSettings)) + .map(({ repo, githubVersion }) => `${repo}@${githubVersion}`) .join(","); const branchRef = `refs/heads/${branchName}`; diff --git a/src/commands/githubActions/bumpUpstream/github/getUpstreamVersionTag.ts b/src/commands/githubActions/bumpUpstream/github/getUpstreamVersionTag.ts deleted file mode 100644 index c198eff4..00000000 --- a/src/commands/githubActions/bumpUpstream/github/getUpstreamVersionTag.ts +++ /dev/null @@ -1,15 +0,0 @@ -import { ComposeVersionsToUpdate } from "../types.js"; - -// https://github.com/ipfs/go-ipfs/releases/tag/v0.7.0 -export function getUpstreamVersionTag(versionsToUpdate: ComposeVersionsToUpdate): string { - const entries = Object.entries(versionsToUpdate); - - if (entries.length === 1) { - const [{ newVersion }] = Object.values(versionsToUpdate); - return newVersion; - } else { - return entries - .map(([repoSlug, { newVersion }]) => `${repoSlug}@${newVersion}`) - .join(", "); - } -} \ No newline at end of file diff --git a/src/commands/githubActions/bumpUpstream/github/index.ts b/src/commands/githubActions/bumpUpstream/github/index.ts index ac0bfaec..58c03364 100644 --- a/src/commands/githubActions/bumpUpstream/github/index.ts +++ b/src/commands/githubActions/bumpUpstream/github/index.ts @@ -1,6 +1,5 @@ export * from "./closeOldPrs.js"; export * from "./getBumpPrBody.js"; export * from "./getGithubSettings.js"; -export * from "./getUpstreamVersionTag.js"; export * from "./isBranchNew.js"; export * from "./isValidRelease.js"; diff --git a/src/commands/githubActions/bumpUpstream/index.ts b/src/commands/githubActions/bumpUpstream/index.ts index 67c8ba39..36a31d6f 100644 --- a/src/commands/githubActions/bumpUpstream/index.ts +++ b/src/commands/githubActions/bumpUpstream/index.ts @@ -1,8 +1,6 @@ -import path from "path"; import { CommandModule } from "yargs"; import { CliGlobalOptions } from "../../../types.js"; import { defaultDir } from "../../../params.js"; -import { Github } from "../../../providers/github/Github.js"; import { shell } from "../../../utils/shell.js"; import { getGitHead } from "../../../utils/git.js"; import { buildAndComment } from "../build/index.js"; @@ -12,11 +10,10 @@ import { } from "../../../files/index.js"; import { getNextVersionFromApm } from "../../../utils/versions/getNextVersionFromApm.js"; import { Compose, Manifest } from "@dappnode/types"; -import { isEmpty } from "lodash-es"; -import { UpstreamSettings, UpstreamRepoMap, ComposeVersionsToUpdate, GitSettings, GithubSettings } from "./types.js"; +import { GitSettings, GithubSettings, UpstreamSettings } from "./types.js"; import { printSettings, getInitialSettings } from "./settings/index.js"; import { ManifestFormat } from "../../../files/manifest/types.js"; -import { closeOldPrs, getBumpPrBody, getGithubSettings, getUpstreamVersionTag, isBranchNew, isValidRelease } from "./github/index.js"; +import { closeOldPrs, getBumpPrBody, getGithubSettings, isBranchNew } from "./github/index.js"; interface CliCommandOptions extends CliGlobalOptions { eth_provider: string; @@ -57,16 +54,20 @@ async function gaBumpUpstreamHandler({ use_fallback: useFallback, }: CliCommandOptions): Promise { - const { upstreamSettings, manifestData: { manifest, format }, compose, gitSettings, ethProvider } = await getInitialSettings({ dir, userEthProvider, useFallback }); - printSettings(upstreamSettings, gitSettings, manifest, compose, ethProvider); + const { upstreamSettings, manifestData: { manifest, format: manifestFormat }, compose, gitSettings, ethProvider } = await getInitialSettings({ dir, userEthProvider, useFallback }); + if (!upstreamSettings) { + console.log("There are no upstream repos/versions defined in the manifest"); + return; + } - const upstreamRepoVersions = await getUpstreamRepoVersions(upstreamSettings); - if (!upstreamRepoVersions) { - console.log("There are no new versions to update"); + if (upstreamSettings.every(({ manifestVersion, githubVersion }) => manifestVersion === githubVersion)) { + console.log("All versions are up-to-date"); return; } - const githubSettings = await getGithubSettings(dir, upstreamRepoVersions); + printSettings(upstreamSettings, gitSettings, ethProvider); + + const githubSettings = await getGithubSettings(dir, upstreamSettings); const { branchName, repo } = githubSettings; if (!(await isBranchNew({ branchName, repo }))) { // We assume the PR was already opened @@ -74,18 +75,15 @@ async function gaBumpUpstreamHandler({ return; } - const composeVersionsToUpdate = updateComposeVersions(dir, compose, upstreamRepoVersions); - if (!composeVersionsToUpdate) { - console.log("All versions are up-to-date"); - return; - } + updateComposeUpstreamVersions(dir, compose, upstreamSettings); - await updateManifest({ manifest, manifestFormat: format, composeVersionsToUpdate, dir, ethProvider }); + const newManifest = updateManifestUpstreamVersion({ manifest, manifestFormat, upstreamSettings, dir }); + + await updateManifestPkgVersion({ manifest: newManifest, manifestFormat, dir, ethProvider }); await prepareAndCommitChanges({ - dir, gitSettings, - composeVersionsToUpdate, + upstreamSettings, githubSettings, }); @@ -99,39 +97,6 @@ async function gaBumpUpstreamHandler({ await buildAndComment({ dir, commitSha: gitHead.commit, branch: branchName }); } -async function getUpstreamRepoVersions(upstreamSettings: UpstreamSettings[]): Promise { - - const upstreamRepoVersions: UpstreamRepoMap = {}; - - try { - for (const { arg: upstreamArg, repo: upstreamRepo } of upstreamSettings) { - - const [owner, repo] = upstreamRepo.split("/"); - const githubRepo = new Github({ owner, repo }); - - const releases = await githubRepo.listReleases(); - const latestRelease = releases[0]; - if (!latestRelease) throw Error(`No release found for ${upstreamRepo}`); - - const newVersion = latestRelease.tag_name; - if (!isValidRelease(newVersion)) { - console.log(`This is not a valid release (probably a release candidate) - ${upstreamRepo}: ${newVersion}`); - continue; - } - - upstreamRepoVersions[upstreamArg] = { repo, repoSlug: upstreamRepo, newVersion }; - console.log(`Fetch latest version(s) - ${upstreamRepo}: ${newVersion}`); - } - } catch (e) { - console.error("Error fetching upstream repo versions:", e); - throw e; - } - - if (isEmpty(upstreamRepoVersions)) return null; - - return upstreamRepoVersions; -} - /** * Updates Docker Compose service build arguments with new versions based on `upstreamRepoVersions`. * Creates a deep copy of `compose`, modifies build arguments as needed, and writes the updated @@ -139,70 +104,90 @@ async function getUpstreamRepoVersions(upstreamSettings: UpstreamSettings[]): Pr * * @param {string} dir - Directory for the Compose file. * @param {Compose} compose - Original Docker Compose configuration. - * @param {UpstreamRepoMap} upstreamRepoVersions - Mapping of dependencies to their new versions. - * @return {ComposeVersionsToUpdate | null} - Details of updated versions or null. + * @param {UpstreamSettings[]} upstreamSettings - New versions for the Compose services. */ -function updateComposeVersions(dir: string, compose: Compose, upstreamRepoVersions: UpstreamRepoMap): ComposeVersionsToUpdate | null { - const newCompose = JSON.parse(JSON.stringify(compose)); // Deep copy - const versionsToUpdate: ComposeVersionsToUpdate = {}; +function updateComposeUpstreamVersions(dir: string, compose: Compose, upstreamSettings: UpstreamSettings[]): void { + const newCompose: Compose = JSON.parse(JSON.stringify(compose)); // Deep copy + + for (const upstreamItem of upstreamSettings) { + + for (const [, service] of Object.entries(newCompose.services)) + + // Checks if the service includes a build argument with the same name as the + // upstream item (e.g. "GETH_VERSION" is a build argument for the Geth service) + if (typeof service.build !== "string" && service.build?.args && upstreamItem.arg in service.build.args) - for (const [serviceName, service] of Object.entries(compose.services)) { + service.build.args[upstreamItem.arg] = upstreamItem.githubVersion; + } - if (typeof service.build !== "object" || !service.build.args) - continue; + writeCompose(newCompose, { dir }); +} - for (const [argName, currentVersion] of Object.entries(service.build.args)) { - const upstreamVersionInfo = upstreamRepoVersions[argName]; +/** + * Updates the manifest with new version tags based on the provided `composeVersionsToUpdate` + * and optionally fetches a new version for the manifest. The updated manifest is returned. + * @param {Object} options - The options for updating the manifest. + * @param {Manifest} options.manifest - The manifest object to update. + * @param {UpstreamSettings[]} options.upstreamSettings - The new versions for the manifest. + * @param {string} options.dir - Directory path where the manifest will be saved. + * @param {string} options.ethProvider - Ethereum provider URL. + * @returns {Promise} The updated manifest object. + */ +function updateManifestUpstreamVersion({ + manifest, + manifestFormat, + upstreamSettings, + dir, +}: { + manifest: Manifest; + manifestFormat: ManifestFormat; + upstreamSettings: UpstreamSettings[]; + dir: string; +}): Manifest { - if (!upstreamVersionInfo || currentVersion === upstreamVersionInfo.newVersion) - continue; + if (manifest.upstream) { + for (const upstreamItem of manifest.upstream) { - newCompose.services[serviceName].build.args[argName] = upstreamVersionInfo.newVersion; + const versionUpdate = upstreamSettings.find(({ repo }) => repo === upstreamItem.repo)?.githubVersion; - versionsToUpdate[upstreamVersionInfo.repoSlug] = { - newVersion: upstreamVersionInfo.newVersion, - currentVersion, - }; + if (versionUpdate) + upstreamItem.version = versionUpdate; } - } - if (isEmpty(versionsToUpdate)) { - return null; } else { - writeCompose(newCompose, { dir }); + // There should be only one upstream repo in the legacy format + manifest.upstreamVersion = upstreamSettings[0].githubVersion; } - return versionsToUpdate; + try { + writeManifest(manifest, manifestFormat, { dir }); + } catch (e) { + throw new Error(`Error writing manifest: ${e.message}`); + } + + return manifest; } -/** - * Updates the manifest with a new version and upstream version tag based on the - * provided `composeVersionsToUpdate`. It also writes the updated manifest to disk. - */ -async function updateManifest({ +async function updateManifestPkgVersion({ manifest, manifestFormat, - composeVersionsToUpdate, dir, ethProvider, }: { manifest: Manifest; manifestFormat: ManifestFormat; - composeVersionsToUpdate: ComposeVersionsToUpdate; dir: string; ethProvider: string; }): Promise { try { - manifest.upstreamVersion = getUpstreamVersionTag(composeVersionsToUpdate); - manifest.version = await getNewManifestVersion({ dir, ethProvider }); - writeManifest(manifest, manifestFormat, { dir }); + } catch (e) { - throw Error(`Error updating manifest: ${e.message}`); + // Not throwing an error here because updating the manifest version is not critical + console.error(`Could not fetch new manifest version: ${e}`); } - } async function getNewManifestVersion({ @@ -220,7 +205,7 @@ async function getNewManifestVersion({ }); } catch (e) { if (e.message.includes("NOREPO")) { - console.log("Package not found in APM (probably not published yet"); + console.log("Package not found in APM (probably not published yet)"); console.log("Manifest version set to default 0.1.0"); return "0.1.0"; } else { @@ -231,22 +216,18 @@ async function getNewManifestVersion({ } async function prepareAndCommitChanges({ - dir, gitSettings, - composeVersionsToUpdate, + upstreamSettings, githubSettings, }: { - dir: string; gitSettings: GitSettings; - composeVersionsToUpdate: ComposeVersionsToUpdate; + upstreamSettings: UpstreamSettings[]; githubSettings: GithubSettings; }) { const { branchName, branchRef } = githubSettings; - const commitMsg = createCommitMessage(composeVersionsToUpdate); + const commitMsg = createCommitMessage(upstreamSettings); console.log(`commitMsg: ${commitMsg}`); - console.log(await shell(`cat ${path.join(dir, "dappnode_package.json")}`)); - console.log(await shell(`cat ${path.join(dir, "docker-compose.yml")}`)); if (process.env.SKIP_COMMIT) { console.log("SKIP_COMMIT=true"); @@ -256,13 +237,11 @@ async function prepareAndCommitChanges({ await configureGitUser(gitSettings); await checkoutNewBranch(branchName); await commitAndPushChanges({ commitMsg, branchRef }); - await attemptToOpenPR({ commitMsg, composeVersionsToUpdate, githubSettings }); + await attemptToOpenPR({ commitMsg, upstreamSettings, githubSettings }); } -function createCommitMessage(composeVersionsToUpdate: ComposeVersionsToUpdate): string { - return `bump ${Object.entries(composeVersionsToUpdate) - .map(([repoSlug, { newVersion }]) => `${repoSlug} to ${newVersion}`) - .join(", ")}`; +function createCommitMessage(upstreamSettings: UpstreamSettings[]): string { + return `bump ${upstreamSettings.flatMap(({ repo, githubVersion }) => `${repo} to ${githubVersion}`).join(", ")}`; } async function configureGitUser({ userName, userEmail }: GitSettings) { @@ -281,11 +260,11 @@ async function commitAndPushChanges({ commitMsg, branchRef }: { commitMsg: strin async function attemptToOpenPR({ commitMsg, - composeVersionsToUpdate, + upstreamSettings, githubSettings: { repo, repoData, branchName } }: { commitMsg: string; - composeVersionsToUpdate: ComposeVersionsToUpdate; + upstreamSettings: UpstreamSettings[]; githubSettings: GithubSettings; }) { // Skip PR creation for testing @@ -295,6 +274,6 @@ async function attemptToOpenPR({ from: branchName, to: repoData.data.default_branch, title: commitMsg, - body: getBumpPrBody(composeVersionsToUpdate) + body: getBumpPrBody(upstreamSettings) }); } diff --git a/src/commands/githubActions/bumpUpstream/settings/getInitialSettings.ts b/src/commands/githubActions/bumpUpstream/settings/getInitialSettings.ts index 11f4a796..7325dba3 100644 --- a/src/commands/githubActions/bumpUpstream/settings/getInitialSettings.ts +++ b/src/commands/githubActions/bumpUpstream/settings/getInitialSettings.ts @@ -1,15 +1,15 @@ -import { Manifest } from "@dappnode/types"; +import { Manifest, UpstreamItem } from "@dappnode/types"; import { readManifest, readCompose } from "../../../../files/index.js"; import { arrIsUnique } from "../../../../utils/array.js"; -import { parseCsv } from "../../../../utils/csv.js"; import { getFirstAvailableEthProvider } from "../../../../utils/tryEthProviders.js"; import { InitialSetupData, GitSettings, UpstreamSettings } from "../types.js"; +import { fetchGithubUpstreamVersion } from "../github/fetchGithubUpstreamVersion.js"; export async function getInitialSettings({ dir, userEthProvider, useFallback }: { dir: string, userEthProvider: string, useFallback: boolean }): Promise { const { manifest, format } = readManifest({ dir }); const compose = readCompose({ dir }); - const upstreamSettings = parseUpstreamSettings(manifest); + const upstreamSettings = await parseUpstreamSettings(manifest); const gitSettings = getGitSettings(); @@ -35,33 +35,51 @@ export async function getInitialSettings({ dir, userEthProvider, useFallback }: * Supports both legacy 'upstreamRepo' and 'upstreamArg' fields and current 'upstream' * field (array of objects with 'repo', 'arg' and 'version' fields) */ -function parseUpstreamSettings(manifest: Manifest): UpstreamSettings[] { +async function parseUpstreamSettings(manifest: Manifest): Promise { const upstreamSettings = manifest.upstream - ? manifest.upstream - : parseUpstreamSettingsFromLegacy(manifest); + ? await parseUpstreamSettingsNewFormat(manifest.upstream) + : await parseUpstreamSettingsLegacyFormat(manifest); + + if (!upstreamSettings || upstreamSettings.length < 1) return null; validateUpstreamSettings(upstreamSettings); return upstreamSettings; } +async function parseUpstreamSettingsNewFormat(upstream: UpstreamItem[]): Promise { + const upstreamPromises = upstream.map(async ({ repo, arg, version }) => { + const githubVersion = await fetchGithubUpstreamVersion(repo); + + if (githubVersion) return { repo, arg, manifestVersion: version, githubVersion }; + }); + + const upstreamResults = await Promise.all(upstreamPromises); + return upstreamResults.filter((item) => item !== undefined) as UpstreamSettings[]; +} + /** * Legacy support for 'upstreamRepo' and 'upstreamArg' fields - * Currently, 'upstream' field is used instead, which is an array of objects with 'repo', 'arg' and 'version' fields + * Currently, 'upstream' field is used instead, which is an array of objects with 'repo', 'arg' and 'version' fields */ -function parseUpstreamSettingsFromLegacy(manifest: Manifest): UpstreamSettings[] { - const upstreamRepos = parseCsv(manifest.upstreamRepo); - const upstreamArgs = parseCsv(manifest.upstreamArg || "UPSTREAM_VERSION"); +async function parseUpstreamSettingsLegacyFormat(manifest: Manifest): Promise { + // 'upstreamRepo' and 'upstreamArg' being defined as arrays has been deprecated + + if (!manifest.upstreamRepo || manifest.upstreamRepo.trim() === "") + return null; - if (upstreamRepos.length !== upstreamArgs.length) - throw new Error(`'upstreamRepo' must have the same length as 'upstreamArgs'. Got ${upstreamRepos.length} repos and ${upstreamArgs.length} args.`); + const githubVersion = await fetchGithubUpstreamVersion(manifest.upstreamRepo); - return upstreamRepos.map((repo, i) => ({ - repo, - arg: upstreamArgs[i], - })); + if (!githubVersion) return null; + + return [{ + repo: manifest.upstreamRepo, + manifestVersion: manifest.upstreamVersion || "UPSTREAM_VERSION", + arg: manifest.upstreamArg || "UPSTREAM_VERSION", + githubVersion + }]; } function getEthProviders(useFallback: boolean, userEthProvider: string): string[] { @@ -85,9 +103,6 @@ function getGitSettings(): GitSettings { } function validateUpstreamSettings(upstreamSettings: UpstreamSettings[]): void { - if (upstreamSettings.length < 1) - throw new Error("Must provide at least one 'upstreamRepo'"); - if (!arrIsUnique(upstreamSettings.map(s => s.repo))) throw new Error("Upstream repositories must be unique"); diff --git a/src/commands/githubActions/bumpUpstream/settings/printSettings.ts b/src/commands/githubActions/bumpUpstream/settings/printSettings.ts index 54bfb6e7..fa6a2f7d 100644 --- a/src/commands/githubActions/bumpUpstream/settings/printSettings.ts +++ b/src/commands/githubActions/bumpUpstream/settings/printSettings.ts @@ -1,7 +1,6 @@ -import { Manifest, Compose } from "@dappnode/types"; import { UpstreamSettings, GitSettings } from "../types.js"; -export function printSettings(upstreamSettings: UpstreamSettings[], gitSettings: GitSettings, manifest: Manifest, compose: Compose, ethProvider: string): void { +export function printSettings(upstreamSettings: UpstreamSettings[], gitSettings: GitSettings, ethProvider: string): void { console.log(` @@ -9,10 +8,6 @@ export function printSettings(upstreamSettings: UpstreamSettings[], gitSettings: Git Settings - ${JSON.stringify(gitSettings, null, 2)} - Manifest - ${JSON.stringify(manifest, null, 2)} - - Compose - ${JSON.stringify(compose, null, 2)} - ETH Provider - ${ethProvider} `); diff --git a/src/commands/githubActions/bumpUpstream/types.ts b/src/commands/githubActions/bumpUpstream/types.ts index 995b7159..9a2ab4fe 100644 --- a/src/commands/githubActions/bumpUpstream/types.ts +++ b/src/commands/githubActions/bumpUpstream/types.ts @@ -1,10 +1,10 @@ -import { Manifest, Compose } from "@dappnode/types"; +import { UpstreamItem, Manifest, Compose } from "@dappnode/types"; import { ManifestFormat } from "../../../files/manifest/types.js"; import { Github } from "../../../providers/github/Github.js"; -export interface UpstreamSettings { - repo: string; - arg: string; +export type UpstreamSettings = Omit & { + manifestVersion: string; + githubVersion: string; } export interface GitSettings { @@ -25,7 +25,7 @@ export interface GitBranch { } export interface InitialSetupData { - upstreamSettings: UpstreamSettings[]; + upstreamSettings: UpstreamSettings[] | null; manifestData: { manifest: Manifest; format: ManifestFormat; @@ -41,10 +41,6 @@ export type UpstreamRepo = { newVersion: string }; -export type UpstreamRepoMap = { - [upstreamArg: string]: UpstreamRepo; -}; - export type ComposeVersionsToUpdate = { [repoSlug: string]: { newVersion: string; diff --git a/test/commands/gaBumpUpstream/format.test.ts b/test/commands/gaBumpUpstream/format.test.ts index f88bedc9..3d666e86 100644 --- a/test/commands/gaBumpUpstream/format.test.ts +++ b/test/commands/gaBumpUpstream/format.test.ts @@ -1,25 +1,18 @@ import { expect } from "chai"; import { getBumpPrBody, - getUpstreamVersionTag, isValidRelease, } from "../../../src/commands/githubActions/bumpUpstream/github/index.js"; -import { ComposeVersionsToUpdate } from "../../../src/commands/githubActions/bumpUpstream/types.js"; +import { ComposeVersionsToUpdate, UpstreamSettings } from "../../../src/commands/githubActions/bumpUpstream/types.js"; describe("command / gaBumpUpstream / format", () => { describe("single version", () => { - const versionsToUpdate: ComposeVersionsToUpdate = { - "ipfs/go-ipfs": { - newVersion: "v0.7.0", - currentVersion: "v0.6.0" - } - - }; - - it("getUpstreamVersionTag", () => { - const upstreamVersion = getUpstreamVersionTag(versionsToUpdate); - expect(upstreamVersion).to.equal("v0.7.0"); - }); + const versionsToUpdate: UpstreamSettings[] = [{ + repo: "ipfs/go-ipfs", + arg: "v0.7.0", + manifestVersion: "v0.6.0", + githubVersion: "v0.7.0" + }]; it("getPrBody", () => { const upstreamVersion = getBumpPrBody(versionsToUpdate); @@ -30,24 +23,20 @@ describe("command / gaBumpUpstream / format", () => { }); describe("multiple version", () => { - const versionsToUpdate: ComposeVersionsToUpdate = { - "sigp/lighthouse": { - newVersion: "v0.1.4", - currentVersion: "v0.1.2" + const versionsToUpdate: UpstreamSettings[] = [ + { + repo: "sigp/lighthouse", + arg: "v0.1.4", + manifestVersion: "v0.1.2", + githubVersion: "v0.1.4" }, - "prysmaticlabs/prysm": { - newVersion: "v0.1.0-beta.29", - currentVersion: "v0.1.0-beta.28" + { + repo: "prysmaticlabs/prysm", + arg: "v0.1.0-beta.29", + manifestVersion: "v0.1.0-beta.28", + githubVersion: "v0.1.0-beta.29" } - - }; - - it("getUpstreamVersionTag", () => { - const upstreamVersion = getUpstreamVersionTag(versionsToUpdate); - expect(upstreamVersion).to.equal( - "sigp/lighthouse@v0.1.4, prysmaticlabs/prysm@v0.1.0-beta.29" - ); - }); + ]; it("getPrBody", () => { const upstreamVersion = getBumpPrBody(versionsToUpdate); diff --git a/yarn.lock b/yarn.lock index 7ba75d5c..c765ac83 100644 --- a/yarn.lock +++ b/yarn.lock @@ -57,12 +57,12 @@ dependencies: "@jridgewell/trace-mapping" "0.3.9" -"@dappnode/schemas@^0.1.18": - version "0.1.18" - resolved "https://registry.yarnpkg.com/@dappnode/schemas/-/schemas-0.1.18.tgz#2d937bdcaebf446e5fe4e42af904be90d9e472a7" - integrity sha512-Pxahr4u72yiPVZDVDMXHEQWRuW22nOUuBtY5N3+XGL6qeZZNXNxkzlnP4mEUGBqUBBizK6ffWCCj1OZ/N8XddQ== +"@dappnode/schemas@^0.1.19": + version "0.1.19" + resolved "https://registry.yarnpkg.com/@dappnode/schemas/-/schemas-0.1.19.tgz#8609fa66a471f49c0101acfb124e76ce6ae4cb7a" + integrity sha512-4zKnsjOXt/iBsvXpm3ZqWOLNwGwACq9LsjuK+a5BR/W/wmh5mXacvYSI8O2/kN766kkSFTJteDLGcr0Vf84eHg== dependencies: - "@dappnode/types" "^0.1.37" + "@dappnode/types" "^0.1.38" ajv "^8.12.0" semver "^7.5.0" @@ -89,10 +89,15 @@ resolved "https://registry.yarnpkg.com/@dappnode/types/-/types-0.1.34.tgz#f84713687860b569e405884132a953e4ee4b8ade" integrity sha512-07DEQVP6umDUDhDcX8m7EZMZtUUeyOeigupTWo8/oNsHuw7/V+UMCnUjYr1UsoNug2B3nRJ4V+iYQl0R/fhBEQ== -"@dappnode/types@^0.1.37": - version "0.1.37" - resolved "https://registry.yarnpkg.com/@dappnode/types/-/types-0.1.37.tgz#c66424ca047006cb3b7e22e8d38556babc692bd6" - integrity sha512-+MBKIQsiMG78Yt8mAqQJXDih1D1IqiQVQdXHAdJfoBONnd+bl1shPuOggvS53iBQ54yq1Ccc5oI7usV4a04g0w== +"@dappnode/types@^0.1.38": + version "0.1.38" + resolved "https://registry.yarnpkg.com/@dappnode/types/-/types-0.1.38.tgz#ec2d4fd52044e2e45fb696fa6a42faf807202b77" + integrity sha512-VsPDVYeQ05FKzlHDQHtjk2jL9Sv1dIwR25s0qVQXjB3IBh9jkYzSf99kVTuRpgiLah355tddJpPPHizgLhRqJA== + +"@dappnode/types@^0.1.39": + version "0.1.39" + resolved "https://registry.yarnpkg.com/@dappnode/types/-/types-0.1.39.tgz#f82591dc3403d7c2049a078d43515771e7627939" + integrity sha512-HekCz9O24km0FfAr3yzIq9j8TqCshY3+UD3+ee0SKwj/Iq5QYV0I4gH4EL2U8w7Mwgu2T8tJUzmTbG1c05giEw== "@graphql-typed-document-node/core@^3.2.0": version "3.2.0"