-
Notifications
You must be signed in to change notification settings - Fork 55
feat: Git optional in CI job pipeline #1505
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
import React, { useContext } from 'react' | ||
import React, { useContext, useEffect } from 'react' | ||
import { SourceTypeMap, ViewType } from '../../config' | ||
import { createWebhookConditionList } from '../ciPipeline/ciPipeline.service' | ||
import { SourceMaterials } from '../ciPipeline/SourceMaterials' | ||
import { ValidationRules } from '../ciPipeline/validationRules' | ||
import { Progressing, Toggle, CiPipelineSourceTypeOption } from '@devtron-labs/devtron-fe-common-lib' | ||
import { BuildType, WebhookCIProps } from '../ciPipeline/types' | ||
import { BuildType, CIPipelineBuildType, WebhookCIProps } from '../ciPipeline/types' | ||
import { ReactComponent as AlertTriangle } from '../../assets/icons/ic-alert-triangle.svg' | ||
import { ReactComponent as BugScanner } from '../../assets/icons/scanner.svg' | ||
import AdvancedConfigOptions from './AdvancedConfigOptions' | ||
|
@@ -13,19 +13,24 @@ import { pipelineContext } from '../workflowEditor/workflowEditor' | |
export function Build({ | ||
showFormError, | ||
isAdvanced, | ||
ciPipeline, | ||
ciPipeline, | ||
pageState, | ||
isSecurityModuleInstalled, | ||
setDockerConfigOverridden, | ||
isJobView, | ||
getPluginData, | ||
setCIPipeline, | ||
isJobCI, | ||
isGitRequired, | ||
setIsGitRequired | ||
}: BuildType) { | ||
const { | ||
formData, | ||
setFormData, | ||
formDataErrorObj, | ||
setFormDataErrorObj, | ||
} = useContext(pipelineContext) | ||
|
||
const validationRules = new ValidationRules() | ||
const handleSourceChange = (event, gitMaterialId: number, sourceType: string): void => { | ||
const _formData = { ...formData } | ||
|
@@ -169,23 +174,25 @@ export function Build({ | |
onWebhookConditionSelectorChange: onWebhookConditionSelectorChange, | ||
onWebhookConditionSelectorValueChange: onWebhookConditionSelectorValueChange, | ||
} | ||
|
||
return ( | ||
<> | ||
{isAdvanced && renderPipelineName()} | ||
<SourceMaterials | ||
showError={showFormError} | ||
validationRules={validationRules} | ||
materials={formData.materials} | ||
selectSourceType={selectSourceType} | ||
handleSourceChange={handleSourceChange} | ||
includeWebhookEvents={true} | ||
ciPipelineSourceTypeOptions={formData.ciPipelineSourceTypeOptions} | ||
webhookData={_webhookData} | ||
canEditPipeline={formData.ciPipelineEditable} | ||
isAdvanced={isAdvanced} | ||
handleOnBlur={handleOnBlur} | ||
/> | ||
{isJobCI && renderGitRepoToggle()} | ||
{((isJobCI && isGitRequired) || !isJobCI) && ( | ||
<SourceMaterials | ||
showError={showFormError} | ||
validationRules={validationRules} | ||
materials={formData.materials} | ||
selectSourceType={selectSourceType} | ||
handleSourceChange={handleSourceChange} | ||
includeWebhookEvents={true} | ||
ciPipelineSourceTypeOptions={formData.ciPipelineSourceTypeOptions} | ||
webhookData={_webhookData} | ||
canEditPipeline={formData.ciPipelineEditable} | ||
isAdvanced={isAdvanced} | ||
handleOnBlur={handleOnBlur} | ||
/> | ||
)} | ||
</> | ||
) | ||
} | ||
|
@@ -223,6 +230,28 @@ export function Build({ | |
) | ||
} | ||
|
||
const renderGitRepoToggle = () => { | ||
return ( | ||
<div className="mb-16 dc__border-top-n1 pt-16"> | ||
<div className="fs-13 fw-6 cn-9 lh-20 flexbox dc__content-space dc__align-items-center"> | ||
<div>Pull code from git respository</div> | ||
<div className="w-32 h-20"> | ||
<Toggle | ||
selected={isGitRequired} | ||
onSelect={() => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please extract this method out. |
||
setIsGitRequired(!isGitRequired) | ||
setCIPipeline({ ...ciPipeline, isGitRequired: !isGitRequired }) | ||
}} | ||
/> | ||
</div> | ||
</div> | ||
<div className="cn-7 fs-13 lh-18 fw-4"> | ||
When enabled, Devtron pulls code from the git repository which can be used by tasks in this pipeline | ||
</div> | ||
</div> | ||
) | ||
} | ||
|
||
const renderScanner = () => { | ||
return ( | ||
<> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -110,6 +110,7 @@ export default function CIPipeline({ | |
const [isSecurityModuleInstalled, setSecurityModuleInstalled] = useState<boolean>(false) | ||
const [selectedEnv, setSelectedEnv] = useState<Environment>() | ||
const [environments, setEnvironments] = useState([]) | ||
const [isGitRequired, setIsGitRequired] = useState<boolean>(true) | ||
const [formData, setFormData] = useState<PipelineFormType>({ | ||
name: '', | ||
args: [], | ||
|
@@ -181,6 +182,11 @@ export default function CIPipeline({ | |
const [isDockerConfigOverridden, setDockerConfigOverridden] = useState(false) | ||
const [mandatoryPluginData, setMandatoryPluginData] = useState<MandatoryPluginDataType>(null) | ||
const selectedBranchRef = useRef(null) | ||
|
||
useEffect(() => { | ||
setIsGitRequired(ciPipeline?.isGitRequired ?? true) | ||
}, [ciPipeline]) | ||
|
||
|
||
const mandatoryPluginsMap: Record<number, MandatoryPluginDetailType> = useMemo(() => { | ||
const _mandatoryPluginsMap: Record<number, MandatoryPluginDetailType> = {} | ||
|
@@ -561,6 +567,7 @@ export default function CIPipeline({ | |
ciPipelineType = CIPipelineBuildType.CI_EXTERNAL | ||
} else if (isJobCI) { | ||
ciPipelineType = CIPipelineBuildType.CI_JOB | ||
_ciPipeline.isGitRequired = isGitRequired | ||
} | ||
_ciPipeline.pipelineType = ciPipeline.id ? ciPipeline.pipelineType : ciPipelineType | ||
} | ||
|
@@ -577,6 +584,8 @@ export default function CIPipeline({ | |
false, | ||
formData.webhookConditionList, | ||
formData.ciPipelineSourceTypeOptions, | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please remove this unnecessary space |
||
|
||
) | ||
.then((response) => { | ||
if (response) { | ||
|
@@ -606,6 +615,8 @@ export default function CIPipeline({ | |
validationRules.sourceValue(mat.regex || mat.value, mat.type !== SourceTypeMap.WEBHOOK).isValid | ||
return isValid | ||
}, true) | ||
const skipValidationForGitNotRequired = isJobCI && !isGitRequired | ||
valid = valid || skipValidationForGitNotRequired | ||
if (_formData.materials.length > 1) { | ||
const _isWebhook = _formData.materials.some((_mat) => _mat.type === SourceTypeMap.WEBHOOK) | ||
if (_isWebhook) { | ||
|
@@ -814,7 +825,11 @@ export default function CIPipeline({ | |
setDockerConfigOverridden={setDockerConfigOverridden} | ||
isJobView={isJobCard} | ||
getPluginData={getPluginData} | ||
/> | ||
setCIPipeline={setCIPipeline} | ||
isJobCI={isJobCI} | ||
isGitRequired={isGitRequired} | ||
setIsGitRequired={setIsGitRequired} | ||
/> | ||
</Route> | ||
<Redirect to={`${path}/build`} /> | ||
</Switch> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ export interface CIPipeline { | |
parentCiPipeline: number | ||
parentAppId: number | ||
pipelineType: string | ||
isGitRequired: boolean | ||
} | ||
export interface BuildDetails { | ||
triggerHistory: Map<number, History> | ||
|
@@ -20,6 +21,7 @@ export interface BuildDetails { | |
tagsEditable: boolean | ||
hideImageTaggingHardDelete: boolean | ||
fetchIdData: FetchIdDataStatus | ||
pipeline:CIPipeline | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please format this line |
||
} | ||
|
||
export interface HistoryLogsType { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -156,7 +156,6 @@ export function processWorkflow( | |
) | ||
const appName = workflow.appName | ||
let workflows = new Array<WorkflowType>() | ||
|
||
//populate workflows with CI and CD nodes, sourceNodes are inside CI nodes and PreCD and PostCD nodes are inside CD nodes | ||
workflow.workflows | ||
?.sort((a, b) => a.id - b.id) | ||
|
@@ -219,7 +218,6 @@ export function processWorkflow( | |
if (dimensions.type == WorkflowDimensionType.TRIGGER) { | ||
workflows = workflows.filter((wf) => wf.nodes.length > 0) | ||
} | ||
|
||
addDimensions(workflows, workflowOffset, dimensions) | ||
return { appName, workflows, filteredCIPipelines } | ||
} | ||
|
@@ -234,7 +232,6 @@ function addDimensions(workflows: WorkflowType[], workflowOffset: Offset, dimens | |
if (workflow.nodes.length == 0) { | ||
return | ||
} | ||
|
||
const ciNode = workflow.nodes.find( | ||
(node) => node.type == WorkflowNodeType.CI || node.type == WorkflowNodeType.WEBHOOK, | ||
) | ||
|
@@ -443,7 +440,8 @@ function ciPipelineToNode(ciPipeline: CiPipeline, dimensions: WorkflowDimensions | |
isRegex: ciMaterial?.isRegex, | ||
primaryBranchAfterRegex: ciMaterial?.source?.value, | ||
cipipelineId: ciMaterial?.id, | ||
isJobCI: ciPipeline?.pipelineType === CIPipelineBuildType.CI_JOB | ||
isJobCI: ciPipeline?.pipelineType === CIPipelineBuildType.CI_JOB, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can remove the optional check |
||
isGitRequired: ciPipeline?.isGitRequired | ||
} as NodeAttr | ||
}) | ||
let trigger = ciPipeline.isManual ? TriggerType.Manual.toLocaleLowerCase() : TriggerType.Auto.toLocaleLowerCase() | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we can write it as
{(!isJobCI || isGitRequired) && (