Skip to content

Commit

Permalink
Write manifest multi upstream (#417)
Browse files Browse the repository at this point in the history
* Write manifest for multi-upstream repos

* Improve manifest update doc and format

* Include all versions to update in multi-upstream repos

* Bump schemas 0.1.19 and types 0.1.38

* Deprecate multi-upstream on upstreamVersion

* Fix multi-upstream test

* Keep previous comparison

* Remove old comment

* Rename getUpstreamVersionTag function

* Add spacing

* Unify upstream settings format

* Create manifest upstream types

* Bump types to 0.1.39

* Use types from @dappnode/types:0.1.39

* Only print settings if there are versions to update

* Rename function to updateComposeUpstreamVersions

* Add comment on build arg check

* Separate manifest update
  • Loading branch information
dappnodedev authored Apr 24, 2024
1 parent f285e1e commit 3e05b11
Show file tree
Hide file tree
Showing 12 changed files with 201 additions and 208 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { Github } from "../../../../providers/github/Github.js";
import { isValidRelease } from "./isValidRelease.js";

export async function fetchGithubUpstreamVersion(repo: string): Promise<string | null> {

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<string> {
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;

}
16 changes: 7 additions & 9 deletions src/commands/githubActions/bumpUpstream/github/getBumpPrBody.ts
Original file line number Diff line number Diff line change
@@ -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;
}
Original file line number Diff line number Diff line change
@@ -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<GithubSettings> {
export async function getGithubSettings(dir: string, upstreamSettings: UpstreamSettings[]): Promise<GithubSettings> {
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}`;

Expand Down

This file was deleted.

1 change: 0 additions & 1 deletion src/commands/githubActions/bumpUpstream/github/index.ts
Original file line number Diff line number Diff line change
@@ -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";
Loading

0 comments on commit 3e05b11

Please sign in to comment.