Skip to content
This repository was archived by the owner on Jan 21, 2025. It is now read-only.
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
7 changes: 7 additions & 0 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,13 @@ test-unit:

test-integration:
<<: *common-refs
# for debug
artifacts:
name: "${CI_JOB_NAME}_${CI_COMMIT_REF_NAME}"
expire_in: "1 day"
when: "on_failure"
paths:
- ./generated
stage: test
script:
- yarn --immutable
Expand Down
8 changes: 3 additions & 5 deletions deploy-stg.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,15 @@ timestamp=$(date +%s)
dev_branch=$(git rev-parse --abbrev-ref HEAD)

# replace possible "/" with "-"
# Because of a docker, as it uses git tag for tagging the image so if there's a / symbol
# docker thinks that it's actually a path. but not part of the tag name.
dev_branch_sanitized=${dev_branch/\//-}

stg_branch="stg-v0.0.${timestamp}-${dev_branch_sanitized}"

git checkout -b "$stg_branch"
git push origin "$stg_branch"
git push origin HEAD:"$stg_branch"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Love this simplified method


# wait a bit before deleting branch, so gitlab triggers pipeline
sleep 10

git push origin --delete "$stg_branch"

# get back to initial branch
git checkout "$dev_branch"
18 changes: 11 additions & 7 deletions src/bot/parse/parsePullRequestBotCommandLine.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const dataProvider: DataProvider[] = [
{
suitName: "unrelated to bot comment returns nothing (ignores)",
commandLine: "something from comments",
expectedResponse: new SkipEvent(),
expectedResponse: new SkipEvent("Not a command"),
},
{
suitName: "check wrong set -v, validation should trigger error",
Expand Down Expand Up @@ -86,7 +86,7 @@ const dataProvider: DataProvider[] = [
suitName: "bench-bot, no args when not allowed, should return error",
commandLine: "bot bench",
expectedResponse: new Error(
`Missing arguments for command "bench". Refer to [help docs](http://cmd-bot.docs.com/) for more details.`,
`Missing arguments for command "bench". Refer to [help docs](http://cmd-bot.docs.com/) and/or [source code](https://github.com/paritytech/command-bot-scripts).`,
),
},

Expand All @@ -106,8 +106,12 @@ const dataProvider: DataProvider[] = [
/*
Ignore cases
*/
{ suitName: "empty command line returns nothing (ignores)", commandLine: "", expectedResponse: new SkipEvent() },
{ suitName: "no subcommand - ignore", commandLine: "bot ", expectedResponse: new SkipEvent() },
{
suitName: "empty command line returns nothing (ignores)",
commandLine: "",
expectedResponse: new SkipEvent("Not a command"),
},
{ suitName: "no subcommand - ignore", commandLine: "bot ", expectedResponse: new SkipEvent("Not a command") },
{ suitName: "ignored command", commandLine: "bot merge", expectedResponse: new SkipEvent("Ignored command: merge") },
{
suitName: "ignored command 2",
Expand All @@ -122,21 +126,21 @@ const dataProvider: DataProvider[] = [
suitName: "nonexistent command, should return proper error",
commandLine: "bot nope 123123",
expectedResponse: new Error(
'Could not find matching configuration for command "nope"; Available ones are bench, fmt, sample, try-runtime. Refer to [help docs](http://cmd-bot.docs.com/) for more details.',
'Unknown command "nope"; Available ones are bench, fmt, sample, try-runtime. Refer to [help docs](http://cmd-bot.docs.com/) and/or [source code](https://github.com/paritytech/command-bot-scripts).',
),
},
{
suitName: "not provided command, returns proper error",
commandLine: "bot $",
expectedResponse: new Error(
'Could not find matching configuration for command "$"; Available ones are bench, fmt, sample, try-runtime. Refer to [help docs](http://cmd-bot.docs.com/) for more details.',
'Unknown command "$"; Available ones are bench, fmt, sample, try-runtime. Refer to [help docs](http://cmd-bot.docs.com/) and/or [source code](https://github.com/paritytech/command-bot-scripts).',
),
},
{
suitName: "non existed config must return error with explanation",
commandLine: "bot xz",
expectedResponse: new Error(
`Could not find matching configuration for command "xz"; Available ones are bench, fmt, sample, try-runtime. Refer to [help docs](http://cmd-bot.docs.com/) for more details.`,
`Unknown command "xz"; Available ones are bench, fmt, sample, try-runtime. Refer to [help docs](http://cmd-bot.docs.com/) and/or [source code](https://github.com/paritytech/command-bot-scripts).`,
),
},
];
Expand Down
11 changes: 6 additions & 5 deletions src/bot/parse/parsePullRequestBotCommandLine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
getDocsUrl,
PIPELINE_SCRIPTS_REF,
} from "src/command-configs/fetchCommandsConfiguration";
import { config } from "src/config";
import { LoggerContext } from "src/logger";
import { validateSingleShellCommand } from "src/shell";

Expand All @@ -20,7 +21,7 @@ export const parsePullRequestBotCommandLine = async (

// Add trailing whitespace so that bot can be differentiated from /cmd-[?]
if (!commandLine.startsWith(`${botPullRequestCommentMention} `)) {
return new SkipEvent();
return new SkipEvent("Not a command");
}

// remove "bot "
Expand Down Expand Up @@ -75,13 +76,13 @@ export const parsePullRequestBotCommandLine = async (
const { commandConfigs, commitHash } = await fetchCommandsConfiguration(ctx, variables[PIPELINE_SCRIPTS_REF]);
const configuration = commandConfigs[subcommand]?.command?.configuration;

const helpStr = `Refer to [help docs](${getDocsUrl(commitHash)}) for more details.`;
const helpStr = `Refer to [help docs](${getDocsUrl(commitHash)}) and/or [source code](${
config.pipelineScripts.repository
}).`;

if (typeof configuration === "undefined" || !Object.keys(configuration).length) {
return new Error(
`Could not find matching configuration for command "${subcommand}"; Available ones are ${Object.keys(
commandConfigs,
).join(", ")}. ${helpStr}`,
`Unknown command "${subcommand}"; Available ones are ${Object.keys(commandConfigs).join(", ")}. ${helpStr}`,
);
}

Expand Down
4 changes: 2 additions & 2 deletions src/bot/setupEvent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ export const setupEvent = <E extends WebhookEvents>(
: await createComment(ctx, octokit, sharedCommentParams);
} else if (result instanceof SkipEvent && !!result.reason.trim()) {
eventLogger.debug(
event.payload,
`Skip command "${event.payload.comment.body}" with reason: "${result.reason}"`,
{ command: event.payload.comment.body, payload: event.payload },
`Skip command with reason: "${result.reason}"`,
);
} else if (result instanceof FinishedEvent) {
eventLogger.info({ result }, "Finished command");
Expand Down
25 changes: 12 additions & 13 deletions src/command-configs/renderHelpPage.pug
Original file line number Diff line number Diff line change
Expand Up @@ -56,19 +56,17 @@ html
div.preset
h5.mb-sm(id="link-"+presetName) #{presetName}
p #{ preset.description }
table.ms-table
thead
tr
th
| Command
th
| $
if preset.args
if preset.args
table.ms-table
thead
tr
th
| Command
th
| $
each arg, argKey in preset.args
th.center
| [#{arg.label}]

if preset.args
tr
td #{commandName}
td
Expand All @@ -80,8 +78,6 @@ html
div.mb-sm #{one}
if arg.type_rule
div #{arg.type_rule}
else
p no arguments

p Example:&nbsp;
code
Expand All @@ -92,7 +88,10 @@ html
if arg.type_one_of
| #{arg.type_one_of[0]}
if arg.type_rule
i custom_string
if arg.example
i #{arg.example}
else
i #{arg.type_rule}
| &nbsp;
else
p Example:&nbsp;
Expand Down
38 changes: 31 additions & 7 deletions src/command-configs/renderHelpPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,40 @@ export function renderHelpPage(params: {
const tmplPath = path.join(__dirname, "renderHelpPage.pug");
const { commandConfigs, scriptsRevision, headBranch, config } = params;

commandConfigs.help = mockStaticConfig("Generates help page & provides a link");
commandConfigs.clean = mockStaticConfig("Clears bot comments in PR");

const repoLink = new URL(path.join(config.pipelineScripts.repository, "tree", headBranch)).toString();
const commandStart = botPullRequestCommentMention;

/* TODO: depends on headBranch, if overridden: add `-v PIPELINE_SCRIPTS_REF=branch` to all command examples
same for PATCH_repo=xxx
TODO: Simplify the PIPELINE_SCRIPTS_REF to something more rememberable */
return pug.renderFile(tmplPath, { config, repoLink, commandConfigs, scriptsRevision, headBranch, commandStart });
const preparedConfigs = prepareConfigs(commandConfigs);

// TODO: depends on headBranch, if overridden: add `-v PIPELINE_SCRIPTS_REF=branch` to all command examples same for PATCH_repo=xxx
// TODO: Simplify the PIPELINE_SCRIPTS_REF to something more rememberable */
return pug.renderFile(tmplPath, {
config,
repoLink,
commandConfigs: preparedConfigs,
scriptsRevision,
headBranch,
commandStart,
});
}

function prepareConfigs(cmdConfigs: CommandConfigs): CommandConfigs {
const newCmdConfigs: CommandConfigs = {};

// these commands are added here, as they are defined inside of bot
newCmdConfigs.help = mockStaticConfig("Generates help page & provides a link");
newCmdConfigs.clean = mockStaticConfig("Clears bot comments in PR");

// clean up excluded
for (const cmdName in cmdConfigs) {
const isExcluded = cmdConfigs[cmdName].command.excluded === true;

if (!isExcluded) {
newCmdConfigs[cmdName] = cmdConfigs[cmdName];
}
}

return newCmdConfigs;
}

// append local (or "hardcoded") commands into documentation
Expand Down
10 changes: 8 additions & 2 deletions src/schema/schema.cmd.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
"command": {
"type": "object",
"properties": {
"excluded": {
"type": "boolean"
},
"description": {
"type": "string"
},
Expand Down Expand Up @@ -88,6 +91,9 @@
},
"type_rule": {
"type": "string"
},
"example": {
"type": "string"
}
},
"anyOf": [
Expand All @@ -98,14 +104,14 @@
"required": ["label", "type_many_of"]
},
{
"required": ["label", "type_rule"]
"required": ["label", "type_rule", "example"]
}
]
}
}
}
},
"required": ["args", "description"]
"required": ["description"]
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/test/github-ignore-comands.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ describe.each(commandsDataProvider)(
const skipTriggeredPromise = new Promise((resolve, reject) => {
bot.stdout?.on("data", (dataBuffer: Buffer) => {
const data = dataBuffer.toString();
if (data.includes(`Skip command "${commandLine}"`)) {
if (data.includes(`Skip command with reason: "Ignored command:`) && data.includes(eventId)) {
resolve("Skipped");
} else if (data.includes("handler finished") && data.includes(eventId)) {
reject('Expected to see "Skip command" output first');
Expand Down
2 changes: 1 addition & 1 deletion src/test/github-non-pipeline-cases.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ const commandsDataProvider: CommandDataProviderItem[] = [
commandLine: "bot hrlp", // intentional typo
expected: {
startMessage:
'@somedev123 Could not find matching configuration for command "hrlp"; Available ones are bench, fmt, sample, try-runtime, help, clean. Refer to [help docs](http://localhost:3000/static/docs/',
'@somedev123 Unknown command "hrlp"; Available ones are bench-all, bench-vm, bench, fmt, merge, rebase, sample, try-runtime. Refer to [help docs](http://localhost:3000/static/docs/',
},
},
{
Expand Down
3 changes: 2 additions & 1 deletion src/test/setup/bot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export const getPingPort = (): number | null => pingPort;
export async function launchBot(gitHubUrl: string, gitLabUrl: string, gitDaemons: GitDaemons): Promise<ChildProcess> {
rmSync(path.join(process.cwd(), "data", "access_db"), { recursive: true, force: true });
rmSync(path.join(process.cwd(), "data", "db"), { recursive: true, force: true });
rmSync(path.join(process.cwd(), "generated"), { recursive: true, force: true });
[webhookPort, pingPort] = await findFreePorts(2);

const botEnv = getBotEnv(gitHubUrl, gitLabUrl, gitDaemons.gitHub.url, gitDaemons.gitLab.url);
Expand Down Expand Up @@ -49,7 +50,7 @@ export async function launchBot(gitHubUrl: string, gitLabUrl: string, gitDaemons
return false;
}
},
500,
1000,
50,
`bot did not start to listen on ping port: ${ensureDefined(pingPort)}`,
).then(resolve, reject);
Expand Down
5 changes: 5 additions & 0 deletions src/test/setup/integration.setupAfterEnv.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { afterAll, beforeAll } from "@jest/globals";
import { delay } from "opstooling-js";

import { getBotInstance, launchBot } from "./bot";
import { startGitDaemons, stopGitDaemons } from "./gitDaemons";
Expand All @@ -17,6 +18,8 @@ beforeAll(async () => {

await launchBot(mockServers.gitHub.url, mockServers.gitLab.url, gitDaemons);
console.log("Bot launched");

await delay(1000);
});

afterAll(async () => {
Expand All @@ -30,4 +33,6 @@ afterAll(async () => {

await stopMockServers();
console.log("MockServers stopped");

await delay(1000);
});