A GitHub Action that automatically deletes branches from LaunchDarkly Code References when they are deleted in GitHub.
- π Automatic branch deletion - Deletes LaunchDarkly Code Refs branches when GitHub branches are deleted
- π Retry logic - Built-in retry mechanism for handling rate limits and transient errors
- β‘ Fast execution - Optimized for quick branch cleanup
- π‘οΈ Error handling - Comprehensive error handling with detailed logging
- π§ Configurable - Flexible configuration options for different environments
name: Delete LaunchDarkly Branch
on:
delete:
branches: [main, develop, feature/*]
jobs:
delete-ld-branch:
runs-on: ubuntu-latest
steps:
- name: Delete LaunchDarkly Code Refs Branch
uses: launchdarkly-labs/launchdarkly-code-ref-delete-branch-github-action@v1
with:
access-token: ${{ secrets.LAUNCHDARKLY_ACCESS_TOKEN }}name: Delete LaunchDarkly Branch
on:
delete:
branches: [main, develop, feature/*]
jobs:
delete-ld-branch:
runs-on: ubuntu-latest
steps:
- name: Delete LaunchDarkly Code Refs Branch
uses: launchdarkly-labs/launchdarkly-code-ref-delete-branch-github-action@v1
with:
access-token: ${{ secrets.LAUNCHDARKLY_ACCESS_TOKEN }}
repo: my-custom-repo-key
branch: ${{ github.ref_name }}
base-uri: https://app.launchdarkly.comThe force option allows you to delete LaunchDarkly branches even when the GitHub event is not a branch delete event:
name: Force Delete LaunchDarkly Branch
on:
workflow_dispatch:
inputs:
branch_name:
description: 'Branch name to delete'
required: true
jobs:
force-delete-ld-branch:
runs-on: ubuntu-latest
steps:
- name: Force Delete LaunchDarkly Code Refs Branch
uses: launchdarkly-labs/launchdarkly-code-ref-delete-branch-github-action@v1
with:
access-token: ${{ secrets.LAUNCHDARKLY_ACCESS_TOKEN }}
branch: ${{ inputs.branch_name }}
force: trueWhen to use force: true:
- Manual branch cleanup workflows
- Deleting branches triggered by tag deletions
- Cleanup scripts that run on schedule
- Any scenario where you need to delete a LaunchDarkly branch outside of a GitHub branch delete event
| Input | Description | Required | Default |
|---|---|---|---|
access-token |
LaunchDarkly API access token with Code References permissions | β | - |
repo |
Repository key in LaunchDarkly | β | GitHub repository name |
branch |
Branch name to delete | β | Deleted branch from GitHub event |
base-uri |
LaunchDarkly base URI | β | https://app.launchdarkly.com |
force |
Force delete even when not triggered by a branch delete event | β | false |
- Go to your LaunchDarkly dashboard
- Navigate to Account Settings > Access Tokens
- Create a new token with Code References permissions
- Copy the token value
- Go to your GitHub repository
- Navigate to Settings > Secrets and variables > Actions
- Click "New repository secret"
- Name:
LAUNCHDARKLY_ACCESS_TOKEN - Value: Your LaunchDarkly access token
Create a .github/workflows/delete-ld-branch.yml file in your repository:
name: Delete LaunchDarkly Branch
on:
delete:
branches: [main, develop, feature/*]
jobs:
delete-ld-branch:
runs-on: ubuntu-latest
steps:
- name: Delete LaunchDarkly Code Refs Branch
uses: launchdarkly-labs/launchdarkly-code-ref-delete-branch-github-action@v1
with:
access-token: ${{ secrets.LAUNCHDARKLY_ACCESS_TOKEN }}- Trigger: The action is triggered when a branch is deleted in GitHub
- Detection: It automatically detects the deleted branch name and repository
- API Call: Makes a POST request to LaunchDarkly's Code References API
- Retry Logic: Implements exponential backoff for rate limits and transient errors
- Confirmation: Logs success or failure of the operation
The action includes comprehensive error handling:
- Rate Limiting: Automatically retries with exponential backoff when hitting rate limits
- Transient Errors: Retries on 5xx server errors
- Network Issues: Handles network timeouts and connection errors
- Validation: Validates required inputs and GitHub context
The action implements intelligent retry logic:
- Max Retries: 5 attempts by default
- Base Delay: 1 second initial delay
- Exponential Backoff: Doubles delay on each retry
- Rate Limit Headers: Respects
Retry-AfterandX-Ratelimit-Resetheaders - Transient Errors: Only retries on 429 and 5xx status codes
- Node.js 18+
- npm or yarn
# Install dependencies
npm install
# Build the action
npm run build
# Package for distribution (REQUIRED before publishing)
npm run packageImportant: The dist/index.js file must be created before the action can be used. This is done by running npm run package. The GitHub workflow will automatically build and package the action on releases.
npm run build- Compile TypeScriptnpm run package- Package for distribution using @vercel/nccnpm run lint- Run ESLintnpm run format- Format code with Prettiernpm test- Run tests
Apache 2.0 - see LICENSE file for details.
This repository is maintained by LaunchDarkly Labs. While we try to keep it up to date, it is not officially supported by LaunchDarkly. For officially supported SDKs and tools, visit https://launchdarkly.com
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
For issues and questions:
- Check the Issues page
- Create a new issue with detailed information
- Include logs and error messages when possible