Skip to content

Commit ed1bd9f

Browse files
chore: create feature flag actions (#1705)
1 parent 16d4f8f commit ed1bd9f

5 files changed

Lines changed: 562 additions & 1 deletion

File tree

Lines changed: 226 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,226 @@
1+
# Change Tracking Action
2+
3+
This action creates a single New Relic change tracking event for one account/entity combination. Call this action multiple times to create events for multiple accounts or entities.
4+
5+
## Required Secrets
6+
7+
Before using this action, you need to create the following GitHub secrets:
8+
9+
### API Keys
10+
- `NR_CHANGE_TRACKING_API_KEY_NR1` - New Relic User API key for account 1067061
11+
- `NR_CHANGE_TRACKING_API_KEY_BROWSER` - New Relic User API key for account 550352
12+
13+
### Entity GUIDs
14+
- `NR_ENTITY_GUID_NR1_STAGING` - Entity GUID for account 1067061 staging environment
15+
- `NR_ENTITY_GUID_NR1_US_PROD` - Entity GUID for account 1067061 US production
16+
- `NR_ENTITY_GUID_NR1_EU_PROD` - Entity GUID for account 1067061 EU production
17+
- `NR_ENTITY_GUID_BROWSER_STAGING` - Entity GUID for account 550352 staging environment
18+
19+
**NOTE: The workflow action must have access to staging to publish successfully in staging region**
20+
21+
## Inputs
22+
23+
| Input | Required | Default | Description |
24+
|-------|----------|---------|-------------|
25+
| `accountId` | Yes | - | New Relic account ID (e.g., 1067061, 550352) |
26+
| `entityGuid` | Yes | - | Entity GUID for the application |
27+
| `apiKey` | Yes | - | New Relic User API key for the account |
28+
| `region` | Yes | - | New Relic region (US, EU, dev or Staging) |
29+
| `version` | Yes | - | Version being deployed |
30+
| `category` | No | Deployment | Category of event (Deployment or Feature Flag) |
31+
| `type` | No | Basic | Type of deployment (Basic, Rollback, Blue Green, Canary, Rolling, Shadow) |
32+
| `featureFlagId` | No | - | ID of the feature flag (required when category is Feature Flag) |
33+
| `description` | No | - | Description of the event |
34+
| `changelog` | No | - | Changelog for the deployment (URL or text) |
35+
| `commit` | No | - | Commit hash for the deployment |
36+
| `deepLink` | No | - | Deep link URL for the deployment |
37+
| `user` | No | - | Username of the actor or bot |
38+
| `groupId` | No | - | String to correlate two or more events |
39+
| `shortDescription` | No | - | Short description for the event |
40+
41+
## Supported Environments and Regions
42+
43+
| Environment | Region | Account 1067061 Secret | Account 550352 Secret |
44+
|-------------|--------|------------------------|----------------------|
45+
| staging | Staging | `NR_ENTITY_GUID_NR1_STAGING` | `NR_ENTITY_GUID_BROWSER_STAGING` |
46+
| us-prod | US | `NR_ENTITY_GUID_NR1_US_PROD` | N/A |
47+
| eu-prod | EU | `NR_ENTITY_GUID_NR1_EU_PROD` | N/A |
48+
49+
**Note:** Dev environment is not supported by the New Relic Change Tracking API.
50+
51+
## Usage Examples
52+
53+
### Basic Deployment Event (Single Account)
54+
55+
```yaml
56+
- name: Create change tracking event (Account 1067061)
57+
uses: ./.github/actions/change-tracking
58+
with:
59+
accountId: '1067061'
60+
entityGuid: ${{ secrets.NR_ENTITY_GUID_NR1_STAGING }}
61+
apiKey: ${{ secrets.NR_CHANGE_TRACKING_API_KEY_NR1 }}
62+
region: 'Staging'
63+
version: 'staging-latest'
64+
```
65+
66+
### Multiple Accounts for Same Environment
67+
68+
```yaml
69+
# Create event for account 1067061
70+
- name: Create staging change tracking event (Account 1067061)
71+
uses: ./.github/actions/change-tracking
72+
with:
73+
accountId: '1067061'
74+
entityGuid: ${{ secrets.NR_ENTITY_GUID_NR1_STAGING }}
75+
apiKey: ${{ secrets.NR_CHANGE_TRACKING_API_KEY_NR1 }}
76+
region: 'Staging'
77+
version: 'staging-latest'
78+
shortDescription: 'Staging: main branch deployment'
79+
commit: ${{ github.sha }}
80+
user: ${{ github.actor }}
81+
groupId: '${{ github.run_id }}-${{ github.sha }}'
82+
83+
# Create event for account 550352
84+
- name: Create staging change tracking event (Account 550352)
85+
uses: ./.github/actions/change-tracking
86+
with:
87+
accountId: '550352'
88+
entityGuid: ${{ secrets.NR_ENTITY_GUID_BROWSER_STAGING }}
89+
apiKey: ${{ secrets.NR_CHANGE_TRACKING_API_KEY_BROWSER }}
90+
region: 'Staging'
91+
version: 'staging-latest'
92+
shortDescription: 'Staging: main branch deployment'
93+
commit: ${{ github.sha }}
94+
user: ${{ github.actor }}
95+
groupId: '${{ github.run_id }}-${{ github.sha }}'
96+
```
97+
98+
This allows you to see all related deployments grouped together in New Relic.
99+
100+
### Production Deployment with Rolling Type
101+
102+
```yaml
103+
- name: Get version number
104+
id: agent-loader-version
105+
run: echo "results=$(cat package.json | jq -r '.version')" >> $GITHUB_OUTPUT
106+
107+
- name: Create US production change tracking event
108+
uses: ./.github/actions/change-tracking
109+
with:
110+
accountId: '1067061'
111+
entityGuid: ${{ secrets.NR_ENTITY_GUID_NR1_US_PROD }}
112+
apiKey: ${{ secrets.NR_CHANGE_TRACKING_API_KEY_NR1 }}
113+
region: 'US'
114+
version: ${{ steps.agent-loader-version.outputs.results }}
115+
type: 'Rolling'
116+
description: 'Production release v${{ steps.agent-loader-version.outputs.results }}'
117+
shortDescription: 'US Prod: v${{ steps.agent-loader-version.outputs.results }}'
118+
commit: ${{ github.sha }}
119+
user: ${{ github.actor }}
120+
groupId: '${{ github.run_id }}-${{ github.sha }}'
121+
```
122+
123+
### Feature Flag Events
124+
125+
When feature flags are updated (e.g., changes to `released.js`), create a Feature Flag event:
126+
127+
```yaml
128+
- name: Check if released.js changed
129+
id: check-released
130+
run: |
131+
if git diff HEAD^ HEAD --name-only | grep -q ".github/actions/build-ab/templates/released.js"; then
132+
echo "changed=true" >> $GITHUB_OUTPUT
133+
else
134+
echo "changed=false" >> $GITHUB_OUTPUT
135+
fi
136+
137+
- name: Create dev change tracking event (Account 1067061)
138+
uses: ./.github/actions/change-tracking
139+
with:
140+
accountId: '1067061'
141+
entityGuid: ${{ secrets.NR_ENTITY_GUID_NR1_STAGING }}
142+
apiKey: ${{ secrets.NR_CHANGE_TRACKING_API_KEY_NR1 }}
143+
region: 'Staging'
144+
version: dev-latest
145+
category: ${{ steps.check-released.outputs.changed == 'true' && 'Feature Flag' || 'Deployment' }}
146+
type: 'Basic'
147+
featureFlagId: ${{ steps.check-released.outputs.changed == 'true' && 'hardcoded feature flag' || '' }}
148+
description: ${{ steps.check-released.outputs.changed == 'true' && 'Feature flag configuration updated' || 'Standard deployment' }}
149+
shortDescription: ${{ steps.check-released.outputs.changed == 'true' && 'Dev: Feature flags updated' || 'Dev: Deployment' }}
150+
commit: ${{ github.sha }}
151+
user: ${{ github.actor }}
152+
groupId: '${{ github.run_id }}-${{ github.sha }}'
153+
```
154+
155+
### Shadow Deployment (Experiment)
156+
157+
```yaml
158+
- name: Create experiment change tracking event
159+
uses: ./.github/actions/change-tracking
160+
with:
161+
accountId: '1067061'
162+
entityGuid: ${{ secrets.NR_ENTITY_GUID_NR1_STAGING }}
163+
apiKey: ${{ secrets.NR_CHANGE_TRACKING_API_KEY_NR1 }}
164+
region: 'Staging'
165+
version: 'dev-experiment-branch-name'
166+
type: 'Shadow'
167+
description: 'Experiment deployment for branch experiment-branch-name'
168+
shortDescription: 'Experiment: experiment-branch-name'
169+
commit: ${{ github.sha }}
170+
user: ${{ github.actor }}
171+
groupId: '${{ github.run_id }}-${{ github.sha }}'
172+
```
173+
174+
### Correlating Multiple Events
175+
176+
Use the same `groupId` across multiple action calls to correlate events:
177+
178+
```yaml
179+
# All these events are correlated via the same groupId
180+
- name: Create US prod event
181+
uses: ./.github/actions/change-tracking
182+
with:
183+
accountId: '1067061'
184+
entityGuid: ${{ secrets.NR_ENTITY_GUID_NR1_US_PROD }}
185+
apiKey: ${{ secrets.NR_CHANGE_TRACKING_API_KEY_NR1 }}
186+
region: 'US'
187+
version: '1.2.3'
188+
shortDescription: 'US Prod: v1.2.3'
189+
groupId: '${{ github.run_id }}-${{ github.sha }}'
190+
191+
- name: Create EU prod event
192+
uses: ./.github/actions/change-tracking
193+
with:
194+
accountId: '1067061'
195+
entityGuid: ${{ secrets.NR_ENTITY_GUID_NR1_EU_PROD }}
196+
apiKey: ${{ secrets.NR_CHANGE_TRACKING_API_KEY_NR1 }}
197+
region: 'EU'
198+
version: '1.2.3'
199+
shortDescription: 'EU Prod: v1.2.3'
200+
groupId: '${{ github.run_id }}-${{ github.sha }}'
201+
202+
- name: Create dev event
203+
uses: ./.github/actions/change-tracking
204+
with:
205+
accountId: '1067061'
206+
entityGuid: ${{ secrets.NR_ENTITY_GUID_NR1_STAGING }}
207+
apiKey: ${{ secrets.NR_CHANGE_TRACKING_API_KEY_NR1 }}
208+
region: 'Staging'
209+
version: '1.2.3'
210+
shortDescription: 'Dev: Prod release v1.2.3'
211+
groupId: '${{ github.run_id }}-${{ github.sha }}'
212+
```
213+
214+
## Notes
215+
216+
- The action creates a **single** change tracking event for one account/entity combination
217+
- Call the action multiple times to create events for multiple accounts or entities
218+
- The action uses `sudo snap install newrelic-cli` to install the New Relic CLI on Linux runners
219+
- The action runs on the `Browser-Agent-Assigned-IP-Linux` runner when specified in the workflow
220+
- **Categories supported**:
221+
- `Deployment` - For code deployments (default). Required field: `version`. Optional fields: `changelog`, `commit`, `deepLink`
222+
- `Feature Flag` - For feature flag changes. Required field: `featureFlagId`
223+
- Event types follow New Relic CLI conventions: Basic, Rollback, Blue Green, Canary, Rolling, Shadow
224+
- Use `groupId` to correlate related events across different accounts/environments (recommended: `${{ github.run_id }}-${{ github.sha }}`)
225+
- For more information, see the [New Relic Change Tracking documentation](https://docs.newrelic.com/docs/change-tracking/change-tracking-events/)
226+
Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
# This composite action creates New Relic change tracking events for deployments.
2+
# Call this action once per entity/account combination.
3+
4+
name: 'Create Change Tracking Event'
5+
description: 'Creates a New Relic change tracking event for a single entity'
6+
7+
inputs:
8+
accountId:
9+
description: 'New Relic account ID (e.g., 1067061, 550352)'
10+
required: true
11+
entityGuid:
12+
description: 'Entity GUID for the application'
13+
required: true
14+
apiKey:
15+
description: 'New Relic User API key for the account'
16+
required: true
17+
region:
18+
description: 'New Relic region (US, EU, Staging)'
19+
required: true
20+
version:
21+
description: 'Version being deployed (required for Deployment category)'
22+
required: true
23+
category:
24+
description: 'Category of event. Valid values: Deployment, Feature Flag'
25+
required: false
26+
default: 'Deployment'
27+
type:
28+
description: 'Type of deployment event. Valid values: Basic, Rollback, Blue Green, Canary, Rolling, Shadow'
29+
required: false
30+
default: 'Basic'
31+
featureFlagId:
32+
description: 'ID of the feature flag (required when category is Feature Flag)'
33+
required: false
34+
default: ''
35+
description:
36+
description: 'Description of the event'
37+
required: false
38+
default: ''
39+
changelog:
40+
description: 'Changelog for the deployment (URL or text)'
41+
required: false
42+
default: ''
43+
commit:
44+
description: 'Commit hash for the deployment'
45+
required: false
46+
default: ''
47+
deepLink:
48+
description: 'Deep link URL for the deployment'
49+
required: false
50+
default: ''
51+
user:
52+
description: 'Username of the actor or bot'
53+
required: false
54+
default: ''
55+
groupId:
56+
description: 'String to correlate two or more events'
57+
required: false
58+
default: ''
59+
shortDescription:
60+
description: 'Short description for the event'
61+
required: false
62+
default: ''
63+
64+
runs:
65+
using: 'composite'
66+
steps:
67+
- name: Install New Relic CLI
68+
shell: bash
69+
run: |
70+
echo "Installing New Relic CLI..."
71+
sudo snap install newrelic-cli
72+
newrelic version
73+
74+
- name: Create change tracking event
75+
shell: bash
76+
env:
77+
ACCOUNT_ID: ${{ inputs.accountId }}
78+
ENTITY_GUID: ${{ inputs.entityGuid }}
79+
API_KEY: ${{ inputs.apiKey }}
80+
REGION: ${{ inputs.region }}
81+
VERSION: ${{ inputs.version }}
82+
CATEGORY: ${{ inputs.category }}
83+
TYPE: ${{ inputs.type }}
84+
FEATURE_FLAG_ID: ${{ inputs.featureFlagId }}
85+
DESCRIPTION: ${{ inputs.description }}
86+
CHANGELOG: ${{ inputs.changelog }}
87+
COMMIT: ${{ inputs.commit }}
88+
DEEP_LINK: ${{ inputs.deepLink }}
89+
USER: ${{ inputs.user }}
90+
GROUP_ID: ${{ inputs.groupId }}
91+
SHORT_DESCRIPTION: ${{ inputs.shortDescription }}
92+
run: |
93+
# Build command arguments array
94+
args=(
95+
"--entitySearch" "id = '$ENTITY_GUID'"
96+
"--category" "$CATEGORY"
97+
"--type" "$TYPE"
98+
)
99+
100+
# Add category-specific required fields
101+
if [ "$CATEGORY" = "Deployment" ]; then
102+
args+=("--version" "$VERSION")
103+
[ -n "$CHANGELOG" ] && args+=("--changelog" "$CHANGELOG")
104+
[ -n "$COMMIT" ] && args+=("--commit" "$COMMIT")
105+
[ -n "$DEEP_LINK" ] && args+=("--deepLink" "$DEEP_LINK")
106+
elif [ "$CATEGORY" = "Feature Flag" ]; then
107+
[ -n "$FEATURE_FLAG_ID" ] && args+=("--featureFlagId" "$FEATURE_FLAG_ID")
108+
fi
109+
110+
# Add common optional fields
111+
[ -n "$DESCRIPTION" ] && args+=("--description" "$DESCRIPTION")
112+
[ -n "$USER" ] && args+=("--user" "$USER")
113+
[ -n "$GROUP_ID" ] && args+=("--groupId" "$GROUP_ID")
114+
[ -n "$SHORT_DESCRIPTION" ] && args+=("--shortDescription" "$SHORT_DESCRIPTION")
115+
116+
# Create change tracking event
117+
echo "Creating change tracking event for account $ACCOUNT_ID..."
118+
echo " Category: $CATEGORY"
119+
echo " Type: $TYPE"
120+
if [ "$CATEGORY" = "Deployment" ]; then
121+
echo " Version: $VERSION"
122+
elif [ "$CATEGORY" = "Feature Flag" ]; then
123+
echo " Feature Flag ID: $FEATURE_FLAG_ID"
124+
fi
125+
echo " GUID: $ENTITY_GUID"
126+
echo " Region: $REGION"
127+
128+
NEW_RELIC_REGION="$REGION" NEW_RELIC_API_KEY="$API_KEY" \
129+
newrelic changeTracking create "${args[@]}"
130+
131+
echo "Change tracking event created successfully!"

0 commit comments

Comments
 (0)