Skip to content
launchdarkly

GitHub Action

LaunchDarkly Flags

v1.0.1 Latest version

LaunchDarkly Flags

launchdarkly

LaunchDarkly Flags

Evaluate LaunchDarkly flags in your GitHub Action workflow

Installation

Copy and paste the following snippet into your .yml file.

              

- name: LaunchDarkly Flags

uses: launchdarkly/gha-flags@v1.0.1

Learn more about this action in launchdarkly/gha-flags
Choose a version

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: launchdarkly/gha-flags@v1.0.1
        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: launchdarkly/gha-flags@v1.0.1
        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: launchdarkly/gha-flags@v1.0.1
        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: launchdarkly/gha-flags@v1.0.1
        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: launchdarkly/gha-flags@v1.0.1
        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: launchdarkly/gha-flags@v1.0.1
        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: launchdarkly/gha-flags@v1.0.1
        with:
          sdk-key: ${{ secrets.LD_SDK_KEY }}
          flags: test-boolean-flag
          send-events: false

Contributing

We encourage pull requests and other contributions from the community. Check out our contributing guidelines for instructions on how to contribute to this project.

About LaunchDarkly

  • LaunchDarkly is a continuous delivery platform that provides feature flags as a service and allows developers to iterate quickly and safely. We allow you to easily flag your features and manage them from the LaunchDarkly dashboard. With LaunchDarkly, you can:
    • Roll out a new feature to a subset of your users (like a group of users who opt-in to a beta tester group), gathering feedback and bug reports from real-world use cases.
    • Gradually roll out a feature to an increasing percentage of users, and track the effect that the feature has on key metrics (for instance, how likely is a user to complete a purchase if they have feature A versus feature B?).
    • Turn off a feature that you realize is causing performance problems in production, without needing to re-deploy, or even restart the application with a changed configuration file.
    • Grant access to certain features based on user attributes, like payment plan (eg: users on the ‘gold’ plan get access to more features than users in the ‘silver’ plan). Disable parts of your application to facilitate maintenance, without taking everything offline.
  • LaunchDarkly provides feature flag SDKs for a wide variety of languages and technologies. Check out our documentation for a complete list.
  • Explore LaunchDarkly