Skip to content

step-security/launchdarkly-gha-flags

Repository files navigation

LaunchDarkly Flag Evaluation GitHub Action

GitHub Action for evaluating LaunchDarkly flags in your workflow.

Inputs

parameter description required default
sdk-key Server-side SDK key for environment. true
flags Provide a list flag keys and default value in a comma separated format with a newline between each flag you want evaluated. example-flag,true true
context-key The key of the context object used in a feature flag evaluation false ld-github-action-flags
send-events Whether to send analytics events back to LaunchDarkly false true
offline Whether to use the LaunchDarkly SDK in offline mode false false
base-uri The base URI for the LaunchDarkly server. Most users should use the default value. false https://app.launchdarkly.com
stream-uri The base URI for the LaunchDarkly streaming server. Most users should use the default value. false https://stream.launchdarkly.com
events-uri The base URI for the LaunchDarkly events server. Most users should use the default value. false https://events.launchdarkly.com
proxy-auth Allows you to specify basic authentication parameters for an optional HTTP proxy. Usually of the form username:password. false
proxy-host Allows you to specify a host for an optional HTTP proxy. Both the host and port must be specified to enable proxy support. false
proxy-port Allows you to specify a port for an optional HTTP proxy. Both the host and port must be specified to enable proxy support. false
proxy-scheme When using an HTTP proxy, specifies whether it is accessed via http or https false

Output

The values of the request flags are stored on the step outputs with the flag key.

Keys:

Flag keys used in this GitHub Action must contain only alphanumeric characters, -, or _.

Values:

Outputs are Unicode strings, and can be a maximum of 1 MB. The total of all outputs in a workflow run can be a maximum of 50 MB.

Read more: Metadata syntax

Examples

Basic

This example evaluates flag keys of different types and prints their values.

name: Evaluate LaunchDarkly flags
on: push
jobs:
  eval-flags:
    runs-on: ubuntu-latest
    steps:
      - name: Evaluate flags
        id: flags
        uses: step-security/launchdarkly-gha-flags@v1
        with:
          sdk-key: ${{ secrets.LD_SDK_KEY }}
          flags: |
            test-boolean-flag
            test-string-flag
            test-number-flag
            test-json-flag
      - name: Print flag values
        run: |
          echo ${{ steps.flags.outputs.test-boolean-flag }}
          echo ${{ steps.flags.outputs.test-string-flag }}
          echo ${{ steps.flags.outputs.test-number-flag }}
          echo ${{ toJSON(steps.flags.outputs.test-json-flag) }}

Dynamic context key

This example evaluates a flag for a context. Here, the LaunchDarkly context key is the username of the GitHub user who initiated the workflow run.

Read more: GitHub Actions Contexts

name: Evaluate LaunchDarkly flags
on: push
jobs:
  eval-flags:
    runs-on: ubuntu-latest
    steps:
      - name: Evaluate flags
        id: flags
        uses: step-security/launchdarkly-gha-flags@v1
        with:
          sdk-key: ${{ secrets.LD_SDK_KEY }}
          flags: favorite-animal
          context-key: ${{ github.actor }}
      - name: Favorite animal
        if: steps.flags.outputs.favorite-animal != 'idk'
        run: echo "${{ github.actor }}'s favorite animal is a...${{ steps.flags.outputs.favorite-animal }}"

Use value in expression

This example evaluates a flag key and uses the value in an expression in a subsequent step.

name: Evaluate LaunchDarkly flags
on: push
jobs:
  eval-flags:
    runs-on: ubuntu-latest
    steps:
      - name: Evaluate flags
        id: ld
        uses: step-security/launchdarkly-gha-flags@v1
        with:
          sdk-key: ${{ secrets.LD_SDK_KEY }}
          flags: test-boolean-flag
      - name: If true
        if: steps.flags.outputs.test-boolean-flag == 'true'
        run: echo "It's true"
      - name: If false
        if: steps.flags.outputs.test-boolean-flag == 'false'
        run: echo "It's false"

Parse output string to types

This example illustrates how output values are stored as strings. You can parse them to JSON or a JSON data type using fromJSON().

name: Evaluate LaunchDarkly flags
on: push
jobs:
  eval-flags:
    runs-on: ubuntu-latest
    steps:
      - name: Evaluate flags
        id: ld
        uses: step-security/launchdarkly-gha-flags@v1
        with:
          sdk-key: ${{ secrets.LD_SDK_KEY }}
          flags: test-boolean-flag
          - name: If true
            if: fromJSON(steps.flags.outputs.test-boolean-flag) == true
            run: echo "It's true"
          - name: If false
            if: fromJSON(steps.flags.outputs.test-boolean-flag) == false
            run: echo "It's false"

Setting custom contexts

If you would like to include additional custom properties in your context object you may specify environment variables with the LD_ prefix. All values will be treated at strings.

By default, all metadata associated with the workflow run is saved in custom properties.

Read more: Setting custom contexts

name: Evaluate LaunchDarkly flags
on: push
job:
  deploy:
    runs-on: ubuntu-latest
    steps:
      - name: Evaluate flags
        id: ld
        uses: step-security/launchdarkly-gha-flags@v1
        with:
          sdk-key: ${{ secrets.LD_SDK_KEY }}
          flags: test-boolean-flag
        env:
          LD_group: beta

Use with GitHub deployment environments

Read more: Using environments for deployment

name: Deploy to environment
on: push
job:
  deploy:
    runs-on: ubuntu-latest
    environment: production
    steps:
      - name: Evaluate flags
        id: ld
        uses: step-security/launchdarkly-gha-flags@v1
        with:
          sdk-key: ${{ secrets.LD_SDK_KEY }} # configure environment-specific secret
          flags: test-boolean-flag

Disable analytics events

This example evaluates flag keys without sending events to LaunchDarkly.

Read more: Analytics events

name: Evaluate LaunchDarkly flags
on: push
jobs:
  eval-flags:
    runs-on: ubuntu-latest
    steps:
      - name: Evaluate flags
        id: flags
        uses: step-security/launchdarkly-gha-flags@v1
        with:
          sdk-key: ${{ secrets.LD_SDK_KEY }}
          flags: test-boolean-flag
          send-events: false

About

Evaluate LaunchDarkly flags in your GitHub Action workflow. Secure drop-in replacement for launchdarkly/gha-flags.

Topics

Resources

License

Security policy

Stars

Watchers

Forks

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •