Skip to content
Merged
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
6 changes: 5 additions & 1 deletion src/commands/build/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,11 @@ export async function buildHandler({
requireGitData,
deleteOldPins,
...(multiVariantMode &&
getVariantOptions({ variantsStr: variants, rootDir: dir, variantsDirName }))
getVariantOptions({
variantsStr: variants,
rootDir: dir,
variantsDirName
}))
};

const verbosityOptions: VerbosityOptions = {
Expand Down
12 changes: 10 additions & 2 deletions src/commands/githubActions/build/botComment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export function getBuildBotComment({
.map(([dnpName, { releaseMultiHash }], index) =>
formatBuildEntry({ dnpName, releaseMultiHash, index })
)
.join('\n\n');
.join("\n\n");

return `Dappnode bot has built and pinned the built packages to an IPFS node, for commit: ${commitSha}

Expand All @@ -34,7 +34,15 @@ ${botCommentTag}
`;
}

function formatBuildEntry({ dnpName, releaseMultiHash, index }: { dnpName: string, releaseMultiHash: string, index: number }) {
function formatBuildEntry({
dnpName,
releaseMultiHash,
index
}: {
dnpName: string;
releaseMultiHash: string;
index: number;
}) {
const installLink = getInstallDnpLink(releaseMultiHash);
return `${index + 1}. Package **${dnpName}**

Expand Down
89 changes: 51 additions & 38 deletions src/commands/githubActions/bumpUpstream/github/closeOldPrs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,71 +5,84 @@ import { shell } from "../../../../utils/shell.js";
/**
* Close old PRs related to bump-upstream branches, keeping only the latest one.
*/
export async function closeOldPrs(thisRepo: Github, newBranch: string): Promise<void> {
const newPr = await getNewPr(thisRepo, newBranch);
const bumpBranches = await getBumpBranches(thisRepo, newBranch);
export async function closeOldPrs(
thisRepo: Github,
newBranch: string
): Promise<void> {
const newPr = await getNewPr(thisRepo, newBranch);
const bumpBranches = await getBumpBranches(thisRepo, newBranch);

for (const oldBranch of bumpBranches) {
await closePrsAndDeleteBranch(thisRepo, oldBranch, newPr.html_url);
}
for (const oldBranch of bumpBranches) {
await closePrsAndDeleteBranch(thisRepo, oldBranch, newPr.html_url);
}
}

/**
* Get the open PR for a given branch.
*/
async function getNewPr(thisRepo: Github, newBranch: string) {
const [newPr] = await thisRepo.getOpenPrsFromBranch({ branch: newBranch });
if (!newPr) throw Error(`No PR found for branch ${newBranch}`);
return newPr;
const [newPr] = await thisRepo.getOpenPrsFromBranch({ branch: newBranch });
if (!newPr) throw Error(`No PR found for branch ${newBranch}`);
return newPr;
}

/**
* Get branches that start with the branchNameRoot and are not the new branch.
*/
async function getBumpBranches(thisRepo: Github, newBranch: string) {
const allBranches = await thisRepo.listBranches();
return allBranches
.filter(({ name }) => name.startsWith(branchNameRoot) && name !== newBranch)
.map(({ name }) => name);
const allBranches = await thisRepo.listBranches();
return allBranches
.filter(({ name }) => name.startsWith(branchNameRoot) && name !== newBranch)
.map(({ name }) => name);
}

/**
* Close all PRs for a given branch and delete the branch.
*/
async function closePrsAndDeleteBranch(thisRepo: Github, oldBranch: string, newPrUrl: string) {
try {
const prs = await thisRepo.getOpenPrsFromBranch({ branch: oldBranch });
await Promise.all(prs.map(pr => closePr(thisRepo, pr, newPrUrl)));
await deleteBranch(oldBranch);
} catch (error) {
console.error(`Error handling branch ${oldBranch}:`, error);
}
async function closePrsAndDeleteBranch(
thisRepo: Github,
oldBranch: string,
newPrUrl: string
) {
try {
const prs = await thisRepo.getOpenPrsFromBranch({ branch: oldBranch });
await Promise.all(prs.map(pr => closePr(thisRepo, pr, newPrUrl)));
await deleteBranch(oldBranch);
} catch (error) {
console.error(`Error handling branch ${oldBranch}:`, error);
}
}

/**
* Close a single PR with a comment.
*/
async function closePr(thisRepo: Github, pr: { number: number }, newPrUrl: string) {
try {
await thisRepo.commentPullRequest({
number: pr.number,
body: `Newer version available, closing for ${newPrUrl}`
});
await thisRepo.closePR(pr.number);
console.log(`Closed PR #${pr.number} and commented: 'Newer version available, closing for ${newPrUrl}'`);
} catch (error) {
console.error(`Error commenting and closing PR ${pr.number}`, error);
}
async function closePr(
thisRepo: Github,
pr: { number: number },
newPrUrl: string
) {
try {
await thisRepo.commentPullRequest({
number: pr.number,
body: `Newer version available, closing for ${newPrUrl}`
});
await thisRepo.closePR(pr.number);
console.log(
`Closed PR #${pr.number} and commented: 'Newer version available, closing for ${newPrUrl}'`
);
} catch (error) {
console.error(`Error commenting and closing PR ${pr.number}`, error);
}
}

/**
* Delete a branch from the repository.
*/
async function deleteBranch(branchName: string) {
try {
await shell(`git push origin --delete ${branchName}`);
console.log(`Deleted branch: ${branchName}`);
} catch (error) {
console.error(`Error deleting branch ${branchName}`, error);
}
try {
await shell(`git push origin --delete ${branchName}`);
console.log(`Deleted branch: ${branchName}`);
} catch (error) {
console.error(`Error deleting branch ${branchName}`, error);
}
}
Original file line number Diff line number Diff line change
@@ -1,32 +1,33 @@
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;
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}`);
const [owner, repoName] = repo.split("/");
const githubRepo = new Github({ owner, repo: repoName });

return latestRelease.tag_name;
const releases = await githubRepo.listReleases();
const latestRelease = releases[0];
if (!latestRelease) throw Error(`No release found for ${repo}`);

}
return latestRelease.tag_name;
}
34 changes: 24 additions & 10 deletions src/commands/githubActions/bumpUpstream/github/getBumpPrBody.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,29 @@
import { UpstreamSettings } from "../types.js";

export function getBumpPrBody(upstreamSettings: UpstreamSettings[]): string {
return [
"Bumps upstream version",
upstreamSettings.flatMap(({ repo, githubVersion, manifestVersion }) =>
`- [${repo}](${getGitHubUrl({ repo })}) from ${manifestVersion} to [${githubVersion}](${getGitHubUrl({ repo, tag: githubVersion })})`
).join("\n")
].join("\n\n");
return [
"Bumps upstream version",
upstreamSettings
.flatMap(
({ repo, githubVersion, manifestVersion }) =>
`- [${repo}](${getGitHubUrl({
repo
})}) from ${manifestVersion} to [${githubVersion}](${getGitHubUrl({
repo,
tag: githubVersion
})})`
)
.join("\n")
].join("\n\n");
}

function getGitHubUrl({ repo, tag = "" }: { repo: string, tag?: string }): string {
const baseUrl = `https://github.com/${repo}`;
return tag ? `${baseUrl}/releases/tag/${tag}` : baseUrl;
}
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
Expand Up @@ -2,19 +2,23 @@ import { branchNameRoot } from "../../../../params.js";
import { Github } from "../../../../providers/github/Github.js";
import { GithubSettings, GitBranch, UpstreamSettings } from "../types.js";

export async function getGithubSettings(dir: string, upstreamSettings: UpstreamSettings[]): Promise<GithubSettings> {
const thisRepo = Github.fromLocal(dir);
const repoData = await thisRepo.getRepo();
const branch = getBumpBranch(upstreamSettings);
return { repo: thisRepo, repoData, ...branch };
export async function getGithubSettings(
dir: string,
upstreamSettings: UpstreamSettings[]
): Promise<GithubSettings> {
const thisRepo = Github.fromLocal(dir);
const repoData = await thisRepo.getRepo();
const branch = getBumpBranch(upstreamSettings);
return { repo: thisRepo, repoData, ...branch };
}

function getBumpBranch(upstreamSettings: UpstreamSettings[]): GitBranch {
const branchName = branchNameRoot +
Array.from(Object.values(upstreamSettings))
.map(({ repo, githubVersion }) => `${repo}@${githubVersion}`)
.join(",");
const branchRef = `refs/heads/${branchName}`;
const branchName =
branchNameRoot +
Array.from(Object.values(upstreamSettings))
.map(({ repo, githubVersion }) => `${repo}@${githubVersion}`)
.join(",");
const branchRef = `refs/heads/${branchName}`;

return { branchName, branchRef };
}
return { branchName, branchRef };
}
20 changes: 13 additions & 7 deletions src/commands/githubActions/bumpUpstream/github/isBranchNew.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
import { Github } from "../../../../providers/github/Github.js";
import { getLocalBranchExists } from "../../../../utils/git.js";

export async function isBranchNew({ branchName, repo }: { branchName: string, repo: Github }): Promise<boolean> {
const [remoteBranchExists, localBranchExists] = await Promise.all([
repo.branchExists(branchName),
getLocalBranchExists(branchName),
]);
export async function isBranchNew({
branchName,
repo
}: {
branchName: string;
repo: Github;
}): Promise<boolean> {
const [remoteBranchExists, localBranchExists] = await Promise.all([
repo.branchExists(branchName),
getLocalBranchExists(branchName)
]);

return !remoteBranchExists && !localBranchExists;
}
return !remoteBranchExists && !localBranchExists;
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import semver from "semver";

export function isValidRelease(version: string): boolean {
// Nightly builds are not considered valid releases (not taken into account by semver)
if (version.includes("nightly")) return false;
// Nightly builds are not considered valid releases (not taken into account by semver)
if (version.includes("nightly")) return false;

if (!semver.valid(version)) return false;
if (!semver.valid(version)) return false;

const preReleases = semver.prerelease(version);
const preReleases = semver.prerelease(version);

// A version is considered a valid release if it has no pre-release components.
return preReleases === null || preReleases.length === 0;
}
// A version is considered a valid release if it has no pre-release components.
return preReleases === null || preReleases.length === 0;
}
Loading