Skip to content

Commit

Permalink
workflows: add Action Names and Env to Run Workflow button (#7877)
Browse files Browse the repository at this point in the history
Let user decide which action to run from our web UI.
The field accepts multiple action names separated by comma (`,`).

Custom input could be provided via environment variables.
The environment variables should be specified in comma-separated
key-value pairs.
For example: `VAR1=value1,VAR2=value2`.

---------

Co-authored-by: Brandon Duffany <[email protected]>
  • Loading branch information
sluongng and bduffany authored Nov 14, 2024
1 parent 2bccf54 commit 627f7ea
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
1 change: 0 additions & 1 deletion enterprise/app/workflows/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ ts_library(
"//app/capabilities",
"//app/components/button",
"//app/components/button:link_button",
"//app/components/checkbox",
"//app/components/dialog:simple_modal_dialog",
"//app/components/input",
"//app/components/link",
Expand Down
28 changes: 27 additions & 1 deletion enterprise/app/workflows/workflows.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import TextInput from "../../../app/components/input/input";
import alert_service from "../../../app/alert/alert_service";
import errorService from "../../../app/errors/error_service";
import Spinner from "../../../app/components/spinner/spinner";
import Checkbox from "../../../app/components/checkbox/checkbox";
import ActionListComponent from "./action_list";

type Workflow = workflow.GetWorkflowsResponse.Workflow;
Expand Down Expand Up @@ -359,6 +358,8 @@ type RepoItemState = {
isMenuOpen: boolean;

showRunWorkflowInput: boolean;
runWorkflowActionNames: string;
runWorkflowEnv: string;
runWorkflowBranch: string;
runWorkflowVisibility: string;
isWorkflowRunning: boolean;
Expand All @@ -370,6 +371,8 @@ class RepoItem extends React.Component<RepoItemProps, RepoItemState> {
state: RepoItemState = {
isMenuOpen: false,
showRunWorkflowInput: false,
runWorkflowActionNames: "",
runWorkflowEnv: "",
runWorkflowBranch: "",
runWorkflowVisibility: "",
isWorkflowRunning: false,
Expand Down Expand Up @@ -415,6 +418,19 @@ class RepoItem extends React.Component<RepoItemProps, RepoItemState> {
.executeWorkflow(
new workflow.ExecuteWorkflowRequest({
pushedRepoUrl: this.props.repoUrl,
// Parse "var1=val1,var2=val2" string from the input field to Record<string, string>
env: Object.fromEntries<string>(
this.state.runWorkflowEnv
.split(",")
.filter((n) => n.includes("="))
.map((n) => n.trim().split("="))
.filter((parts) => parts.length)
.map(([name, ...valueParts]) => [name, valueParts.join("=")])
),
actionNames: this.state.runWorkflowActionNames
.split(",")
.map((n) => n.trim())
.filter((n) => n.length > 0),
pushedBranch: this.state.runWorkflowBranch,
targetRepoUrl: this.props.repoUrl,
targetBranch: this.state.runWorkflowBranch,
Expand Down Expand Up @@ -529,6 +545,16 @@ class RepoItem extends React.Component<RepoItemProps, RepoItemState> {
placeholder={"e.g. PUBLIC (optional)"}
onChange={(e) => this.setState({ runWorkflowVisibility: e.target.value })}
/>
<div className="title">Action Names:</div>
<TextInput
placeholder={"e.g. Test,Build"}
onChange={(e) => this.setState({ runWorkflowActionNames: e.target.value })}
/>
<div className="title">Environment Variables:</div>
<TextInput
placeholder={"e.g. VAR1=value1,VAR2=value2"}
onChange={(e) => this.setState({ runWorkflowEnv: e.target.value })}
/>
<FilledButton onClick={this.runWorkflow.bind(this)} disabled={this.state.runWorkflowBranch === ""}>
Run
</FilledButton>
Expand Down

0 comments on commit 627f7ea

Please sign in to comment.