Skip to content

Commit

Permalink
Fix empty bot comment (#437)
Browse files Browse the repository at this point in the history
dappnodedev authored Jul 11, 2024
1 parent 95271e8 commit 0988e76
Showing 4 changed files with 42 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/commands/githubActions/build/botComment.ts
Original file line number Diff line number Diff line change
@@ -21,7 +21,7 @@ export function getBuildBotComment({
const buildEntries = Object.entries(buildResults)
.map(([dnpName, { releaseMultiHash }], index) => {
if (releaseMultiHash)
formatBuildEntry({ dnpName, releaseMultiHash, index });
return formatBuildEntry({ dnpName, releaseMultiHash, index });
})
.join("\n\n");

40 changes: 32 additions & 8 deletions src/commands/githubActions/build/index.ts
Original file line number Diff line number Diff line change
@@ -7,6 +7,7 @@ import { Github } from "../../../providers/github/Github.js";
import { parseRef } from "../../../providers/github/utils.js";
import { getBuildBotComment, isTargetComment } from "./botComment.js";
import { cleanPinsFromDeletedBranches } from "./cleanPinsFromDeletedBranches.js";
import { BuildActionOptions } from "./types.js";

// This action should be run on 'push' and 'pull_request' events
//
@@ -24,20 +25,33 @@ import { cleanPinsFromDeletedBranches } from "./cleanPinsFromDeletedBranches.js"
// For 'pull_request' events:
// Does a build test but doesn't upload the result anywhere

export const gaBuild: CommandModule<CliGlobalOptions, CliGlobalOptions> = {
export const gaBuild: CommandModule<BuildActionOptions, CliGlobalOptions> = {
command: "build",
describe:
"Build and upload test release and post a comment with install link to the triggering PR",
builder: {},
builder: {
all_variants: {
alias: "all-variants",
description: `Build all package variants at once, by merging the dappnode_package.json and docker-compose.yml files in the root of the project with the specific ones defined for each package variant`,
type: "boolean"
},
variants: {
alias: "variant",
description: `Specify the package variants to build (only for packages that support it). Defined by comma-separated list of variant names. Example: "variant1,variant2"`,
type: "string"
}
},
handler: async (args): Promise<void> => await gaBuildHandler(args)
};

/**
* Common handler for CLI and programatic usage
*/
async function gaBuildHandler({
dir = defaultDir
}: CliGlobalOptions): Promise<void> {
dir = defaultDir,
all_variants,
variants
}: BuildActionOptions): Promise<void> {
const { eventName, sha: commitSha, ref: refString } = getGithubContext();
const ref = parseRef(refString);

@@ -61,7 +75,9 @@ async function gaBuildHandler({
await buildAndComment({
dir,
commitSha,
branch: ref.branch
branch: ref.branch,
all_variants,
variants
});
} else if (eventName === "push" || eventName === "pull_request") {
// Consider that for 'pull_request' commitSha does not represent a known commit
@@ -75,7 +91,9 @@ async function gaBuildHandler({
provider: "dappnode",
upload_to: "ipfs",
skip_save: true,
verbose: true
verbose: true,
all_variants,
variants
});
} else if (!eventName) {
throw Error("Not in Github action context");
@@ -87,11 +105,15 @@ async function gaBuildHandler({
export async function buildAndComment({
dir,
commitSha,
branch
branch,
all_variants,
variants
}: {
dir: string;
commitSha: string;
branch: string;
all_variants?: boolean;
variants?: string;
}): Promise<void> {
// Connect to Github Octokit REST API and post or edit a comment on PR
const github = Github.fromLocal(dir);
@@ -101,7 +123,9 @@ export async function buildAndComment({
upload_to: "ipfs",
require_git_data: true,
delete_old_pins: true,
verbose: true
verbose: true,
all_variants,
variants
});

const body = getBuildBotComment({ commitSha, buildResults });
6 changes: 6 additions & 0 deletions src/commands/githubActions/build/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { CliGlobalOptions } from "../../../types.js";

export interface BuildActionOptions extends CliGlobalOptions {
variants?: string;
all_variants?: boolean;
}
5 changes: 3 additions & 2 deletions src/commands/githubActions/bumpUpstream/index.ts
Original file line number Diff line number Diff line change
@@ -56,6 +56,7 @@ export const gaBumpUpstream: CommandModule<
type: "boolean"
},
use_variants: {
alias: "use-variants",
description: `It will use the dappnode_package.json and docker-compose.yml files in the root of the project together with the specific ones defined for each package variant to build all of them`,
type: "boolean"
},
@@ -233,8 +234,8 @@ async function updateManifestPkgVersion({
}): Promise<void> {
const manifestDirs = allVariants
? getAllVariantsInPath(variantsDir).map(variant =>
path.join(variantsDir, variant)
)
path.join(variantsDir, variant)
)
: [dir];

for (const dir of manifestDirs) {

0 comments on commit 0988e76

Please sign in to comment.