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

fix: do not consider implicit dependencies from action references in dead code branches #6862

Merged
merged 5 commits into from
Feb 19, 2025

Conversation

stefreak
Copy link
Member

@stefreak stefreak commented Feb 18, 2025

What this PR does / why we need it:
This PR changes getContextLookupReferences to ignore dead code
branches

Which issue(s) this PR fixes:

Fixes an issue where we considered implicit dependencies from action references in dead code branches.

Addititional info:

There was an alternate solution attempt, here: #6849

One of the benefits of the approach of detecting dead branches is that it now also works with logical AND (&&), logical OR (||), ternary expressions (? :) and if block expressions (${if ...}) and not just with structural if operators ($if: yaml keys).

Example / minimal repro:

kind: Project
apiVersion: garden.io/v1
name: test
environments:
 - name: local
variables:
 disabled: ${true}
---
kind: Run
type: exec
name: myrun
spec:
  command: [echo, "${ !var.disabled ? actions.deploy.mydeploy.outputs.logs : '<not executed>'}"]
---
kind: Deploy
type: exec
name: mydeploy
disabled: ${var.disabled}
spec:
  deployCommand: [echo, "${var.disabled ? 'I should not run' : 'I should run'}"]

Command: garden run myrun
Expected behaviour: the deploy "mydeploy" should not be executed.

The docs for the disabled flag do not reflect the current behaviour where we execute disabled actions, if another action references one of their outputs. This is a separate issue that will be dealt with in a separate PR.

@stefreak
Copy link
Member Author

Alternative approach for #6849

Copy link
Collaborator

@twelvemo twelvemo left a comment

Choose a reason for hiding this comment

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

This is great work and a real fun read! Together with the good test coverage this really looks good to go!

return this.getChildren()
}

const activeBranch = isTruthy(condition) ? this.consequent : this.alternate
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is some smart reasoning!

Copy link
Member Author

Choose a reason for hiding this comment

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

Hahah!

},
]
for (const testCase of branchTestCases) {
it(`correctly avoids dead code branches (test case: ${testCase.name})`, () => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

super nice to cover all these test cases!

@eysi09
Copy link
Collaborator

eysi09 commented Feb 19, 2025

This is great work and a real fun read! Together with the good test coverage this really looks good to go!

Agreed! Was still reading through it but childrenEligibleForRecursion made me smile. And also agree that it's good to go!

@stefreak stefreak added this pull request to the merge queue Feb 19, 2025
Merged via the queue into main with commit b4ee791 Feb 19, 2025
40 checks passed
@stefreak stefreak deleted the avoid-dead-code-branches branch February 19, 2025 16:29
@stefreak stefreak mentioned this pull request Feb 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants