Skip to content

Commit f56d185

Browse files
Merge branch 'main' into dependabot/npm_and_yarn/nanoid-3.3.8
2 parents 245f422 + c2c05a1 commit f56d185

File tree

15 files changed

+334
-9
lines changed

15 files changed

+334
-9
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# This composite action is used to report the local build size to New Relic
2+
# You must build the agent before running this action
3+
4+
name: 'Report Build Size to New Relic'
5+
6+
inputs:
7+
nr-api-key:
8+
description: 'NR API Key for reporting events'
9+
required: true
10+
11+
runs:
12+
using: "composite"
13+
steps:
14+
- name: Install dependencies
15+
run: npm install --silent --no-progress --prefix $GITHUB_ACTION_PATH/..
16+
shell: bash
17+
- name: Get local stats
18+
id: get-stats
19+
shell: bash
20+
run: |
21+
rum=$(cat ./build/nr-rum-standard.stats.json); echo "rum=$rum" >> $GITHUB_OUTPUT;
22+
full=$(cat ./build/nr-full-standard.stats.json); echo "full=$full" >> $GITHUB_OUTPUT;
23+
spa=$(cat ./build/nr-spa-standard.stats.json); echo "spa=$spa" >> $GITHUB_OUTPUT;
24+
- name: Report rum size to NR
25+
uses: metal-messiah/webpack-build-size-action@main
26+
with:
27+
nr-api-key: ${{ inputs.nr-api-key }}
28+
nr-account-id: '550352'
29+
nr-env: 'staging'
30+
analysis-file-contents: ${{ steps.get-stats.outputs.rum }}
31+
file-name-filter: '.min.js'
32+
- name: Report full size to NR
33+
uses: metal-messiah/webpack-build-size-action@main
34+
with:
35+
nr-api-key: ${{ inputs.nr-api-key }}
36+
nr-account-id: '550352'
37+
nr-env: 'staging'
38+
analysis-file-contents: ${{ steps.get-stats.outputs.full }}
39+
file-name-filter: '.min.js'
40+
- name: Report spa size to NR
41+
uses: metal-messiah/webpack-build-size-action@main
42+
with:
43+
nr-api-key: ${{ inputs.nr-api-key }}
44+
nr-account-id: '550352'
45+
nr-env: 'staging'
46+
analysis-file-contents: ${{ steps.get-stats.outputs.spa }}
47+
file-name-filter: '.min.js'
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# This composite action is used to delete files from a S3 bucket.
2+
3+
name: 'S3 File Deletion'
4+
5+
inputs:
6+
aws_access_key_id:
7+
description: 'AWS access key id used for authentication.'
8+
required: true
9+
aws_secret_access_key:
10+
description: 'AWS secret access key used for authentication.'
11+
required: true
12+
aws_region:
13+
description: "AWS region where S3 bucket is located."
14+
required: false
15+
default: us-east-1
16+
aws_role:
17+
description: "AWS role ARN that needs to be used for authentication."
18+
required: true
19+
aws_bucket_name:
20+
description: "S3 bucket name where files need to be deleted."
21+
required: true
22+
dry_run:
23+
description: "Indicates if we should just list files to deleted without actually deleting them."
24+
required: false
25+
bucket_dir:
26+
description: 'A sub directory where the files are located within the S3 bucket.'
27+
required: false
28+
29+
outputs:
30+
results:
31+
description: "Array of objects containing information about each file uploaded"
32+
value: ${{ steps.action-script.outputs.results }}
33+
34+
runs:
35+
using: "composite"
36+
steps:
37+
- name: Install dependencies
38+
run: npm install --silent --no-progress --prefix $GITHUB_ACTION_PATH/..
39+
shell: bash
40+
- name: Run action script
41+
id: action-script
42+
env:
43+
AWS_ACCESS_KEY_ID: ${{ inputs.aws_access_key_id }}
44+
AWS_SECRET_ACCESS_KEY: ${{ inputs.aws_secret_access_key }}
45+
run: |
46+
node $GITHUB_ACTION_PATH/index.js \
47+
--region ${{ inputs.aws_region }} \
48+
--bucket ${{ inputs.aws_bucket_name }} \
49+
--role ${{ inputs.aws_role }} \
50+
${{ inputs.dry_run && '--dry' || '' }} \
51+
${{ inputs.bucket_dir && format('--dir {0}', inputs.bucket_dir) || '' }}
52+
shell: bash

.github/actions/s3-delete/args.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import process from 'process'
2+
import yargs from 'yargs'
3+
import { hideBin } from 'yargs/helpers'
4+
5+
export const args = yargs(hideBin(process.argv))
6+
.usage('$0 [options]')
7+
8+
.string('role')
9+
.describe('role', 'S3 role ARN')
10+
11+
.string('bucket')
12+
.describe('bucket', 'S3 bucket name')
13+
14+
.string('region')
15+
.describe('region', 'AWS region location of S3 bucket. Defaults to us-east-1.')
16+
.default('region', 'us-east-1')
17+
18+
.boolean('dry')
19+
.default('dry', false)
20+
.describe('dry', 'Runs the action script without actually uploading files.')
21+
.alias('dry', 'dry-run')
22+
23+
.string('dir')
24+
.describe('dir', 'Bucket sub-directory name. Leave empty to refer to the root of the bucket.')
25+
26+
.demandOption(['bucket', 'role'])
27+
.argv

.github/actions/s3-delete/index.js

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
import * as core from '@actions/core'
2+
import { AssumeRoleCommand, STSClient } from '@aws-sdk/client-sts'
3+
import { S3Client, S3ServiceException, paginateListObjectsV2, DeleteObjectsCommand, waitUntilObjectNotExists } from '@aws-sdk/client-s3'
4+
import { args } from './args.js'
5+
6+
const stsClient = new STSClient({ region: args.region })
7+
const s3Credentials = await stsClient.send(new AssumeRoleCommand({
8+
RoleArn: args.role,
9+
RoleSessionName: 'deleteExperimentFromS3Session',
10+
DurationSeconds: 900
11+
}))
12+
13+
const s3Client = new S3Client({
14+
region: args.region,
15+
credentials: {
16+
accessKeyId: s3Credentials.Credentials.AccessKeyId,
17+
secretAccessKey: s3Credentials.Credentials.SecretAccessKey,
18+
sessionToken: s3Credentials.Credentials.SessionToken
19+
}
20+
})
21+
22+
async function collectKeysToDelete(bucketName, bucketDir) {
23+
const keys = []
24+
core.info("Bucket name: " + bucketName)
25+
core.info(`Looking up files with prefix '${bucketDir}'`)
26+
27+
try {
28+
const params = {
29+
Bucket: bucketName,
30+
Prefix:bucketDir
31+
}
32+
const paginator = paginateListObjectsV2({ client: s3Client }, params)
33+
for await (const page of paginator) {
34+
page.Contents?.forEach(obj => {
35+
keys.push(obj.Key)
36+
})
37+
}
38+
core.info(`Found ${keys.length} matching files`)
39+
core.info(keys.map(k => ` • ${k}`).join('\n'))
40+
return keys
41+
} catch (err) {
42+
if (err instanceof S3ServiceException) {
43+
core.setFailed(
44+
`Error from S3 while listing objects for "${bucketName}". ${err.name}: ${err.message}`,
45+
)
46+
} else {
47+
core.setFailed(`Error while listing objects for "${bucketName}". ${err.name}: ${err.message}`)
48+
}
49+
process.exit(1)
50+
}
51+
}
52+
53+
async function deleteFiles(bucketName, keys) {
54+
try {
55+
core.info('Deleting...')
56+
57+
const { Deleted } = await s3Client.send(
58+
new DeleteObjectsCommand({
59+
Bucket: bucketName,
60+
Delete: {
61+
Objects: keys.map((k) => ({ Key: k })),
62+
},
63+
}),
64+
)
65+
66+
for (const key in keys) {
67+
await waitUntilObjectNotExists(
68+
{ client: s3Client },
69+
{ Bucket: bucketName, Key: key },
70+
)
71+
}
72+
core.info(
73+
`Successfully deleted ${Deleted?.length || 0} objects.`,
74+
)
75+
core.info(Deleted?.map((d) => ` • ${d.Key}`).join("\n"))
76+
} catch (err) {
77+
if (err instanceof S3ServiceException) {
78+
core.setFailed(
79+
`Error from S3 while deleting objects for "${bucketName}". ${err.name}: ${err.message}`,
80+
)
81+
} else {
82+
core.setFailed(`Error while deleting objects for "${bucketName}". ${err.name}: ${err.message}`)
83+
}
84+
process.exit(1)
85+
}
86+
}
87+
88+
if (args.dry) {
89+
core.info('This is a dry run.')
90+
}
91+
const keysToBeDeleted = await collectKeysToDelete(args.bucket, args.dir)
92+
if (!args.dry) {
93+
if (keysToBeDeleted.length > 0) {
94+
await deleteFiles(args.bucket, keysToBeDeleted)
95+
} else {
96+
core.info('No files found to delete')
97+
}
98+
}
99+
core.info('Completed successfully')
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# This workflow will run automatically when a branch is deleted.
2+
3+
name: Branch Cleanup
4+
5+
on: delete
6+
7+
jobs:
8+
branch-delete:
9+
if: github.event.ref_type == 'branch'
10+
runs-on: ubuntu-latest
11+
timeout-minutes: 5
12+
defaults:
13+
run:
14+
shell: bash
15+
steps:
16+
- uses: actions/checkout@v4
17+
- uses: actions/setup-node@v4
18+
with:
19+
node-version: 22.11.0 # See package.json for the stable node version that works with our testing. Do not change this unless you know what you are doing as some node versions do not play nicely with our testing server.
20+
- name: Clean up for deleted branch
21+
id: cleanup-start
22+
run: echo "Clean up for branch ${{ github.event.ref }}"
23+
- name: Delete dev experiment
24+
id: s3-delete-dev
25+
uses: ./.github/actions/s3-delete
26+
with:
27+
aws_access_key_id: ${{ secrets.AWS_ACCESS_KEY_ID }}
28+
aws_secret_access_key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
29+
aws_role: ${{ secrets.AWS_ROLE_ARN }}
30+
aws_bucket_name: ${{ secrets.AWS_BUCKET }}
31+
bucket_dir: experiments/dev/${{ github.event.ref }}
32+
dry_run: true
33+
- name: Delete staging experiment
34+
id: s3-delete-staging
35+
uses: ./.github/actions/s3-delete
36+
with:
37+
aws_access_key_id: ${{ secrets.AWS_ACCESS_KEY_ID }}
38+
aws_secret_access_key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
39+
aws_role: ${{ secrets.AWS_ROLE_ARN }}
40+
aws_bucket_name: ${{ secrets.AWS_BUCKET }}
41+
bucket_dir: experiments/staging/${{ github.event.ref }}
42+
dry_run: true
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# This workflow can be run on any branch.
2+
# Given an environment, this workflow will delete the branch's experiment from S3
3+
4+
name: Delete Experiment
5+
6+
on:
7+
workflow_dispatch:
8+
inputs:
9+
nr_environment:
10+
description: 'Target New Relic environment'
11+
required: true
12+
type: choice
13+
options:
14+
- dev
15+
- staging
16+
17+
jobs:
18+
delete-experiment-on-s3:
19+
runs-on: ubuntu-latest
20+
timeout-minutes: 5
21+
defaults:
22+
run:
23+
shell: bash
24+
steps:
25+
- uses: actions/checkout@v4
26+
- uses: actions/setup-node@v4
27+
with:
28+
node-version: 22.11.0 # See package.json for the stable node version that works with our testing. Do not change this unless you know what you are doing as some node versions do not play nicely with our testing server.
29+
- name: Clean branch name
30+
id: clean-branch-name
31+
run: echo "results=$(echo '${{ github.ref }}' | sed 's/refs\/heads\///g' | sed 's/[^[:alnum:].-]/-/g')" >> $GITHUB_OUTPUT
32+
- name: Delete experiment
33+
id: s3-delete
34+
uses: ./.github/actions/s3-delete
35+
with:
36+
aws_access_key_id: ${{ secrets.AWS_ACCESS_KEY_ID }}
37+
aws_secret_access_key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
38+
aws_role: ${{ secrets.AWS_ROLE_ARN }}
39+
aws_bucket_name: ${{ secrets.AWS_BUCKET }}
40+
bucket_dir: experiments/${{ inputs.nr_environment }}/${{ steps.clean-branch-name.outputs.results }}

.github/workflows/publish-dev.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,20 @@ jobs:
9090
fastly_key: ${{ secrets.FASTLY_PURGE_KEY }}
9191
fastly_service: staging-js-agent.newrelic.com
9292
asset_path: ${{ join(fromJson(steps.s3-upload.outputs.results).*.Key, ' ') }}
93+
# This step creates a new Change Tracking Marker
94+
- name: New Relic Application Deployment Marker
95+
uses: newrelic/deployment-marker-action@v2.3.0
96+
with:
97+
apiKey: ${{ secrets.INTERNAL_STAGING_INGEST_LICENSE_KEY }}
98+
guid: NTUwMzUyfEJST1dTRVJ8QVBQTElDQVRJT058ODkzODM5MjI
99+
commit: "${{ github.sha }}"
100+
version: "${{ github.ref_name }}"
101+
user: "${{ github.actor }}"
102+
# track build size as custom event
103+
- name: Report local stats as NR event
104+
uses: './.github/actions/nr-report-build-size'
105+
with:
106+
nr-api-key: ${{ secrets.INTERNAL_STAGING_INGEST_LICENSE_KEY }}
93107

94108
# Publish dev to staging NRDB
95109
# publish-dev-nr:

.github/workflows/pull-request-checks.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,10 @@ jobs:
9797
pr_number: ${{ github.event.number }}
9898
comment: ${{ steps.asset-size-report.outputs.results }}
9999
comment_tag: <!-- browser_agent asset size report -->
100+
- name: Report local stats as NR event
101+
uses: './.github/actions/nr-report-build-size'
102+
with:
103+
nr-api-key: ${{ secrets.INTERNAL_STAGING_INGEST_LICENSE_KEY }}
100104

101105
# Jobs for workflow_dispatch events
102106

package-lock.json

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

third_party_manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"lastUpdated": "Tue Dec 17 2024 16:31:01 GMT+0000 (Coordinated Universal Time)",
2+
"lastUpdated": "Thu Dec 19 2024 20:09:27 GMT+0000 (Coordinated Universal Time)",
33
"projectName": "New Relic Browser Agent",
44
"projectUrl": "https://github.com/newrelic/newrelic-browser-agent",
55
"includeOptDeps": true,

0 commit comments

Comments
 (0)