Skip to main content

Default Push Policy Options In Stack Settings

Would like to add a selection when creating and editing stack settings that allows for users to control what triggers proposed runs when no push policy is attached.

  • Push file changes or PR diff (current behavior, stays the default)

  • PR diff only, so proposed runs reflect the files shown in the pull request

Tracked runs are unaffected: they continue to be based on the files in the push to the stack’s tracked branch. If a push policy is attached, it replaces the default behavior as it does today, and the setting has no effect. The UI should say so next to the setting.

Workaround
Problem
Status: 🔭 Discovery1 comment

Log in to comment and vote

Comments1

  • Green Rice

    •

    Oct 30

    We fixed this issue with a PR policy based on the one in https://support.spacelift.io/articles/9908339044-why-a-pull-request-triggers-runs-on-stacks-it-doesn-t-touch?lang=en but had to change the startswith(normalize_path(filepath), normalize_path(input.stack.project_root)) line bc it was matching unrelated stacks with the same first characters as another folder (e.g. the stack in our-data/ would get triggered for changes in our-datadog/. This is the updated policy that corrects that behavior:

    package spacelift
    
    track if {
      affected
      input.push.branch == input.stack.branch
    }
    
    # Proposed runs come from the PR diff only, not the full push file list.
    propose if affected_pr
    
    ignore if {
      not affected
      not affected_pr
    }
    
    ignore if input.push.tag != ""
    
    affected if {
      some filepath in input.push.affected_files
      in_project_root(normalize_path(filepath))
    }
    
    affected if {
      some filepath in input.push.affected_files
      some glob_pattern in input.stack.additional_project_globs
      glob.match(glob_pattern, ["/"], normalize_path(filepath))
    }
    
    affected_pr if {
      some filepath in input.pull_request.diff
      in_project_root(normalize_path(filepath))
    }
    
    affected_pr if {
      some filepath in input.pull_request.diff
      some glob_pattern in input.stack.additional_project_globs
      glob.match(glob_pattern, ["/"], normalize_path(filepath))
    }
    
    normalize_path(path) := trim(path, "/")
    
    project_root := normalize_path(input.stack.project_root)
    
    in_project_root(_) if project_root == ""
    
    in_project_root(path) if startswith(path, concat("", [project_root, "/"]))
    
    sample if true