Skip to content

Commit

Permalink
Merge branch 'main' into dependabot/npm_and_yarn/multi-131610d547
Browse files Browse the repository at this point in the history
  • Loading branch information
metal-messiah authored Dec 30, 2024
2 parents 291c97b + c2c05a1 commit adcdb61
Show file tree
Hide file tree
Showing 15 changed files with 334 additions and 9 deletions.
47 changes: 47 additions & 0 deletions .github/actions/nr-report-build-size/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# This composite action is used to report the local build size to New Relic
# You must build the agent before running this action

name: 'Report Build Size to New Relic'

inputs:
nr-api-key:
description: 'NR API Key for reporting events'
required: true

runs:
using: "composite"
steps:
- name: Install dependencies
run: npm install --silent --no-progress --prefix $GITHUB_ACTION_PATH/..
shell: bash
- name: Get local stats
id: get-stats
shell: bash
run: |
rum=$(cat ./build/nr-rum-standard.stats.json); echo "rum=$rum" >> $GITHUB_OUTPUT;
full=$(cat ./build/nr-full-standard.stats.json); echo "full=$full" >> $GITHUB_OUTPUT;
spa=$(cat ./build/nr-spa-standard.stats.json); echo "spa=$spa" >> $GITHUB_OUTPUT;
- name: Report rum size to NR
uses: metal-messiah/webpack-build-size-action@main
with:
nr-api-key: ${{ inputs.nr-api-key }}
nr-account-id: '550352'
nr-env: 'staging'
analysis-file-contents: ${{ steps.get-stats.outputs.rum }}
file-name-filter: '.min.js'
- name: Report full size to NR
uses: metal-messiah/webpack-build-size-action@main
with:
nr-api-key: ${{ inputs.nr-api-key }}
nr-account-id: '550352'
nr-env: 'staging'
analysis-file-contents: ${{ steps.get-stats.outputs.full }}
file-name-filter: '.min.js'
- name: Report spa size to NR
uses: metal-messiah/webpack-build-size-action@main
with:
nr-api-key: ${{ inputs.nr-api-key }}
nr-account-id: '550352'
nr-env: 'staging'
analysis-file-contents: ${{ steps.get-stats.outputs.spa }}
file-name-filter: '.min.js'
52 changes: 52 additions & 0 deletions .github/actions/s3-delete/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# This composite action is used to delete files from a S3 bucket.

name: 'S3 File Deletion'

inputs:
aws_access_key_id:
description: 'AWS access key id used for authentication.'
required: true
aws_secret_access_key:
description: 'AWS secret access key used for authentication.'
required: true
aws_region:
description: "AWS region where S3 bucket is located."
required: false
default: us-east-1
aws_role:
description: "AWS role ARN that needs to be used for authentication."
required: true
aws_bucket_name:
description: "S3 bucket name where files need to be deleted."
required: true
dry_run:
description: "Indicates if we should just list files to deleted without actually deleting them."
required: false
bucket_dir:
description: 'A sub directory where the files are located within the S3 bucket.'
required: false

outputs:
results:
description: "Array of objects containing information about each file uploaded"
value: ${{ steps.action-script.outputs.results }}

runs:
using: "composite"
steps:
- name: Install dependencies
run: npm install --silent --no-progress --prefix $GITHUB_ACTION_PATH/..
shell: bash
- name: Run action script
id: action-script
env:
AWS_ACCESS_KEY_ID: ${{ inputs.aws_access_key_id }}
AWS_SECRET_ACCESS_KEY: ${{ inputs.aws_secret_access_key }}
run: |
node $GITHUB_ACTION_PATH/index.js \
--region ${{ inputs.aws_region }} \
--bucket ${{ inputs.aws_bucket_name }} \
--role ${{ inputs.aws_role }} \
${{ inputs.dry_run && '--dry' || '' }} \
${{ inputs.bucket_dir && format('--dir {0}', inputs.bucket_dir) || '' }}
shell: bash
27 changes: 27 additions & 0 deletions .github/actions/s3-delete/args.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import process from 'process'
import yargs from 'yargs'
import { hideBin } from 'yargs/helpers'

export const args = yargs(hideBin(process.argv))
.usage('$0 [options]')

.string('role')
.describe('role', 'S3 role ARN')

.string('bucket')
.describe('bucket', 'S3 bucket name')

.string('region')
.describe('region', 'AWS region location of S3 bucket. Defaults to us-east-1.')
.default('region', 'us-east-1')

.boolean('dry')
.default('dry', false)
.describe('dry', 'Runs the action script without actually uploading files.')
.alias('dry', 'dry-run')

.string('dir')
.describe('dir', 'Bucket sub-directory name. Leave empty to refer to the root of the bucket.')

.demandOption(['bucket', 'role'])
.argv
99 changes: 99 additions & 0 deletions .github/actions/s3-delete/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
import * as core from '@actions/core'
import { AssumeRoleCommand, STSClient } from '@aws-sdk/client-sts'
import { S3Client, S3ServiceException, paginateListObjectsV2, DeleteObjectsCommand, waitUntilObjectNotExists } from '@aws-sdk/client-s3'
import { args } from './args.js'

const stsClient = new STSClient({ region: args.region })
const s3Credentials = await stsClient.send(new AssumeRoleCommand({
RoleArn: args.role,
RoleSessionName: 'deleteExperimentFromS3Session',
DurationSeconds: 900
}))

const s3Client = new S3Client({
region: args.region,
credentials: {
accessKeyId: s3Credentials.Credentials.AccessKeyId,
secretAccessKey: s3Credentials.Credentials.SecretAccessKey,
sessionToken: s3Credentials.Credentials.SessionToken
}
})

async function collectKeysToDelete(bucketName, bucketDir) {
const keys = []
core.info("Bucket name: " + bucketName)
core.info(`Looking up files with prefix '${bucketDir}'`)

try {
const params = {
Bucket: bucketName,
Prefix:bucketDir
}
const paginator = paginateListObjectsV2({ client: s3Client }, params)
for await (const page of paginator) {
page.Contents?.forEach(obj => {
keys.push(obj.Key)
})
}
core.info(`Found ${keys.length} matching files`)
core.info(keys.map(k => ` • ${k}`).join('\n'))
return keys
} catch (err) {
if (err instanceof S3ServiceException) {
core.setFailed(
`Error from S3 while listing objects for "${bucketName}". ${err.name}: ${err.message}`,
)
} else {
core.setFailed(`Error while listing objects for "${bucketName}". ${err.name}: ${err.message}`)
}
process.exit(1)
}
}

async function deleteFiles(bucketName, keys) {
try {
core.info('Deleting...')

const { Deleted } = await s3Client.send(
new DeleteObjectsCommand({
Bucket: bucketName,
Delete: {
Objects: keys.map((k) => ({ Key: k })),
},
}),
)

for (const key in keys) {
await waitUntilObjectNotExists(
{ client: s3Client },
{ Bucket: bucketName, Key: key },
)
}
core.info(
`Successfully deleted ${Deleted?.length || 0} objects.`,
)
core.info(Deleted?.map((d) => ` • ${d.Key}`).join("\n"))
} catch (err) {
if (err instanceof S3ServiceException) {
core.setFailed(
`Error from S3 while deleting objects for "${bucketName}". ${err.name}: ${err.message}`,
)
} else {
core.setFailed(`Error while deleting objects for "${bucketName}". ${err.name}: ${err.message}`)
}
process.exit(1)
}
}

if (args.dry) {
core.info('This is a dry run.')
}
const keysToBeDeleted = await collectKeysToDelete(args.bucket, args.dir)
if (!args.dry) {
if (keysToBeDeleted.length > 0) {
await deleteFiles(args.bucket, keysToBeDeleted)
} else {
core.info('No files found to delete')
}
}
core.info('Completed successfully')
42 changes: 42 additions & 0 deletions .github/workflows/branch-cleanup.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# This workflow will run automatically when a branch is deleted.

name: Branch Cleanup

on: delete

jobs:
branch-delete:
if: github.event.ref_type == 'branch'
runs-on: ubuntu-latest
timeout-minutes: 5
defaults:
run:
shell: bash
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
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.
- name: Clean up for deleted branch
id: cleanup-start
run: echo "Clean up for branch ${{ github.event.ref }}"
- name: Delete dev experiment
id: s3-delete-dev
uses: ./.github/actions/s3-delete
with:
aws_access_key_id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws_secret_access_key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws_role: ${{ secrets.AWS_ROLE_ARN }}
aws_bucket_name: ${{ secrets.AWS_BUCKET }}
bucket_dir: experiments/dev/${{ github.event.ref }}
dry_run: true
- name: Delete staging experiment
id: s3-delete-staging
uses: ./.github/actions/s3-delete
with:
aws_access_key_id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws_secret_access_key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws_role: ${{ secrets.AWS_ROLE_ARN }}
aws_bucket_name: ${{ secrets.AWS_BUCKET }}
bucket_dir: experiments/staging/${{ github.event.ref }}
dry_run: true
40 changes: 40 additions & 0 deletions .github/workflows/delete-experiment.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# This workflow can be run on any branch.
# Given an environment, this workflow will delete the branch's experiment from S3

name: Delete Experiment

on:
workflow_dispatch:
inputs:
nr_environment:
description: 'Target New Relic environment'
required: true
type: choice
options:
- dev
- staging

jobs:
delete-experiment-on-s3:
runs-on: ubuntu-latest
timeout-minutes: 5
defaults:
run:
shell: bash
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
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.
- name: Clean branch name
id: clean-branch-name
run: echo "results=$(echo '${{ github.ref }}' | sed 's/refs\/heads\///g' | sed 's/[^[:alnum:].-]/-/g')" >> $GITHUB_OUTPUT
- name: Delete experiment
id: s3-delete
uses: ./.github/actions/s3-delete
with:
aws_access_key_id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws_secret_access_key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws_role: ${{ secrets.AWS_ROLE_ARN }}
aws_bucket_name: ${{ secrets.AWS_BUCKET }}
bucket_dir: experiments/${{ inputs.nr_environment }}/${{ steps.clean-branch-name.outputs.results }}
14 changes: 14 additions & 0 deletions .github/workflows/publish-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,20 @@ jobs:
fastly_key: ${{ secrets.FASTLY_PURGE_KEY }}
fastly_service: staging-js-agent.newrelic.com
asset_path: ${{ join(fromJson(steps.s3-upload.outputs.results).*.Key, ' ') }}
# This step creates a new Change Tracking Marker
- name: New Relic Application Deployment Marker
uses: newrelic/[email protected]
with:
apiKey: ${{ secrets.INTERNAL_STAGING_INGEST_LICENSE_KEY }}
guid: NTUwMzUyfEJST1dTRVJ8QVBQTElDQVRJT058ODkzODM5MjI
commit: "${{ github.sha }}"
version: "${{ github.ref_name }}"
user: "${{ github.actor }}"
# track build size as custom event
- name: Report local stats as NR event
uses: './.github/actions/nr-report-build-size'
with:
nr-api-key: ${{ secrets.INTERNAL_STAGING_INGEST_LICENSE_KEY }}

# Publish dev to staging NRDB
# publish-dev-nr:
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/pull-request-checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,10 @@ jobs:
pr_number: ${{ github.event.number }}
comment: ${{ steps.asset-size-report.outputs.results }}
comment_tag: <!-- browser_agent asset size report -->
- name: Report local stats as NR event
uses: './.github/actions/nr-report-build-size'
with:
nr-api-key: ${{ secrets.INTERNAL_STAGING_INGEST_LICENSE_KEY }}

# Jobs for workflow_dispatch events

Expand Down
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion third_party_manifest.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"lastUpdated": "Tue Dec 17 2024 16:31:01 GMT+0000 (Coordinated Universal Time)",
"lastUpdated": "Thu Dec 19 2024 20:09:27 GMT+0000 (Coordinated Universal Time)",
"projectName": "New Relic Browser Agent",
"projectUrl": "https://github.com/newrelic/newrelic-browser-agent",
"includeOptDeps": true,
Expand Down
2 changes: 1 addition & 1 deletion tools/lambda-test/webview-asset-ids.mjs
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export default { androidID: 'lt://APP10160341241734453059148955', iosID: 'lt://APP10160542501734453056523348' }
export default { androidID: 'lt://APP10160541191734638965500740', iosID: 'lt://APP10160542501734638964688891' }
2 changes: 1 addition & 1 deletion tools/test-builds/browser-agent-wrapper/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@
"author": "",
"license": "ISC",
"dependencies": {
"@newrelic/browser-agent": "file:../../../temp/newrelic-browser-agent-1.276.0.tgz"
"@newrelic/browser-agent": "file:../../../temp/newrelic-browser-agent-1.277.0.tgz"
}
}
2 changes: 1 addition & 1 deletion tools/test-builds/library-wrapper/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"license": "ISC",
"dependencies": {
"@apollo/client": "^3.8.8",
"@newrelic/browser-agent": "file:../../../temp/newrelic-browser-agent-1.276.0.tgz",
"@newrelic/browser-agent": "file:../../../temp/newrelic-browser-agent-1.277.0.tgz",
"graphql": "^16.8.1"
}
}
2 changes: 1 addition & 1 deletion tools/test-builds/raw-src-wrapper/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@
"author": "",
"license": "ISC",
"dependencies": {
"@newrelic/browser-agent": "file:../../../temp/newrelic-browser-agent-1.276.0.tgz"
"@newrelic/browser-agent": "file:../../../temp/newrelic-browser-agent-1.277.0.tgz"
}
}
Loading

0 comments on commit adcdb61

Please sign in to comment.