|
| 1 | +# LaunchDarkly Delete Branch Action |
| 2 | + |
| 3 | +A GitHub Action that automatically deletes branches from LaunchDarkly Code References when they are deleted in GitHub. |
| 4 | + |
| 5 | +## Features |
| 6 | + |
| 7 | +- 🚀 **Automatic branch deletion** - Deletes LaunchDarkly Code Refs branches when GitHub branches are deleted |
| 8 | +- 🔄 **Retry logic** - Built-in retry mechanism for handling rate limits and transient errors |
| 9 | +- ⚡ **Fast execution** - Optimized for quick branch cleanup |
| 10 | +- 🛡️ **Error handling** - Comprehensive error handling with detailed logging |
| 11 | +- 🔧 **Configurable** - Flexible configuration options for different environments |
| 12 | + |
| 13 | +## Usage |
| 14 | + |
| 15 | +### Basic Usage |
| 16 | + |
| 17 | +```yaml |
| 18 | +name: Delete LaunchDarkly Branch |
| 19 | +on: |
| 20 | + delete: |
| 21 | + branches: [main, develop, feature/*] |
| 22 | + |
| 23 | +jobs: |
| 24 | + delete-ld-branch: |
| 25 | + runs-on: ubuntu-latest |
| 26 | + steps: |
| 27 | + - name: Delete LaunchDarkly Code Refs Branch |
| 28 | + uses: your-org/launchdarkly-delete-branch-action@v1 |
| 29 | + with: |
| 30 | + access-token: ${{ secrets.LAUNCHDARKLY_ACCESS_TOKEN }} |
| 31 | +``` |
| 32 | +
|
| 33 | +### Advanced Usage |
| 34 | +
|
| 35 | +```yaml |
| 36 | +name: Delete LaunchDarkly Branch |
| 37 | +on: |
| 38 | + delete: |
| 39 | + branches: [main, develop, feature/*] |
| 40 | + |
| 41 | +jobs: |
| 42 | + delete-ld-branch: |
| 43 | + runs-on: ubuntu-latest |
| 44 | + steps: |
| 45 | + - name: Delete LaunchDarkly Code Refs Branch |
| 46 | + uses: your-org/launchdarkly-delete-branch-action@v1 |
| 47 | + with: |
| 48 | + access-token: ${{ secrets.LAUNCHDARKLY_ACCESS_TOKEN }} |
| 49 | + repo: my-custom-repo-key |
| 50 | + branch: ${{ github.ref_name }} |
| 51 | + base-uri: https://app.launchdarkly.com |
| 52 | +``` |
| 53 | +
|
| 54 | +## Inputs |
| 55 | +
|
| 56 | +| Input | Description | Required | Default | |
| 57 | +|-------|-------------|----------|---------| |
| 58 | +| `access-token` | LaunchDarkly API access token with Code References permissions | ✅ | - | |
| 59 | +| `repo` | Repository key in LaunchDarkly | ❌ | GitHub repository name | |
| 60 | +| `branch` | Branch name to delete | ❌ | Deleted branch from GitHub event | |
| 61 | +| `base-uri` | LaunchDarkly base URI | ❌ | `https://app.launchdarkly.com` | |
| 62 | + |
| 63 | +## Setup |
| 64 | + |
| 65 | +### 1. Create a LaunchDarkly Access Token |
| 66 | + |
| 67 | +1. Go to your LaunchDarkly dashboard |
| 68 | +2. Navigate to Account Settings > Access Tokens |
| 69 | +3. Create a new token with Code References permissions |
| 70 | +4. Copy the token value |
| 71 | + |
| 72 | +### 2. Add the Token to GitHub Secrets |
| 73 | + |
| 74 | +1. Go to your GitHub repository |
| 75 | +2. Navigate to Settings > Secrets and variables > Actions |
| 76 | +3. Click "New repository secret" |
| 77 | +4. Name: `LAUNCHDARKLY_ACCESS_TOKEN` |
| 78 | +5. Value: Your LaunchDarkly access token |
| 79 | + |
| 80 | +### 3. Create the Workflow |
| 81 | + |
| 82 | +Create a `.github/workflows/delete-ld-branch.yml` file in your repository: |
| 83 | + |
| 84 | +```yaml |
| 85 | +name: Delete LaunchDarkly Branch |
| 86 | +on: |
| 87 | + delete: |
| 88 | + branches: [main, develop, feature/*] |
| 89 | +
|
| 90 | +jobs: |
| 91 | + delete-ld-branch: |
| 92 | + runs-on: ubuntu-latest |
| 93 | + steps: |
| 94 | + - name: Delete LaunchDarkly Code Refs Branch |
| 95 | + uses: your-org/launchdarkly-delete-branch-action@v1 |
| 96 | + with: |
| 97 | + access-token: ${{ secrets.LAUNCHDARKLY_ACCESS_TOKEN }} |
| 98 | +``` |
| 99 | + |
| 100 | +## How It Works |
| 101 | + |
| 102 | +1. **Trigger**: The action is triggered when a branch is deleted in GitHub |
| 103 | +2. **Detection**: It automatically detects the deleted branch name and repository |
| 104 | +3. **API Call**: Makes a POST request to LaunchDarkly's Code References API |
| 105 | +4. **Retry Logic**: Implements exponential backoff for rate limits and transient errors |
| 106 | +5. **Confirmation**: Logs success or failure of the operation |
| 107 | + |
| 108 | +## Error Handling |
| 109 | + |
| 110 | +The action includes comprehensive error handling: |
| 111 | + |
| 112 | +- **Rate Limiting**: Automatically retries with exponential backoff when hitting rate limits |
| 113 | +- **Transient Errors**: Retries on 5xx server errors |
| 114 | +- **Network Issues**: Handles network timeouts and connection errors |
| 115 | +- **Validation**: Validates required inputs and GitHub context |
| 116 | + |
| 117 | +## Retry Logic |
| 118 | + |
| 119 | +The action implements intelligent retry logic: |
| 120 | + |
| 121 | +- **Max Retries**: 5 attempts by default |
| 122 | +- **Base Delay**: 1 second initial delay |
| 123 | +- **Exponential Backoff**: Doubles delay on each retry |
| 124 | +- **Rate Limit Headers**: Respects `Retry-After` and `X-Ratelimit-Reset` headers |
| 125 | +- **Transient Errors**: Only retries on 429 and 5xx status codes |
| 126 | + |
| 127 | +## Development |
| 128 | + |
| 129 | +### Prerequisites |
| 130 | + |
| 131 | +- Node.js 18+ |
| 132 | +- npm or yarn |
| 133 | + |
| 134 | +### Setup |
| 135 | + |
| 136 | +```bash |
| 137 | +# Install dependencies |
| 138 | +npm install |
| 139 | +
|
| 140 | +# Build the action |
| 141 | +npm run build |
| 142 | +
|
| 143 | +# Package for distribution |
| 144 | +npm run package |
| 145 | +``` |
| 146 | + |
| 147 | +### Scripts |
| 148 | + |
| 149 | +- `npm run build` - Compile TypeScript |
| 150 | +- `npm run package` - Package for distribution using @vercel/ncc |
| 151 | +- `npm run lint` - Run ESLint |
| 152 | +- `npm run format` - Format code with Prettier |
| 153 | +- `npm test` - Run tests |
| 154 | + |
| 155 | +## License |
| 156 | + |
| 157 | +MIT License - see [LICENSE](LICENSE) file for details. |
| 158 | + |
| 159 | +## Contributing |
| 160 | + |
| 161 | +1. Fork the repository |
| 162 | +2. Create a feature branch |
| 163 | +3. Make your changes |
| 164 | +4. Add tests if applicable |
| 165 | +5. Submit a pull request |
| 166 | + |
| 167 | +## Support |
| 168 | + |
| 169 | +For issues and questions: |
| 170 | + |
| 171 | +1. Check the [Issues](https://github.com/your-org/launchdarkly-delete-branch-action/issues) page |
| 172 | +2. Create a new issue with detailed information |
| 173 | +3. Include logs and error messages when possible |
0 commit comments