launchdarkly / ld-find-code-refs

Build tool for automatically sending feature flag code references to LaunchDarkly
https://launchdarkly.com
Other
45 stars 34 forks source link

Issue: sending 0 code references across 313 flags and 0 files to LaunchDarkly for project(s): #393

Closed jmgawecki closed 9 months ago

jmgawecki commented 9 months ago

Scan succeeds but finds no references.

Our yaml file:

name: Find LaunchDarkly flag code references
on:
  push:
    branches:
      - develop
      - story/IT-736
# cancel in-flight workflow run if another push was triggered
concurrency:
  group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
  cancel-in-progress: true
jobs:
  launchDarklyCodeReferences:
    name: LaunchDarkly Code References
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
        with:
          fetch-depth: 11 # This value must be set if the lookback configuration option is not disabled for find-code-references. Read more: https://github.com/launchdarkly/ld-find-code-refs#searching-for-unused-flags-extinctions
      - name: LaunchDarkly Code References
        uses: launchdarkly/find-code-references@v2.10.0
        with:
          accessToken: ${{ secrets.LD_ACCESS_TOKEN }}
          projKey: default
          default_branch: story/IT-736

Result of the scan:

INFO: 2023/10/02 15:06:01 coderefs.go:148: sending 0 code references across 313 flags and 0 files to LaunchDarkly for project(s): [ default]

The very same configuration on our Android project works just fine, finds reference and sends them to LD UI. I've checked the gitignore file as I've seen that entry .* may cause some issues but it's not the case for us.

Thanks for help

jazanne commented 9 months ago

@jmgawecki thanks for reaching out - can you share the configuration you're using in .launchdarkly/coderefs.yml file?

jmgawecki commented 9 months ago

Hey there, thanks for getting back. Would you be able to guide me where do I find this directory? Is it in the project?

jazanne commented 9 months ago

It's optional, but it you have it, it should be part of project repo. Here is more information about configuration https://github.com/launchdarkly/ld-find-code-refs/blob/main/docs/CONFIGURATION.md#yaml

If you don't see one that exists, my guess is that you may need some aliases configured to find your flag keys.

Can you share an example of what one of your flag's look like in the code? (variable name / format etc.)

jmgawecki commented 9 months ago

Flags are kept in the enum as such (Swift):

public enum FeatureFlag: String, CaseIterable, Codable {
     case FIRST_FEATURE_FLAG
     case SECOND_FEATURE_FLAG
}
jmgawecki commented 9 months ago

The only file I added is .../Project/.github/workflows/action.yaml

jazanne commented 9 months ago

Thanks for sharing, as long as your FIRST_FEATURE_FLAG matches the flag key in LD (for example, "first-feature-flag", it seems you'll need to configure aliases in ...Project/.launchdarkly/coderefs.yaml like this:

aliases:
     - type: uppersnakecase
jmgawecki commented 9 months ago

Thanks, I've checked the LD and flags there and what's defined here are a perfect match, for ex: FIRST_FEATURE_FLAG in LD is exactly the same on the client FIRST_FEATURE_FLAG.

In that case, do I understand it correctly that aliases should not be needed?

jazanne commented 9 months ago

The way that our flag key scanning works means that we look for matches of the KEY surrounded by delimiters like so, "KEY"

Since your usage uses the KEY without quotes, it needs the uppersnakecase alias to find the match (aliases don't require delimiters`.

Another option is to disable delimiter matching in your configuration like

delimiters:
  disableDefaults: true

Please let me know if either of those options work

jmgawecki commented 9 months ago

I found the solution. When explicitly writing down the raw value, LD finds it. As en example:

public enum FeatureFlag: String, CaseIterable, Codable {
     case FIRST_FEATURE_FLAG = "FIRST_FEATURE_FLAG" // finds it
     case SECOND_FEATURE_FLAG // will not find it
}

Is this potentially a bug?

jazanne commented 9 months ago

This is expected behavior - Here are some tests that demonstrate the behavior you're seeing https://github.com/launchdarkly/ld-find-code-refs/pull/395

jmgawecki commented 9 months ago

This solved the issue! Thanks

jmgawecki commented 9 months ago

Issue has been resolved by disabling delimiters

jazanne commented 9 months ago

Glad we were able to come to resolution!