Coder Social home page Coder Social logo

launchdarkly / find-code-references Goto Github PK

View Code? Open in Web Editor NEW
58.0 41.0 17.0 61 KB

Find references to feature flags in your code

Home Page: https://docs.launchdarkly.com/home/code/github-actions

Dockerfile 100.00%
launchdarkly-docker-image managed-by-terraform action github-action github-actions launchdarkly launchdarkly-integration

find-code-references's Issues

Action Can't Execute Alias Command File

I have the action setup and working, however I needed to be able to provide aliases for it. I setup a .launchdarkly/coderefs.yaml file with the following contents:

aliases:
    - type: command
      command: .launchdarkly/flagAlias.sh

And a file in the same folder called flagAlias.sh with the following contents:

#! /bin/sh
read flagKey <&0; echo "[\"FeatureFlags.$flagKey\", \"'$flagKey'\", \"\\\"$flagKey\\\"\"]"

When I run this locally via the CLI in Ubuntu, ld-find-code-refs --dryRun --projKey=default -t redactedkey -d . -r repo-name --debug, it executes properly and appears to do what I expect.

When run in the github action, however, I get this error instead:

ERROR: 2023/03/06 20:52:38 matcher.go:43: failed to generate aliases: filepattern '0': failed to execute alias command: fork/exec .launchdarkly/flagAlias.sh: permission denied

So it seems that there is something funky with the docker image that is preventing the file from being executed.

for reference, here's the github action file too:

name: Find LaunchDarkly flag code references
on: push
# 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/[email protected]
        with:
          accessToken: ${{ secrets.LD_ACCESS_TOKEN }}
          projKey: "default"
          debug: "true"

Changes made to version tags - January 9, 2023

Update 1/9/23

The old version tags have been deleted. Please follow the steps below if you haven't yet.

Summary

In December 2021, we updated this GitHub Action to use semantic versioning that matched the launchdarkly/ld-find-code-refs CLI, starting with version 2.4.1.

This disrupted dependabot updates that you may have been using to keep the action up to date (See #25). In order to mitigate this issue and resume automated updates we will remove old version tags on January 9, 2023.

We strongly encourage moving to the latest version of the action, which is v2.8.0.

uses: launchdarkly/[email protected]

Update guide

If you prefer to stay on your current version you can switch to the corresponding new tag immediately.

  • uses: launchdarkly/find-code-references@v14 -> uses: launchdarkly/[email protected]

  • uses: launchdarkly/find-code-references@v13 -> uses: launchdarkly/[email protected]

  • uses: launchdarkly/find-code-references@v12 -> uses: launchdarkly/[email protected]

  • uses: launchdarkly/find-code-references@v11 -> uses: launchdarkly/[email protected]

  • uses: launchdarkly/find-code-references@v10 -> uses: launchdarkly/[email protected]

  • uses: launchdarkly/find-code-references@v9 -> uses: launchdarkly/[email protected]

  • uses: launchdarkly/find-code-references@v8 -> uses: launchdarkly/[email protected]

  • uses: launchdarkly/find-code-references@v7 -> uses: launchdarkly/[email protected]

  • uses: launchdarkly/find-code-references@v6 -> uses: launchdarkly/[email protected]

  • uses: launchdarkly/find-code-references@v5 -> uses: launchdarkly/[email protected]

  • uses: launchdarkly/find-code-references@v4 -> uses: launchdarkly/[email protected]

  • uses: launchdarkly/find-code-references@v3 -> uses: launchdarkly/[email protected]

  • uses: launchdarkly/find-code-references@v2 ->uses: launchdarkly/find-code-references@ v1.2.0

  • uses: launchdarkly/find-code-references@v1 -> uses: launchdarkly/[email protected]

v9 not released?

The latest version on the actions marketplace for this is v8, but there's also a v9 tag – is it intentional that it hasn't been made a release?

Cleaning up deleted branches

If you are running this action in a private repo, you will need to manually delete branches

Here is an example workflow:

name: Delete code references branch
on: delete

jobs:
  branch-delete-tasks:
    runs-on: ubuntu-latest
    steps:
      - name: Delete branch
        if: ${{ github.event.ref_type == 'branch' }}
        uses: fjogeleit/[email protected]
        with:
          url: 'https://app.launchdarkly.com/api/v2/code-refs/repositories/${{ github.event.repository.name }}/branch-delete-tasks'
          method: POST
          customHeaders: '{"Authorization": "${{ secrets.LD_ACCESS_TOKEN }}"}'
          data: '["${{ github.event.ref }}"]'
          retry: 1
          retryWait: 1000

More information about the code references API can be found at https://apidocs.launchdarkly.com/tag/Code-references

Error: Parsing git branch name

Hey y'all!

Excited to move my current github actions to the new YAML format! Although I think I ran into a bug in this action...

My current YAML for github actions looks like this

on: push
name: Launch Darkly References Check
jobs:
  launchDarklyCodeReferences:
    name: LaunchDarkly Code References
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v1
    - name: LaunchDarkly Code References
      uses: launchdarkly/find-code-references@v1
      env:
        GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        LD_ACCESS_TOKEN: ${{ secrets.LD_ACCESS_TOKEN }}
        LD_PROJ_KEY: default

Which seems to be in alignment with the README, but on run I seem to get an error every time...

/usr/bin/docker run --name b3e3f70048f4234f874e5cb2d49457b881c1a2_aa989a --label b3e3f7 --workdir /github/workspace --rm -e GITHUB_TOKEN -e LD_ACCESS_TOKEN -e LD_PROJ_KEY -e INPUT_LD-PROJ-KEY -e INPUT_LD-ACCESS-TOKEN -e INPUT_GITHUB-TOKEN -e HOME -e GITHUB_REF -e GITHUB_SHA -e GITHUB_REPOSITORY -e GITHUB_ACTOR -e GITHUB_WORKFLOW -e GITHUB_HEAD_REF -e GITHUB_BASE_REF -e GITHUB_EVENT_NAME -e GITHUB_WORKSPACE -e GITHUB_ACTION -e GITHUB_EVENT_PATH -e RUNNER_OS -e RUNNER_TOOL_CACHE -e RUNNER_TEMP -e RUNNER_WORKSPACE -v "/var/run/docker.sock":"/var/run/docker.sock" -v "/home/runner/work/_temp/_github_home":"/github/home" -v "/home/runner/work/_temp/_github_workflow":"/github/workflow" -v "/home/runner/work/REPO/REPO":"/github/workspace" b3e3f7:0048f4234f874e5cb2d49457b881c1a2
 INFO: 2019/08/12 17:09:12 github-actions.go:24: Setting GitHub action env vars
INFO: 2019/08/12 17:09:12 github-actions.go:60: starting repo parsing program with options:
 map[defaultBranch:master repoUrl:https://github.com/ORG/REPO delimiters: exclude: baseUri: debug:false repoType:github repoName:REPO dir:/github/workspace updateSequenceId:1565629698000 accessToken: projKey:KEY contextLines:2]
INFO: 2019/08/12 17:09:12 command.go:191: absolute directory path: /github/workspace
ERROR: 2019/08/12 17:09:12 coderefs.go:66: error parsing git branch name: git repo at /github/workspace must be checked out to a valid branch
##[error]Docker run failed with exit code 1

I'm guessing this has to do with the move from static directories /github/workspace to env vars $GITHUB_WORKSPACE.

Any thoughts?

skipping code reference pruning: authentication required

Hi, great LD folx,

We happened to notice in the logs this warning:

INFO: 2023/12/28 17:52:26 coderefs.go:199: attempting to prune old code reference data from LaunchDarkly
WARNING: 2023/12/28 17:52:26 coderefs.go:202: unable to retrieve branch list from remote, skipping code reference pruning: authentication required

Our workflow follows your examples, and we are providing our accessToken and projKey correctly, so I'm wondering if this is something we should be concerned about?

Thanks for your time!

LaunchDarkly API responded with status code 403

For the latest one 2.8.0, with example action with only changes we did - create repo secret and named LD_Project_Key with string:

helpers.go:39: error creating repository: LaunchDarkly API responded with status code 403

image

Actions running for hours

Hi all,

I figured I'd put in an issue for this action. We have the fetch-depth option set to 11.

The action stalls after:


INFO: 2023/01/24 23:11:07 coderefs.go:182: checking if 320 flags without references were removed in the last 11 commits for project: default

Error: Parsing GITHUB_REF in v6

Hey guys. Thank you for this action and looking forward to getting it working for my team. I'm currently seeing a potential issue with parsing the GITHUB_REF. I'm attempting to run the following config.

name: Update Launch Darkly Code References

# Controls when the action will run. Triggers the workflow on push or pull request
# events but only for the master branch
on:
  push:
    branches: [ master ]
  pull_request:
    branches: [ master ]

jobs:
  launchDarklyCodeReferences:
    name: LaunchDarkly Code References
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v2
      with:
        ref: ${{ github.event.pull_request.head.sha }}
    - name: LaunchDarkly Code References
      uses: launchdarkly/find-code-references@v6
      with:
        githubToken: ${{ secrets.GITHUB_TOKEN }}
        accessToken: ${{ secrets.LD_ACCESS_TOKEN }}
        projKey: Dev

and I'm getting the following error.

Run launchdarkly/find-code-references@v6
  with:
    githubToken: ***
    accessToken: ***
    projKey: dev
    baseUri: https://app.launchdarkly.com
    contextLines: 2
    debug: false
    ignoreServiceErrors: false
/usr/bin/docker run --name d3887c998a087545b1a4ae8b1c0dd60de7_1dec84 --label 3888d3 --workdir /github/workspace --rm -e INPUT_GITHUBTOKEN -e INPUT_ACCESSTOKEN -e INPUT_PROJKEY -e INPUT_BASEURI -e INPUT_CONTEXTLINES -e INPUT_DEBUG -e INPUT_DELIMITERS -e INPUT_EXCLUDE -e INPUT_IGNORESERVICEERRORS -e LD_PROJ_KEY -e LD_ACCESS_TOKEN -e LD_BASE_URI -e LD_CONTEXT_LINES -e LD_DEBUG -e LD_DELIMITERS -e LD_EXCLUDE -e LD_IGNORE_SERVICE_ERRORS -e GITHUB_TOKEN -e HOME -e GITHUB_JOB -e GITHUB_REF -e GITHUB_SHA -e GITHUB_REPOSITORY -e GITHUB_REPOSITORY_OWNER -e GITHUB_RUN_ID -e GITHUB_RUN_NUMBER -e GITHUB_ACTOR -e GITHUB_WORKFLOW -e GITHUB_HEAD_REF -e GITHUB_BASE_REF -e GITHUB_EVENT_NAME -e GITHUB_SERVER_URL -e GITHUB_API_URL -e GITHUB_GRAPHQL_URL -e GITHUB_WORKSPACE -e GITHUB_ACTION -e GITHUB_EVENT_PATH -e RUNNER_OS -e RUNNER_TOOL_CACHE -e RUNNER_TEMP -e RUNNER_WORKSPACE -e ACTIONS_RUNTIME_URL -e ACTIONS_RUNTIME_TOKEN -e ACTIONS_CACHE_URL -e GITHUB_ACTIONS=true -e CI=true -v "/var/run/docker.sock":"/var/run/docker.sock" -v "/home/runner/work/_temp/_github_home":"/github/home" -v "/home/runner/work/_temp/_github_workflow":"/github/workflow" -v "/home/runner/work/frontend-app/frontend-app":"/github/workspace" 3888d3:887c998a08754111a4ae8b1c0dd60de7
ERROR: 2020/07/01 15:26:36 github-actions.go:33: error parsing GITHUB_REF: expected branch name starting with refs/heads/, got: refs/pull/69/merge
INFO: 2020/07/01 15:26:36 github-actions.go:26: Setting GitHub action env vars

I'm not sure if github/git modified the type of refs that are available to use, but in the below link...
https://docs.github.com/en/actions/reference/events-that-trigger-workflows
You will find that on an Action pull_request event, the GITHUB_REF is set to refs/pull/:prNumber/merge.

So far I have attempted the checkout action with and without the ref:

    - uses: actions/checkout@v2
      with:
        ref: ${{ github.event.pull_request.head.sha }}

and

    - uses: actions/checkout@v2

I've also attempted using different versions of both the checkout action and find-code-reference. Any help would be greatly appreciated!

Action fails on forked repositories

AFAIK, secrets aren't available on forks, so anytime someone forks our repo the action fails to run because the LaunchDarkly secret is missing.

Any ideas to mitigate?

ERROR: 2021/08/24 17:00:46 coderefs.go:276: error retrieving repository: unauthorized, check your LaunchDarkly access token

Hi there,

I am getting the following error even though I have already created LD_ACCESS_TOKEN which has writer role and added that as secrets on github. Not sure what I am missing. Any idea?

When I check here: https://app.launchdarkly.com/settings/authorization that token is Never used πŸ€”

ERROR: 2021/08/24 17:00:46 coderefs.go:276: error retrieving repository: unauthorized, check your LaunchDarkly access token

This is what my config looks like:

on: push
name: Detect LaunchDarkly Feature Flag References
jobs:
  launchDarklyCodeReferences:
    name: LaunchDarkly Code References
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
        with:
          # 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
          fetch-depth: 11
      - name: LaunchDarkly Code References
        uses: launchdarkly/find-code-references@v11
        with:
          accessToken: ${{ secrets.GITHUB_TOKEN }}
          githubToken: ${{ secrets.LD_ACCESS_TOKEN }}
          projKey: default

These are the prerequisites:

Prerequisites
To set up code references in LaunchDarkly, you must have the following prerequisites:

1. You must have an API access token with writer-level access or higher. Create an API access token in the Access Tokens page. To learn more, read API access tokens.

2. You must have a custom role that allows all actions on code references.

3. You must allow ld-find-code-refs to run in environment that has access to your source code.

I don't have a custom role, but from other documentation it seems like that is not necessary since I already have writer role.

The default branch has been renamed - January 9, 2023

Update 1/9/23

The master branch has now been deleted. Please update your action to point at a version tag or the main branch.

Summary

The default branch name has been renamed to main (previously master).

If you are using the GitHub Action with the master branch we strongly recommend pinning to the latest version.

uses: launchdarkly/[email protected]

The master branch will be preserved until January 9, 2023.

If you have local clone, it is recommended to update it by running the following commands:

git branch -m master main
git fetch origin
git branch -u origin/main main
git remote set-head origin -a

runtime error: index out of range [65533] with length 58363

Every now and then we have a commit that breaks the action, which means that the refs don't get updated and the action continues to fail for the next 10 commits (due to the lookback), maybe missing some updates forever.

Here's the logs of the failure, slightly redacted.

DEBUG: 2023/10/25 20:19:57 client.go:599: [DEBUG] PUT https://app.launchdarkly.com/api/v2/code-refs/repositories/[REDACTED]/branches/main
INFO: 2023/10/25 20:19:58 coderefs.go:182: checking if 223 flags without references were removed in the last 10 commits for project: default
DEBUG: 2023/10/25 20:19:58 git.go:245: Examining commit: [REDACTED][170](https://github.com/[REDACTED])[REDACTED]
panic: runtime error: index out of range [65533] with length 58363

goroutine 1 [running]:
github.com/sergi/go-diff/diffmatchpatch.(*DiffMatchPatch).DiffCharsToLines(0xc0009a48a8?, {0xc0002f4a20, 0xb, 0x11000?}, {0xc004000000, 0xe3fb, 0x11000?})
	/tmp/project-releaser/project/vendor/github.com/sergi/go-diff/diffmatchpatch/diff.go:452 +0x29b
github.com/go-git/go-git/v5/utils/diff.DoWithTimeout({0xc0057a0000?, 0x1?}, {0xc00606c000?, 0x2?}, 0xc001a30e80?)
	/tmp/project-releaser/project/vendor/github.com/go-git/go-git/v5/utils/diff/diff.go:37 +0x11d
github.com/go-git/go-git/v5/utils/diff.Do(...)
	/tmp/project-releaser/project/vendor/github.com/go-git/go-git/v5/utils/diff/diff.go:22
github.com/go-git/go-git/v5/plumbing/object.filePatchWithContext({0xa0df18, 0xc00002e0b8}, 0xc001a30d80)
	/tmp/project-releaser/project/vendor/github.com/go-git/go-git/v5/plumbing/object/patch.go:68 +0x195
github.com/go-git/go-git/v5/plumbing/object.getPatchContext({0xa0df18, 0xc00002e0b8}, {0x0, 0x0}, {0xc001153c20, 0x3, 0x5?})
	/tmp/project-releaser/project/vendor/github.com/go-git/go-git/v5/plumbing/object/patch.go:38 +0xf4
github.com/go-git/go-git/v5/plumbing/object.Changes.PatchContext(...)
	/tmp/project-releaser/project/vendor/github.com/go-git/go-git/v5/plumbing/object/change.go:158
github.com/launchdarkly/ld-find-code-refs/v2/internal/git.Client.FindExtinctions({{0xc0000321c1, 0x11}, {0xc000030016, 0x4}, {0xc000033bc0, 0x28}, 0x18b43f11920}, {{0xc0000281a4, 0x7}, {0x0, ...}, ...}, ...)
	/tmp/project-releaser/project/internal/git/git.go:250 +0x3de
github.com/launchdarkly/ld-find-code-refs/v2/coderefs.runExtinctions({{0xc00002a090, 0x28}, {0xc00003203c, 0x1c}, {0xc000030016, 0x4}, {0x0, 0x0}, {0xc00002fe78, 0x4}, ...}, ...)
	/tmp/project-releaser/project/coderefs/coderefs.go:[183](https://github.com/benchsci/bsci/actions/runs/6645431980/job/18057601554#step:4:184) +0xa25
github.com/launchdarkly/ld-find-code-refs/v2/coderefs.Run({{0xc00002a090, 0x28}, {0xc00003203c, 0x1c}, {0xc000030016, 0x4}, {0x0, 0x0}, {0xc00002fe78, 0x4}, ...}, ...)
	/tmp/project-releaser/project/coderefs/coderefs.go:75 +0x9db
main.main()
	/tmp/project-releaser/project/build/package/github-actions/github-actions.go:25 +0x15d

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.