Skip to content

Commit

Permalink
make Command's job CI image configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
mordamax committed Jul 18, 2023
1 parent 83b1aa1 commit f265a9c
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 14 deletions.
10 changes: 0 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ Before starting to work on this project, we recommend reading the
- [Pull request commands](#pull-request-commands)
- [Help](#pull-request-command-help)
- [Cancel](#pull-request-command-cancel)
- [Generic](#pull-request-command-generic)
- [Testing generic command in dev](#pull-request-command-generic-dev)
- [API](#api)
- [Queue](#api-command-queue)
- [Cancel](#api-command-cancel)
Expand Down Expand Up @@ -60,14 +58,6 @@ In `[bot-args]` are optional, you can provide the following options

Bot responds with an actual list of commands generated from pipeline.

## Example of one generic command Bench <a name="pull-request-command-generic"></a>

`bot bench $ runtime westend-dev pallet_balances`

#### Testing the updates to command-bot-scripts by overriding its default branch <a name="pull-request-command-generic-dev"></a>

`bot bench -v PIPELINE_SCRIPTS_REF=your-branch $ overhead assets westmint`

## Cancel <a name="pull-request-command-cancel"></a>

In the pull request where you previously ran `bot queue`, comment:
Expand Down
2 changes: 1 addition & 1 deletion src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ export const setupApi = (ctx: Context, server: Server): void => {
job: {
...configuration.gitlab.job,
variables: { ...configuration.gitlab.job.variables, ...variables },
image: gitlab.jobImage,
image: gitlab.defaultJobImage,
},
pipeline: null,
},
Expand Down
9 changes: 8 additions & 1 deletion src/bot/events/onIssueCommentCreated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
updateComment,
} from "src/github";
import { counters, getMetricsPrData } from "src/metrics";
import { CMD_IMAGE } from "src/setup";
import { cancelTask, getNextTaskId, PullRequestTask, queueTask, serializeTaskQueuedDate } from "src/task";
import { getLines } from "src/utils";

Expand Down Expand Up @@ -150,6 +151,12 @@ export const onIssueCommentCreated: WebhookHandler<"issue_comment.created"> = as

const defaultVariables = parsedCommand.configuration.gitlab?.job.variables;
const overriddenVariables = parsedCommand.variables;
const configJobImage = parsedCommand.configuration.gitlab?.job.image;
let image: string = typeof configJobImage === "string" ? configJobImage : gitlab.defaultJobImage;

if (typeof overriddenVariables?.[CMD_IMAGE] === "string") {
image = overriddenVariables[CMD_IMAGE] as string;
}

const task: PullRequestTask = {
...pr,
Expand All @@ -167,8 +174,8 @@ export const onIssueCommentCreated: WebhookHandler<"issue_comment.created"> = as
queuedDate: serializeTaskQueuedDate(queuedDate),
gitlab: {
job: {
image,
tags: parsedCommand.configuration.gitlab?.job.tags || [],
image: gitlab.jobImage,
variables: Object.assign(defaultVariables, overriddenVariables),
},
pipeline: null,
Expand Down
12 changes: 12 additions & 0 deletions src/command-configs/help/parts/commands.pug
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,18 @@ div(id="link-new-command").command
p
code #{commandStart} new-command -v PIPELINE_SCRIPTS_REF=mak/new-command new-id --new-arg=value

div(id="link-override-ci-image").command
h5 Override Command's CI Image
p You can override command's CI image with any other image, for example when you need to test new version of Rust

p Syntax (after command name):
p
code -v CMD_IMAGE=paritytech/ci-unified:bullseye-1.70.0-2023-05-23

p Examples:
p
code #{commandStart} update-ui -v CMD_IMAGE=paritytech/ci-unified:bullseye-1.70.0-2023-05-23 --rust_version=1.70.0

div(id="link-rust").command
h5 Rust Log, etc
p You can define custom env variables like for RUST env
Expand Down
2 changes: 2 additions & 0 deletions src/command-configs/help/parts/navigation.pug
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,7 @@ div.sticky-nav
a(href="\#link-companion") Patch Companion
li
a(href="\#link-new-command") How to test new command (test dev branch)
li
a(href="\#link-override-ci-image") Override Command's CI Image
li
a(href="\#link-rust") Rust Log, etc
2 changes: 1 addition & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const main = async () => {
accessTokenUsername: config.gitlabAccessTokenUsername,
domain: config.gitlabDomain,
pushNamespace: config.gitlabPushNamespace,
jobImage: config.gitlabJobImage,
defaultJobImage: config.gitlabJobImage,
},
}).then(resolve, reject),
)
Expand Down
3 changes: 3 additions & 0 deletions src/schema/schema.cmd.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@
"variables": {
"type": "object",
"additionalProperties": true
},
"image": {
"type": "string"
}
},
"required": ["tags"]
Expand Down
5 changes: 5 additions & 0 deletions src/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,12 @@ export const DOCS_URL_PATH = "/static/docs/";
export const GENERATED_DIR = path.join(process.cwd(), "generated");
export const DOCS_DIR = path.join(GENERATED_DIR, "docs");

// -v --variable to override scripts branch to test new features
export const PIPELINE_SCRIPTS_REF = "PIPELINE_SCRIPTS_REF";

// -v --variable to override default image revision
export const CMD_IMAGE = "CMD_IMAGE";

export const LATEST = "latest";

export const setup = async (
Expand Down
2 changes: 1 addition & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export type Context = {
accessToken: string;
domain: string;
pushNamespace: string;
jobImage: string;
defaultJobImage: string;
accessTokenUsername: string;
};
};
Expand Down

0 comments on commit f265a9c

Please sign in to comment.