A GitHub Action to capture a New Relic event describing your build size metrics.
Key | Required | Default | Description |
---|---|---|---|
analysis-file-contents |
If analysis-type is not manual and no analysis-file-url values are supplied |
- | Build analysis file contents -- Takes precendence over analysis-file-url when both are supplied. |
analysis-file-url |
If analysis-type is not manual and no analysis-file-contents values are supplied |
- | Public URL to the analysis file - When supplied without the analysis-file-contents, the action will fetch the file contents from the URL. It will decorate all events created with a link to the uploaded asset. |
analysis-type |
**If using manual-* values, must be manual |
webpack |
Type of analysis file to parse. Please note: webpack assumes the file supplied was generated using webpack-bundle-analyzer |
commit |
- | github.sha |
Commit identifier of the build |
event-type |
- | BuildSize |
Type of event to be captured |
file-name-filter |
- | - | When supplied, will only include entrypoint file names that include the given substring - When undefined, will include everything in the analysis file |
manual-analysis-file-name |
If analysis-type is manual |
- | Manually supply the file name of your build - Takes precendence over analysis-file-contents and analysis-file-url when supplied. Only works if analysis-type is "manual" |
manual-analysis-file-size |
If analysis-type is manual |
- | Manually supply the file name of your build - Takes precendence over analysis-file-contents and analysis-file-url when supplied. Only works if analysis-type is "manual" |
manual-analysis-gzip-size |
If analysis-type is manual |
- | Manually supply the file name of your build - Takes precendence over analysis-file-contents and analysis-file-url when supplied. Only works if analysis-type is "manual" |
nr-account-id |
Always | - | New Relic Account ID to be used to capture events |
nr-api-key |
Always | - | New Relic API key to be used to capture events |
nr-env |
- | US |
NR Environment to be used to capture events. Valid values are US . EU to be supported in the future |
traverse |
- | false |
When true, will traverse all subtrees and capture events for each item. Currently only supports webpack analysis type. |
trigger |
- | github.workflow |
Trigger of the capturing the build size. Can be useful if you have differing reasons or jobs for capturing the build size across your repository. |
user |
- | github.actor |
User who triggered the build |
version |
- | github.ref_name |
Version of the build |
Github secrets assumed to be set:
NEW_RELIC_API_KEY
- New Relic API keyNEW_RELIC_ACCOUNT_ID
- New Relic Account ID
There are a number of default GitHub environment variables that are used in these examples as well.
name: Capture Build Size With New Relic
on:
workflow_dispatch:
push:
jobs:
report-build-size:
runs-on: ubuntu-latest
name: Report Webpack Stats To New Relic
steps:
- name: Checkout
uses: actions/checkout@v4
# This step parses the build stats (URL) and creates NR events
- name: Capture Build Size
uses: newrelic/[email protected]
with:
analysis-file-url: https://foo.bar/mybuild.stats.json
nr-account-id: ${{ secrets.NEW_RELIC_ACCOUNT_ID }}
nr-api-key: ${{ secrets.NEW_RELIC_API_KEY }}
name: Capture Build Size With New Relic
on:
workflow_dispatch:
push:
jobs:
report-build-size:
runs-on: ubuntu-latest
name: Report Webpack Stats To New Relic
steps:
- name: Checkout
uses: actions/checkout@v4
# This step builds the code (and includes the webpack-bundle-analyzer)
- name: Build
run: npm run build
# This step reads the locally made stats file (assuming to be located in "./build")
- name: Get local stats file
id: get-stats
shell: bash
run: |
stats=$(cat ./build/mybuild.stats.json); echo "stats=$stats" >> $GITHUB_OUTPUT;
# This step parses the Build stats (file) and creates NR events
- name: Capture Build Size
uses: newrelic/[email protected]
with:
analysis-file-contents: ${{ steps.get-stats.output.stats }}
nr-account-id: ${{ secrets.NEW_RELIC_ACCOUNT_ID }}
nr-api-key: ${{ secrets.NEW_RELIC_API_KEY }}
name: Capture Build Size With New Relic
on:
workflow_dispatch:
push:
jobs:
report-build-size:
runs-on: ubuntu-latest
name: Report Webpack Stats To New Relic
steps:
- name: Checkout
uses: actions/checkout@v4
# This step builds the code
- name: Build
run: npm run build
# This step parses the Build stats (file) and creates NR events
- name: Capture Build Size
uses: newrelic/[email protected]
with:
analysis-type: 'manual'
manual-analysis-file-name: 'main-Build' # the file name to report
manual-analysis-file-size: 12345 # Some value calculated manually
nr-account-id: ${{ secrets.NEW_RELIC_ACCOUNT_ID }}in your build steps that does not rely on an explicit analysis file like webpack-build-analyzer
nr-api-key: ${{ secrets.NEW_RELIC_API_KEY }}
name: Capture Build Size With New Relic
on:
pull_request: # run on pull request sync events
jobs:
report-build-size:
runs-on: ubuntu-latest
name: Report Webpack Stats To New Relic
steps:
- name: Checkout
uses: actions/checkout@v4
# This step parses the Build stats (URL) and creates NR events
- name: Capture Build Size
uses: newrelic/[email protected]
with:
analysis-file-url: https://foo.bar/mybuild.stats.json # the webpack stats file URL
analysis-type: 'webpack' # parse a webpack stats file
commit: ${{ github.sha }} # the commit that triggered the action
event-type: 'MyBuildSize' # report the event with a custom event type
file-name-filter: '.min.js' # only include entrypoints that are minified
nr-account-id: ${{ secrets.NEW_RELIC_ACCOUNT_ID }} # US environment account
nr-api-key: ${{ secrets.NEW_RELIC_API_KEY }} # US environment api key
nr-env: 'US' # US environment
traverse: true # Will create events for each sub-file in the analysis file
trigger: 'PR' # Indicate the build was tied to a PR
user: ${{ github.actor }} # the user who raised the PR
version: ${{ github.ref_name }} # the PR number tied to the action
- In NR1, log into the account you pointed the action to report to.
- Select "Query your data"
- Run the given NRQL query
- "analysisFileUrl"
- "analysisType"
- "commit"
- "entryPoint"
- "fileName"
- "fileSize"
- "gzipSize"
- "isInitialEntrypoint"
- "timestamp"
- "trigger"
- "user"
- "version"
This example assumes you are collecting BuildSize
events every time your main branch changes
FROM BuildSize select latest(fileSize)/1000 as 'KB' where isInitialEntrypoint where version = 'main' facet fileName timeseries since 1 week ago
This example assumes you are collecting BuildSize
events every time your main branch changes
FROM BuildSize select latest(fileSize)/1000 as 'KB' where isInitialEntrypoint is not true where version = 'main' facet fileName timeseries since 1 week ago
This examples assumes you are collecting BuildSize
events every time your main branch changes as well as when a PR is created/updated. Each PR BuildSize
will have a version
attribute matching its PR number.
FROM BuildSize select latest(fileSize)/1000 as 'KB', latest(gzipSize)/1000 as 'GZIP KB', latest(timestamp), latest(commit) as 'SHA' where fileName = <file name> facet version
This examples assumes you are collecting BuildSize
events every time your main branch changes as well as when a PR is created/updated. Each PR BuildSize
will have a version
attribute matching its PR number.
FROM BuildSize select stddev(fileSize)/1000 as 'Stddev KB' where fileName = <file name> facet version
This examples assumes you are collecting BuildSize
events every time your main branch changes as well as when a PR is created/updated. Each PR BuildSize
will have a version
attribute matching its PR number.
FROM BuildSize select latest(fileSize)/1000 as 'KB', latest(gzipSize)/1000 as 'GZIP KB', latest(timestamp), latest(commit) as 'SHA' where fileName = <file name> and user = <user id> facet version