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

[sc-223067] allow branch pruning to be disabled in main job #405

Merged
Merged
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
1 change: 1 addition & 0 deletions build/metadata/github-actions/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,5 @@ If the action fails, there may be a problem with your configuration. To investig
| lookback | Set the number of commits to search in history for whether you removed a feature flag from code. You may set to 0 to disable this feature. Setting this option to a high value will increase search time. | `false` | 10 |
| projKey | Key of the LaunchDarkly project associated with this repository. Found under Account Settings -> Projects in the LaunchDarkly dashboard. Cannot be combined with `projects` block in configuration file. | `false` | |
| repoName | The repository name. Defaults to the current GitHub repository. | `false` | |
| prune | There is a known issue where the GitHub Action will not prune deleted branch data in private repos. Only enable this if you are running the action in a public repo. | `false` | false |
<!-- action-docs-inputs -->
5 changes: 5 additions & 0 deletions build/metadata/github-actions/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ inputs:
repoName:
description: "The repository name. Defaults to the current GitHub repository."
required: false
prune:
default: "false"
description: "There is a known issue where the GitHub Action will not prune deleted branch data in private repos. Only enable this if you are running the action in a public repo."
required: false
runs:
using: 'docker'
image: 'Dockerfile'
Expand All @@ -51,3 +55,4 @@ runs:
LD_DEBUG: ${{ inputs.debug }}
LD_IGNORE_SERVICE_ERRORS: ${{ inputs.ignoreServiceErrors }}
LD_LOOKBACK: ${{ inputs.lookback }}
LD_PRUNE: ${{ inputs.prune }}
10 changes: 4 additions & 6 deletions coderefs/coderefs.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,7 @@ func generateHunkOutput(opts options.Options, matcher search.Matcher, branch ld.
}

func runExtinctions(opts options.Options, matcher search.Matcher, branch ld.BranchRep, repoParams ld.RepoParams, gitClient *git.Client, ldApi ld.ApiClient) {
lookback := opts.Lookback
dryRun := opts.DryRun
if lookback > 0 {
if opts.Lookback > 0 {
var removedFlags []ld.ExtinctionRep

flagCounts := branch.CountByProjectAndFlag(matcher.GetElements(), opts.GetProjectKeys())
Expand All @@ -180,22 +178,22 @@ func runExtinctions(opts options.Options, matcher search.Matcher, branch ld.Bran
}
}
log.Info.Printf("checking if %d flags without references were removed in the last %d commits for project: %s", len(missingFlags), opts.Lookback, project.Key)
removedFlagsByProject, err := gitClient.FindExtinctions(project, missingFlags, matcher, lookback+1)
removedFlagsByProject, err := gitClient.FindExtinctions(project, missingFlags, matcher, opts.Lookback+1)
if err != nil {
log.Warning.Printf("unable to generate flag extinctions: %s", err)
} else {
log.Info.Printf("found %d removed flags", len(removedFlagsByProject))
}
removedFlags = append(removedFlags, removedFlagsByProject...)
}
if len(removedFlags) > 0 && !dryRun {
if len(removedFlags) > 0 && !opts.DryRun {
err := ldApi.PostExtinctionEvents(removedFlags, repoParams.Name, branch.Name)
if err != nil {
log.Error.Printf("error sending extinction events to LaunchDarkly: %s", err)
}
}
}
if !dryRun {
if !opts.DryRun && opts.Prune {
log.Info.Printf("attempting to prune old code reference data from LaunchDarkly")
remoteBranches, err := gitClient.RemoteBranches()
if err != nil {
Expand Down
7 changes: 6 additions & 1 deletion docs/CONFIGURATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,19 +44,22 @@ Flags:
-B, --defaultBranch string The default branch. The LaunchDarkly UI will default to this branch. If not provided, will fallback to 'main'. (default "main")

-d, --dir string Path to existing checkout of the repository.

--dryRun If enabled, the scanner will run without sending code references to LaunchDarkly. Combine with the outDir option to output code references to a CSV.

-h, --help help for ld-find-code-refs

--hunkUrlTemplate string If provided, LaunchDarkly will attempt to generate links to your VCS service provider per code reference. Example: https://github.com/launchdarkly/ld-find-code-refs/blob/${sha}/${filePath}#L${lineNumber}. Allowed template variables: 'sha', 'filePath', 'lineNumber'. If "hunkUrlTemplate" is not provided, but "repoUrl" is provided and "repoType" is not custom, LaunchDarkly will attempt to automatically generate source code links for the given "repoType".

-i, --ignoreServiceErrors If enabled, the scanner will terminate with exit code 0 when the LaunchDarkly API is unreachable or returns an unexpected response.

-l, --lookback int Sets the number of git commits to search in history for whether a feature flag was removed from code. May be set to 0 to disabled this feature. Setting this option to a high value will increase search time. (default 10)

-o, --outDir string If provided, will output a csv file containing all code references for the project to this directory.

-p, --projKey string LaunchDarkly project key. Found under Account Settings -> Projects in the LaunchDarkly dashboard. Cannot be combined with "projects" block in configuration file.

--prune If enabled, branches that are not found in the remote repository will be deleted from LaunchDarkly. (default true)
jazanne marked this conversation as resolved.
Show resolved Hide resolved

-r, --repoName string Repository name. Will be displayed in LaunchDarkly. Case insensitive. Repository names must only contain letters, numbers, '.', '_' or '-'."

-T, --repoType string The repo service provider. Used to correctly categorize repositories in the LaunchDarkly UI. Acceptable values: bitbucket|custom|github|gitlab. (default "custom")
Expand All @@ -67,6 +70,8 @@ Flags:

-s, --updateSequenceId int An integer representing the order number of code reference updates. Used to version updates across concurrent executions of the flag finder. If not provided, data will always be updated. If provided, data will only be updated if the existing "updateSequenceId" is less than the new "updateSequenceId". Examples: the time a "git push" was initiated, CI build number, the current unix timestamp. (default -1)

--userAgent string (Internal) Platform where code references is run.

-v, --version version for ld-find-code-refs
```

Expand Down
5 changes: 5 additions & 0 deletions options/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,11 @@ the project to this directory.`,
defaultValue: "",
usage: `LaunchDarkly project key. Found under Account Settings -> Projects in the LaunchDarkly dashboard. Cannot be combined with "projects" block in configuration file.`,
},
{
name: "prune",
defaultValue: true,
usage: `If enabled, branches that are not found in the remote repository will be deleted from LaunchDarkly.`,
},
{
name: "repoName",
short: "r",
Expand Down
3 changes: 2 additions & 1 deletion options/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,15 @@ type Options struct {
RepoType string `mapstructure:"repoType"`
RepoUrl string `mapstructure:"repoUrl"`
Revision string `mapstructure:"revision"`
UserAgent string `mapstructure:"userAgent"`
ContextLines int `mapstructure:"contextLines"`
Lookback int `mapstructure:"lookback"`
UpdateSequenceId int `mapstructure:"updateSequenceId"`
AllowTags bool `mapstructure:"allowTags"`
Debug bool `mapstructure:"debug"`
DryRun bool `mapstructure:"dryRun"`
IgnoreServiceErrors bool `mapstructure:"ignoreServiceErrors"`
UserAgent string `mapstructure:"userAgent"`
Prune bool `mapstructure:"prune"`

// The following options can only be configured via YAML configuration

Expand Down