Skip to content
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

feat: Git optional in CI job pipeline #1505

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"private": true,
"homepage": "/dashboard",
"dependencies": {
"@devtron-labs/devtron-fe-common-lib": "0.0.41",
"@devtron-labs/devtron-fe-common-lib": "0.0.42-beta-2",
"@sentry/browser": "^7.3.1",
"@sentry/integrations": "^7.3.1",
"@sentry/tracing": "^7.3.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ export default function EnvCIDetails({ filteredAppIds }: AppGroupDetailDefaultTy
hideImageTaggingHardDelete={hideImageTaggingHardDelete}
fetchIdData={fetchBuildIdData}
isJobCI={pipeline.pipelineType === CIPipelineBuildType.CI_JOB}
pipeline={pipeline}
/>
</Route>
)
Expand Down
63 changes: 46 additions & 17 deletions src/components/CIPipelineN/Build.tsx
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'
Expand All @@ -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 }
Expand Down Expand Up @@ -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
Copy link
Contributor

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) && (

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}
/>
)}
</>
)
}
Expand Down Expand Up @@ -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={() => {
setIsGitRequired(!isGitRequired)
Copy link
Contributor

Choose a reason for hiding this comment

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

Please extract this method out.

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 (
<>
Expand Down
17 changes: 16 additions & 1 deletion src/components/CIPipelineN/CIPipeline.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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: [],
Expand Down Expand Up @@ -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> = {}
Expand Down Expand Up @@ -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
}
Expand All @@ -577,6 +584,8 @@ export default function CIPipeline({
false,
formData.webhookConditionList,
formData.ciPipelineSourceTypeOptions,

Copy link
Contributor

Choose a reason for hiding this comment

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

Please remove this unnecessary space


)
.then((response) => {
if (response) {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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>
Expand Down
27 changes: 16 additions & 11 deletions src/components/app/details/cIDetails/CIDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,8 @@ export default function CIDetails({ isJobView, filteredEnvIds }: { isJobView?: b
hideImageTaggingHardDelete={hideImageTaggingHardDelete}
fetchIdData={fetchBuildIdData}
isJobCI={pipeline.pipelineType === CIPipelineBuildType.CI_JOB}
pipeline={pipeline}

/>
</Route>
) : pipeline.parentCiPipeline || pipeline.pipelineType === 'LINKED' ? (
Expand Down Expand Up @@ -268,6 +270,7 @@ export const Details = ({
appReleaseTags,
hideImageTaggingHardDelete,
fetchIdData,
pipeline
}: BuildDetails) => {
const isJobCard: boolean = isJobView || isJobCI
const { pipelineId, appId, buildId } = useParams<{ appId: string; buildId: string; pipelineId: string }>()
Expand Down Expand Up @@ -386,17 +389,19 @@ export const Details = ({
Logs
</NavLink>
</li>
<li className="tab-list__tab">
<NavLink
replace
className="tab-list__tab-link"
activeClassName="active"
to={`source-code`}
data-testid="source-code-link"
>
Source
</NavLink>
</li>
{isJobCI && pipeline.isGitRequired && (
<li className="tab-list__tab">
<NavLink
replace
className="tab-list__tab-link"
activeClassName="active"
to={`source-code`}
data-testid="source-code-link"
>
Source
</NavLink>
</li>
)}
<li className="tab-list__tab">
<NavLink
replace
Expand Down
2 changes: 2 additions & 0 deletions src/components/app/details/cIDetails/types.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export interface CIPipeline {
parentCiPipeline: number
parentAppId: number
pipelineType: string
isGitRequired: boolean
}
export interface BuildDetails {
triggerHistory: Map<number, History>
Expand All @@ -20,6 +21,7 @@ export interface BuildDetails {
tagsEditable: boolean
hideImageTaggingHardDelete: boolean
fetchIdData: FetchIdDataStatus
pipeline:CIPipeline
Copy link
Contributor

Choose a reason for hiding this comment

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

Please format this line

}

export interface HistoryLogsType {
Expand Down
1 change: 1 addition & 0 deletions src/components/app/details/triggerView/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -532,6 +532,7 @@ export interface CiPipeline {
}
isOffendingMandatoryPlugin?: boolean
pipelineType?: string
isGitRequired?: boolean
}

export interface Material {
Expand Down
6 changes: 2 additions & 4 deletions src/components/app/details/triggerView/workflow.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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 }
}
Expand All @@ -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,
)
Expand Down Expand Up @@ -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,
Copy link
Contributor

Choose a reason for hiding this comment

The 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()
Expand Down
2 changes: 2 additions & 0 deletions src/components/ciPipeline/ciPipeline.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,8 @@ function parseCIResponse(
ciPipeline: ciPipeline,
form: {
name: ciPipeline.name,
pipelineType: ciPipeline.pipelineType,
isGitRequired: ciPipeline.isGitRequired,
triggerType: ciPipeline.isManual ? TriggerType.Manual : TriggerType.Auto,
materials: materials,
args: args.length ? args : [],
Expand Down
6 changes: 6 additions & 0 deletions src/components/ciPipeline/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,7 @@ export interface CIPipelineDataType {
environmentId?: any
pipelineType?: string
customTag?: CustomTagType
isGitRequired?: boolean
}
export interface CIPipelineState {
code: number
Expand Down Expand Up @@ -367,6 +368,7 @@ export interface SourceMaterialsProps {
isBranchRegex?: (material) => boolean
isAdvanced?: boolean
handleOnBlur?: (event) => void
isGitRequired?: boolean
}

export interface WebhookCIProps {
Expand All @@ -389,6 +391,10 @@ export interface BuildType {
setDockerConfigOverridden: React.Dispatch<React.SetStateAction<boolean>>
isJobView?: boolean
getPluginData: (_formData?: PipelineFormType) => void
setCIPipeline: React.Dispatch<React.SetStateAction<CIPipelineDataType>>
isJobCI?: boolean
isGitRequired?: boolean
setIsGitRequired?: React.Dispatch<React.SetStateAction<boolean>>
}

export interface PreBuildType {
Expand Down
Loading
Loading