Skip to content

devopsdina/ld-cp-exp-date-gh-actions-audit

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

12 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

LaunchDarkly Feature Flag Expiry Audit Action

A GitHub Action that audits LaunchDarkly feature flags with expiry dates stored in custom properties. This action helps teams proactively manage feature flag lifecycle by identifying flags that are approaching their expiration date or are already past due.

Features

  • πŸ” Automated Scanning: Queries all feature flags in a LaunchDarkly project
  • πŸ“… Expiry Detection: Identifies flags with custom properties containing expiry dates
  • ⏰ Flexible Time Ranges: Configure how far ahead to check for expiring flags (default: 7 days)
  • πŸ“Š Comprehensive Reporting: Generates detailed summaries with flag names, keys, and expiry information
  • 🚨 Past Due Identification: Optionally includes flags that are already past their expiry date
  • πŸ“ Multiple Date Formats: Supports various date formats (MM/DD/YYYY, YYYY-MM-DD, etc.)
  • 🎫 Automated Issue Creation: Optionally creates GitHub issues for expired flags with task labels
  • 🌐 Multi-Project Support: Audit a single project or all projects in your LaunchDarkly account

Usage

Basic Example

name: LaunchDarkly Flag Expiry Audit
on:
  schedule:
    # Run every Monday at 9 AM UTC
    - cron: '0 9 * * 1'
  workflow_dispatch: # Allow manual triggers

jobs:
  audit-flags:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      
      - name: Audit LaunchDarkly Feature Flags
        uses: devopsdina/ld-cp-exp-date-gh-actions-audit@v1
        with:
          launchdarkly_api_key: ${{ secrets.LAUNCHDARKLY_API_KEY }}
          project_key: 'your-project-key'

Using with Automatic Issue Creation

name: Flag Cleanup with Issue Creation
on:
  schedule:
    - cron: '0 9 * * 1' # Monday at 9 AM

jobs:
  audit-and-create-issues:
    runs-on: ubuntu-latest
    permissions:
      issues: write
      contents: read
    steps:
      - uses: actions/checkout@v4
      
      - name: Audit flags and create issues
        uses: devopsdina/ld-cp-exp-date-gh-actions-audit@v1
        with:
          launchdarkly_api_key: ${{ secrets.LAUNCHDARKLY_API_KEY }}
          project_key: 'your-project-key'
          days_ahead: '7'
          include_past_due: 'true'
          create_issues: 'true'
          github_token: ${{ secrets.GITHUB_TOKEN }}

Auditing All Projects

name: Audit All LaunchDarkly Projects
on:
  schedule:
    - cron: '0 6 * * 1' # Monday at 6 AM

jobs:
  audit-all-projects:
    runs-on: ubuntu-latest
    permissions:
      issues: write
      contents: read
    steps:
      - uses: actions/checkout@v4
      
      - name: Audit all projects
        uses: devopsdina/ld-cp-exp-date-gh-actions-audit@v1
        with:
          launchdarkly_api_key: ${{ secrets.LAUNCHDARKLY_API_KEY }}
          project_key: 'all'  # This will audit ALL projects
          days_ahead: '14'
          create_issues: 'true'
          github_token: ${{ secrets.GITHUB_TOKEN }}

Inputs

Input Description Required Default
launchdarkly_api_key LaunchDarkly API access token (should be stored as a secret) Yes
project_key LaunchDarkly project key (use "all" to audit all projects) Yes
days_ahead Number of days ahead to check for expiring flags No 7
include_past_due Include flags that are past their expiry date No true
custom_property_name Name of the custom property containing the expiry date No flag.expiry.date
create_issues Create GitHub issues for expired flags No false
github_token GitHub token for creating issues No ${{ secrets.GITHUB_TOKEN }}

Outputs

Output Description
expiring_flags JSON array of flags approaching expiration within the specified time range
past_due_flags JSON array of flags that are past their expiry date
total_count Total number of flags found with expiry date custom properties

Output Format

Each flag object in the output arrays contains:

{
  "name": "My Feature Flag",
  "key": "my-feature-flag",
  "projectKey": "my-project",
  "projectName": "My Project",
  "expiryDate": "2024-03-15",
  "customPropertyKey": "flag.expiry.date",
  "customPropertyValue": "03/15/2024",
  "daysUntilExpiry": 5
}

Setting Up Custom Properties in LaunchDarkly

To use this action, your feature flags must have a custom property containing an expiry date.

Creating the Custom Property

  1. Navigate to your feature flag in LaunchDarkly
  2. Go to the flag's Settings tab
  3. Click + Add custom property
  4. Create a new property with:
    • Name: flag-expiry-date (or your preferred name)
    • Key: flag.expiry.date (should match the action's custom_property_key input)
    • Values: Enter the expiry date in MM/DD/YYYY format (e.g., 03/15/2024)

Supported Date Formats

The action supports multiple date formats:

  • MM/DD/YYYY (e.g., 03/15/2024)
  • MM-DD-YYYY (e.g., 03-15-2024)
  • YYYY-MM-DD (e.g., 2024-03-15)
  • YYYY/MM/DD (e.g., 2024/03/15)

GitHub Issue Creation

The action can automatically create GitHub issues for expired flags using the create_issues: 'true' option.

Issue Template

The action uses the template located at .github/ISSUE_TEMPLATE/expired-flag.md:

  • {{flagName}} - The display name of the flag
  • {{flagKey}} - The flag key
  • {{expiryDate}} - The expiry date
  • {{daysOverdue}} - Number of days past expiry
  • {{projectKey}} - LaunchDarkly project key
  • {{projectName}} - LaunchDarkly project name
  • {{auditDate}} - Date the audit was run
  • {{repoOwner}} - Repository owner
  • {{repoName}} - Repository name

Issue Features

  • Duplicate Prevention: Checks for existing open issues before creating new ones
  • Auto-labeling: Issues are labeled with launchdarkly, expired-flag, and task
  • Task Checklist: Includes cleanup steps as checkboxes
  • Context Information: Provides all necessary details for flag cleanup

Required Permissions

To create issues, your workflow needs:

permissions:
  issues: write
  contents: read

API Requirements

LaunchDarkly API Token

This action requires a LaunchDarkly API access token with read permissions for feature flags.

To create an API token:

  1. Go to Account settings > Authorization in LaunchDarkly
  2. Click Create token
  3. Provide a name for your token
  4. Select the appropriate role (Reader role is sufficient)
  5. Choose the projects you want to audit
  6. Save the token as a GitHub secret (e.g., LAUNCHDARKLY_API_KEY)

Required Permissions

The API token needs:

  • Read access to feature flags in the specified project
  • No write permissions are required

Error Handling

The action includes comprehensive error handling for:

  • Invalid API credentials
  • Network connectivity issues
  • Malformed date formats in custom properties
  • Missing or inaccessible projects
  • API rate limiting (the action uses pagination to handle large numbers of flags)

Examples of Use Cases

1. Automated Cleanup Reminders

Set up a weekly workflow to identify flags approaching expiry and create issues or notifications for the development team.

2. Compliance Reporting

Generate monthly reports showing all flags with expiry dates for compliance or audit purposes.

3. Pre-deployment Checks

Run the action before deployments to ensure no critical flags are about to expire.

4. Slack Notifications

Combine with Slack actions to send notifications to relevant channels when flags are expiring.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

This project is licensed under the MIT License - see the LICENSE file for details.

About

A GitHub Action that audits LaunchDarkly feature flags with expiry dates stored in custom properties.

Resources

License

Stars

Watchers

Forks

Packages

No packages published