launchdarkly / ld-find-code-refs

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

Error parsing git tag name when tag is annotated #329

Closed kaarla closed 1 year ago

kaarla commented 1 year ago

I'm getting this error, but only when I use annotated tags:

INFO: 2023/02/10 16:17:10 coderefs.go:27: absolute directory path: /repo
DEBUG: 2023/02/10 16:17:10 git.go:105: identified branch name: HEAD
ERROR: 2023/02/10 16:17:10 coderefs.go:37: error parsing git tag name: git repo at /repo must be checked out to a valid branch or tag, or --branch option must be set

This is how the call looks like:

ld-find-code-refs \
  --debug=true \
  --accessToken=${LD_ACCESS_TOKEN} \
  --projKey=default \
  --ignoreServiceErrors=false \
  --lookback=10 \
  --contextLines=2 \
  --baseUri=https://app.launchdarkly.com \
  --repoType=github \
  --repoUrl=https://github.com/particle-iot-inc/workerd \
  --defaultBranch=main \
  --allowTags=true \
  --commitUrlTemplate= \
  --hunkUrlTemplate= \
  --repoName=${CIRCLE_PROJECT_REPONAME} \
  --updateSequenceId=${CIRCLE_BUILD_NUM} \
  --dir=/repo \
  --userAgent="circle-ci"

I checked in the source code and never gets to this point: https://github.com/launchdarkly/ld-find-code-refs/blob/4cbe7a942bfd2474c7522ae71311681054281c05/internal/git/git.go#L138

But it returns this message, which means it's not getting an error in the tagName() function: https://github.com/launchdarkly/ld-find-code-refs/blob/4cbe7a942bfd2474c7522ae71311681054281c05/internal/git/git.go#L92

Checking the go-git library, don't find strong proofs to say that the function to retrieve or iterate over tags is only taking the lightweight tags, but the tests I made point to that. This is how my tags look like, 10 and 12 are the ones that work and the difference is those are lightweight while 9 and 11 are annotated:

[redacted hash] tag refs/tags/8.3.9 [redacted hash] commit refs/tags/8.3.10 [redacted hash] tag refs/tags/8.3.11 [redacted hash] commit refs/tags/8.3.12

jazanne commented 1 year ago

@kaarla Sorry for the inconvenience, we'll look into this issue.

In the meantime can you try running with v2.5.7 and let me know if you still see this issue?

kaarla commented 1 year ago

Hello!

It worked with both kind of tags, this is call and output:

ld-find-code-refs \
>   --debug=true \
>   --accessToken=${LD_ACCESS_TOKEN} \
>   --projKey=default \
>   --ignoreServiceErrors=false \
>   --lookback=10 \
>   --contextLines=2 \
>   --baseUri=https://app.launchdarkly.com \
>   --repoType=github \
>   --repoUrl=https://github.com/particle-iot-inc/workerd \
>   --defaultBranch=main \
>   --allowTags=true \
>   --commitUrlTemplate= \
>   --hunkUrlTemplate= \
>   --repoName=${CIRCLE_PROJECT_REPONAME} \
>   --updateSequenceId=${CIRCLE_BUILD_NUM} \
>   --dir=/repo
INFO: 2023/02/16 21:20:08 coderefs.go:28: absolute directory path: /repo
DEBUG: 2023/02/16 21:20:08 git.go:102: identified branch name: HEAD
DEBUG: 2023/02/16 21:20:08 git.go:120: identified tag name: 8.3.11
INFO: 2023/02/16 21:20:08 git.go:47: git tag: 8.3.11
DEBUG: 2023/02/16 21:20:08 git.go:132: identified head sha: e1082c3ebfef067083b8fc7807764c5df0bc7dd7
DEBUG: 2023/02/16 21:20:08 client.go:551: [DEBUG] GET https://app.launchdarkly.com/api/v2/code-refs/repositories/workerd
                     FLAG                     | # REFERENCES  
----------------------------------------------+---------------
  device-service-enable-product-subscriptions |            1  
  Other flags                                 |            0  
INFO: 2023/02/16 21:20:08 coderefs.go:151: sending 1 code references across 141 flags and 1 files to LaunchDarkly for project(s): [ default]
DEBUG: 2023/02/16 21:20:08 client.go:551: [DEBUG] PUT https://app.launchdarkly.com/api/v2/code-refs/repositories/[my-repo]/branches/8.3.11
INFO: 2023/02/16 21:20:09 coderefs.go:186: checking if 140 flags without references were removed in the last 10 commits for project: default
INFO: 2023/02/16 21:20:17 coderefs.go:191: found 0 removed flags
INFO: 2023/02/16 21:20:17 coderefs.go:203: attempting to prune old code reference data from LaunchDarkly
DEBUG: 2023/02/16 21:20:17 git.go:162: found 20 branches on remote
DEBUG: 2023/02/16 21:20:17 client.go:551: [DEBUG] GET https://app.launchdarkly.com/api/v2/code-refs/repositories/workerd/branches
INFO: 2023/02/16 21:20:17 coderefs.go:114: found 0 stale branches to be marked for code reference pruning
jazanne commented 1 year ago

@kaarla thanks for submitting this issue. There is a fix available in https://github.com/launchdarkly/find-code-references/releases/tag/v2.10.0

kaarla commented 1 year ago

I just checked and it works 👍 Thank you!