Skip to content

Commit

Permalink
main sync develop
Browse files Browse the repository at this point in the history
  • Loading branch information
vikramdevtron committed Jan 13, 2025
2 parents 92b06d9 + 1f87c4a commit 671e015
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 19 deletions.
1 change: 1 addition & 0 deletions .github/semantic.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ types:
- doc
- release
- misc
- sync
31 changes: 21 additions & 10 deletions .github/workflows/pr-issue-validator.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ on:
- 'main'
- 'release-**'
- 'develop'
- 'hotfix-v0**'

jobs:
validate-PR-issue:
Expand All @@ -32,7 +33,7 @@ jobs:
run: |
set -x
# Skip validation for documentation or chore PRs
if [[ "$TITLE" =~ ^(doc:|docs:|chore:|misc:) ]]; then
if [[ "$TITLE" =~ ^(doc:|docs:|chore:|misc:|sync:) ]]; then
echo "Skipping validation for docs/chore PR."
echo "PR NUMBER-: $PRNUM "
gh pr edit $PRNUM --remove-label "PR:Issue-verification-failed"
Expand Down Expand Up @@ -105,21 +106,31 @@ jobs:
--header "authorization: Bearer ${{ secrets.GH_PR_VALIDATOR_TOKEN }}" \
"$issue_api_url" | jq '.state'|tr -d \")
# Check if the issue is still open.
if [[ "$issue_status" == open ]]; then
echo "Issue #$issue_num is opened."
# if [[ "$issue_status" == open ]]; then
# echo "Issue #$issue_num is opened."
if [[ $forked == true ]]; then
echo "PR:Ready-to-Review, exiting gracefully"
exit 0
fi
# Remove the 'Issue-verification-failed' label (if present) and add 'Ready-to-Review'.
gh pr edit $PRNUM --remove-label "PR:Issue-verification-failed"
gh pr edit $PRNUM --add-label "PR:Ready-to-Review"
else
echo "Issue #$issue_num is closed. Please link an open issue to proceed."
echo "PR:Ready-to-Review, exiting gracefully"
exit 0
# else
# echo "Issue #$issue_num is closed. Please link an open issue to proceed."
# if [[ $forked == true ]]; then
# echo "PR:Ready-to-Review, exiting gracefully"
# exit 0
# fi
# Add a comment to the PR indicating the issue is not linked correctly.
gh pr comment $PRNUM --body "PR is linked to a closed issue. Please link an open issue to proceed."
# gh pr comment $PRNUM --body "PR is linked to a closed issue. Please link an open issue to proceed."

# Add the 'Issue-verification-failed' label and remove 'Ready-to-Review'.
gh pr edit $PRNUM --add-label "PR:Issue-verification-failed"
gh pr edit $PRNUM --remove-label "PR:Ready-to-Review"
exit 1
fi
# gh pr edit $PRNUM --add-label "PR:Issue-verification-failed"
# gh pr edit $PRNUM --remove-label "PR:Ready-to-Review"
# exit 1
#fi
else
echo "Issue not found. Invalid URL or issue number."
# Add a comment to the PR indicating the issue is not linked correctly.
Expand Down
14 changes: 9 additions & 5 deletions ci-runner/executor/StageExecutor.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ type StageExecutorImpl struct {
}

type StageExecutor interface {
RunCiCdSteps(stepType helper.StepType, ciCdRequest *helper.CommonWorkflowRequest, steps []*helper.StepObject, refStageMap map[int][]*helper.StepObject, scriptEnvVariables *util2.ScriptEnvVariables, preCiStageVariable map[int]map[string]*commonBean.VariableObject) (pluginArtifacts *helper.PluginArtifacts, outVars map[int]map[string]*commonBean.VariableObject, failedStep *helper.StepObject, err error)
RunCiCdSteps(stepType helper.StepType, ciCdRequest *helper.CommonWorkflowRequest, steps []*helper.StepObject, refStageMap map[int][]*helper.StepObject, scriptEnvVariables *util2.ScriptEnvVariables, preCiStageVariable map[int]map[string]*commonBean.VariableObject, resetEnvVariable bool) (pluginArtifacts *helper.PluginArtifacts, outVars map[int]map[string]*commonBean.VariableObject, failedStep *helper.StepObject, err error)
RunCdStageTasks(ciContext cictx.CiContext, tasks []*helper.Task, scriptEnvVariables *util2.ScriptEnvVariables, stageType helper.PipelineType) error
}

Expand All @@ -48,7 +48,7 @@ func NewStageExecutorImpl(cmdExecutor helper.CommandExecutor, scriptExecutor Scr
}
}

func (impl *StageExecutorImpl) RunCiCdSteps(stepType helper.StepType, ciCdRequest *helper.CommonWorkflowRequest, steps []*helper.StepObject, refStageMap map[int][]*helper.StepObject, scriptEnvVariables *util2.ScriptEnvVariables, preCiStageVariable map[int]map[string]*commonBean.VariableObject) (*helper.PluginArtifacts, map[int]map[string]*commonBean.VariableObject, *helper.StepObject, error) {
func (impl *StageExecutorImpl) RunCiCdSteps(stepType helper.StepType, ciCdRequest *helper.CommonWorkflowRequest, steps []*helper.StepObject, refStageMap map[int][]*helper.StepObject, scriptEnvVariables *util2.ScriptEnvVariables, preCiStageVariable map[int]map[string]*commonBean.VariableObject, resetEnvVariable bool) (*helper.PluginArtifacts, map[int]map[string]*commonBean.VariableObject, *helper.StepObject, error) {
/*if stageType == STEP_TYPE_POST {
postCiStageVariable = make(map[int]map[string]*VariableObject) // [stepId]name[]value
}*/
Expand All @@ -65,7 +65,7 @@ func (impl *StageExecutorImpl) RunCiCdSteps(stepType helper.StepType, ciCdReques
)

executeStep := func() error {
refPluginArtifacts, failedStep, err = impl.RunCiCdStep(stepType, *ciCdRequest, i, step, refStageMap, scriptEnvVariables, preCiStageVariable, stageVariable)
refPluginArtifacts, failedStep, err = impl.RunCiCdStep(stepType, *ciCdRequest, i, step, refStageMap, scriptEnvVariables, preCiStageVariable, stageVariable, resetEnvVariable)
if err != nil {
return err
}
Expand Down Expand Up @@ -140,7 +140,7 @@ func getScriptVariables(step *helper.StepObject, scriptEnvVariables *util2.Scrip

func (impl *StageExecutorImpl) RunCiCdStep(stepType helper.StepType, ciCdRequest helper.CommonWorkflowRequest, index int, step *helper.StepObject,
refStageMap map[int][]*helper.StepObject, scriptEnvVariables *util2.ScriptEnvVariables, preCiStageVariable map[int]map[string]*commonBean.VariableObject,
stageVariable map[int]map[string]*commonBean.VariableObject) (artifacts *helper.PluginArtifacts, failedStep *helper.StepObject, err error) {
stageVariable map[int]map[string]*commonBean.VariableObject, resetEnvVariable bool) (artifacts *helper.PluginArtifacts, failedStep *helper.StepObject, err error) {
var vars []*commonBean.VariableObject
if stepType == helper.STEP_TYPE_REF_PLUGIN {
vars, err = deduceVariables(step.InputVars, scriptEnvVariables, nil, nil, stageVariable)
Expand Down Expand Up @@ -317,7 +317,7 @@ func (impl *StageExecutorImpl) RunCiCdStep(stepType helper.StepType, ciCdRequest
}
}
}
refPluginArtifacts, opt, _, err := impl.RunCiCdSteps(helper.STEP_TYPE_REF_PLUGIN, &ciCdRequest, steps, refStageMap, scriptEnvVariables, nil)
refPluginArtifacts, opt, _, err := impl.RunCiCdSteps(helper.STEP_TYPE_REF_PLUGIN, &ciCdRequest, steps, refStageMap, scriptEnvVariables, nil, false)
if err != nil {
fmt.Println(err)
return nil, step, err
Expand Down Expand Up @@ -358,6 +358,10 @@ func (impl *StageExecutorImpl) RunCiCdStep(stepType helper.StepType, ciCdRequest
finalOutVarMap[out.Name] = out
}
stageVariable[step.Index] = finalOutVarMap
// TODO Prakhar: test and restructure
if resetEnvVariable {
scriptEnvVariables = scriptEnvVariables.ResetExistingScriptEnv()
}
return pluginArtifacts, nil, nil
}

Expand Down
3 changes: 2 additions & 1 deletion ci-runner/executor/stage/cdStages.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,12 +191,13 @@ func (impl *CdStage) runCDStages(ciCdRequest *helper.CiCdTriggerEvent) (*helper.
scriptEnvs.SystemEnv["DEST"] = ciCdRequest.CommonWorkflowRequest.CiArtifactDTO.Image
scriptEnvs.SystemEnv["DIGEST"] = ciCdRequest.CommonWorkflowRequest.CiArtifactDTO.ImageDigest
var stage = helper.StepType(ciCdRequest.CommonWorkflowRequest.StageType)
pluginArtifacts, _, step, err := impl.stageExecutorManager.RunCiCdSteps(stage, ciCdRequest.CommonWorkflowRequest, ciCdRequest.CommonWorkflowRequest.PrePostDeploySteps, refStageMap, scriptEnvs, nil)
pluginArtifacts, _, step, err := impl.stageExecutorManager.RunCiCdSteps(stage, ciCdRequest.CommonWorkflowRequest, ciCdRequest.CommonWorkflowRequest.PrePostDeploySteps, refStageMap, scriptEnvs, nil, true)
if err != nil {
return allPluginArtifacts, helper.NewCdStageError(err).
WithFailureMessage(fmt.Sprintf(workFlow.CdStageTaskFailed.String(), ciCdRequest.CommonWorkflowRequest.GetCdStageType(), step.Name)).
WithArtifactUploaded(false)
}
scriptEnvs = scriptEnvs.ResetExistingScriptEnv()
allPluginArtifacts.MergePluginArtifact(pluginArtifacts)
} else {

Expand Down
9 changes: 6 additions & 3 deletions ci-runner/executor/stage/ciStages.go
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ func (impl *CiStage) runPreCiSteps(ciCdRequest *helper.CiCdTriggerEvent, metrics
log.Println("running PRE-CI steps")
}
// run pre artifact processing
_, preCiStageOutVariable, step, err := impl.stageExecutorManager.RunCiCdSteps(helper.STEP_TYPE_PRE, ciCdRequest.CommonWorkflowRequest, ciCdRequest.CommonWorkflowRequest.PreCiSteps, refStageMap, scriptEnvs, nil)
_, preCiStageOutVariable, step, err := impl.stageExecutorManager.RunCiCdSteps(helper.STEP_TYPE_PRE, ciCdRequest.CommonWorkflowRequest, ciCdRequest.CommonWorkflowRequest.PreCiSteps, refStageMap, scriptEnvs, nil, true)
preCiDuration := time.Since(start).Seconds()
if err != nil {
log.Println("error in running pre Ci Steps", "err", err)
Expand All @@ -344,6 +344,7 @@ func (impl *CiStage) runPreCiSteps(ciCdRequest *helper.CiCdTriggerEvent, metrics
WithFailureMessage(fmt.Sprintf(workFlow.PreCiFailed.String(), step.Name)).
WithArtifactUploaded(artifactUploaded)
}
scriptEnvs = scriptEnvs.ResetExistingScriptEnv()
// considering pull images from Container repo Plugin in Pre ci steps only.
// making it non-blocking if results are not available (in case of err)
resultsFromPlugin, fileErr := extractOutResultsIfExists()
Expand Down Expand Up @@ -371,7 +372,8 @@ func (impl *CiStage) runBuildArtifact(ciCdRequest *helper.CiCdTriggerEvent, metr
// build success will always be false
scriptEnvs.SystemEnv[util.ENV_VARIABLE_BUILD_SUCCESS] = "false"
// run post artifact processing
impl.stageExecutorManager.RunCiCdSteps(helper.STEP_TYPE_POST, ciCdRequest.CommonWorkflowRequest, postCiStepsToTriggerOnCiFail, refStageMap, scriptEnvs, preCiStageOutVariable)
impl.stageExecutorManager.RunCiCdSteps(helper.STEP_TYPE_POST, ciCdRequest.CommonWorkflowRequest, postCiStepsToTriggerOnCiFail, refStageMap, scriptEnvs, preCiStageOutVariable, true)
scriptEnvs = scriptEnvs.ResetExistingScriptEnv()
}
// code-block ends
err = helper.NewCiStageError(err).
Expand Down Expand Up @@ -416,14 +418,15 @@ func (impl *CiStage) runPostCiSteps(ciCdRequest *helper.CiCdTriggerEvent, script
scriptEnvs.SystemEnv["DEST"] = dest
scriptEnvs.SystemEnv["DIGEST"] = digest
// run post artifact processing
pluginArtifactsFromFile, _, step, err := impl.stageExecutorManager.RunCiCdSteps(helper.STEP_TYPE_POST, ciCdRequest.CommonWorkflowRequest, ciCdRequest.CommonWorkflowRequest.PostCiSteps, refStageMap, scriptEnvs, preCiStageOutVariable)
pluginArtifactsFromFile, _, step, err := impl.stageExecutorManager.RunCiCdSteps(helper.STEP_TYPE_POST, ciCdRequest.CommonWorkflowRequest, ciCdRequest.CommonWorkflowRequest.PostCiSteps, refStageMap, scriptEnvs, preCiStageOutVariable, true)
if err != nil {
log.Println("error in running Post Ci Steps", "err", err)
return nil, nil, helper.NewCiStageError(err).
WithMetrics(metrics).
WithFailureMessage(fmt.Sprintf(workFlow.PostCiFailed.String(), step.Name)).
WithArtifactUploaded(artifactUploaded)
}
scriptEnvs = scriptEnvs.ResetExistingScriptEnv()
//sent by orchestrator if copy container image v2 is configured

// considering pull images from Container repo Plugin in post ci steps also.
Expand Down
5 changes: 5 additions & 0 deletions ci-runner/executor/util/envUtils.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ type ScriptEnvVariables struct {
ExistingScriptEnv map[string]string
}

func (s *ScriptEnvVariables) ResetExistingScriptEnv() *ScriptEnvVariables {
s.ExistingScriptEnv = make(map[string]string)
return s
}

func getRuntimeEnvVariables(ciCdRequest *helper.CiCdTriggerEvent) map[string]string {
if ciCdRequest.CommonWorkflowRequest.RuntimeEnvironmentVariables == nil {
return make(map[string]string)
Expand Down

0 comments on commit 671e015

Please # to comment.