From 0988e76bfa0aefccfc2ccb6f6c334a083cba5c93 Mon Sep 17 00:00:00 2001 From: dappnodedev <144998261+dappnodedev@users.noreply.github.com> Date: Thu, 11 Jul 2024 11:19:16 +0200 Subject: [PATCH] Fix empty bot comment (#437) --- .../githubActions/build/botComment.ts | 2 +- src/commands/githubActions/build/index.ts | 40 +++++++++++++++---- src/commands/githubActions/build/types.ts | 6 +++ .../githubActions/bumpUpstream/index.ts | 5 ++- 4 files changed, 42 insertions(+), 11 deletions(-) create mode 100644 src/commands/githubActions/build/types.ts diff --git a/src/commands/githubActions/build/botComment.ts b/src/commands/githubActions/build/botComment.ts index a35c7e54..876290fe 100644 --- a/src/commands/githubActions/build/botComment.ts +++ b/src/commands/githubActions/build/botComment.ts @@ -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"); diff --git a/src/commands/githubActions/build/index.ts b/src/commands/githubActions/build/index.ts index 521b5830..78def92d 100644 --- a/src/commands/githubActions/build/index.ts +++ b/src/commands/githubActions/build/index.ts @@ -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,11 +25,22 @@ import { cleanPinsFromDeletedBranches } from "./cleanPinsFromDeletedBranches.js" // For 'pull_request' events: // Does a build test but doesn't upload the result anywhere -export const gaBuild: CommandModule = { +export const gaBuild: CommandModule = { 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 => await gaBuildHandler(args) }; @@ -36,8 +48,10 @@ export const gaBuild: CommandModule = { * Common handler for CLI and programatic usage */ async function gaBuildHandler({ - dir = defaultDir -}: CliGlobalOptions): Promise { + dir = defaultDir, + all_variants, + variants +}: BuildActionOptions): Promise { 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 { // 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 }); diff --git a/src/commands/githubActions/build/types.ts b/src/commands/githubActions/build/types.ts new file mode 100644 index 00000000..42b2dd61 --- /dev/null +++ b/src/commands/githubActions/build/types.ts @@ -0,0 +1,6 @@ +import { CliGlobalOptions } from "../../../types.js"; + +export interface BuildActionOptions extends CliGlobalOptions { + variants?: string; + all_variants?: boolean; +} diff --git a/src/commands/githubActions/bumpUpstream/index.ts b/src/commands/githubActions/bumpUpstream/index.ts index caf3e834..0f8c10f2 100644 --- a/src/commands/githubActions/bumpUpstream/index.ts +++ b/src/commands/githubActions/bumpUpstream/index.ts @@ -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 { const manifestDirs = allVariants ? getAllVariantsInPath(variantsDir).map(variant => - path.join(variantsDir, variant) - ) + path.join(variantsDir, variant) + ) : [dir]; for (const dir of manifestDirs) {