RelativeCI

In-depth webpack bundle analysis and monitoring

Setup GitHub action

Step 1. Output webpack stats JSON file

Follow the steps on Output webpack stats JSON file guide.

Step 2. Configure GitHub action

Depending on your GitHub workflows, you can configure relative-ci/agent-action to run during the following events:

  1. push / pull_request
  2. workflow_run (recommended for workflows triggered by forks)

push/pull_request event

Add relative-ci/agent-action after your build step(the build step will output the webpack stats depending on Step 1. setup).

.github/workflow/build.yml
name: Build
on:
push:
branches:
- master
pull_request:
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: '16.x'
# Install dependencies
- run: npm ci
# Build and output webpack stats to webpack-stats.json
- run: npm run build --json webpack-stats.json
# Send webpack stats and build information to RelativeCI
- name: Send webpack stats to RelativeCI
uses: relative-ci/agent-action@v2
with:
webpackStatsFile: ./webpack-stats.json
key: ${{ secrets.RELATIVE_CI_KEY }}
token: ${{ secrets.GITHUB_TOKEN }}

pull_request event

When the action is running on the pull_request event, GitHub is reporting the merge commit information:

GITHUB_REF='refs/pull/2377/merge'
GITHUB_SHA='Merge #abc124 into #abc123'

relative-ci/agent-action collects the build information from the event data (event.json) and sends the id & message corresponding to the commit that triggered the pull request.


workflow_run event

Workflows triggered by forked repositories

GitHub actions do not share secrets with workflows triggered by forked repositories. To safely run action steps that require access to secrets, GitHub recommends running the workflow on workflow_run event.

When the workflow is triggered by the workflow_run event, the jobs are running in the context of the base branch, making it safe to access the repository secrets. relative-ci/agent-action collects the build information from the event data (event.json) and the webpack stats from the artifacts uploaded during the build workflow(build.yaml)

Workflow 1: Build and upload webpack stats artifacts

Build and upload webpack stats artifact using relative-ci/agent-upload-artifact-action:

.github/workflows/build.yaml
name: Build
on:
push:
branches:
- master
pull_request:
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: '16.x'
# Install dependencies
- run: npm ci
# Build and output webpack stats to webpack-stats.json
- run: npm run build --json webpack-stats.json
# Upload webpack-stats.json to use on relative-ci.yaml workflow
- name: Upload webpack stats artifact
uses: relative-ci/agent-upload-artifact-action@v1
with:
webpackStatsFile: ./webpack-stats.json

Workflow 2. Send webpack stats and build information to RelativeCI

The workflow runs securely in the default branch context(ex: main). relative-ci/agent-action uses the build information (commit, message, branch) from the depending workflow (ex: Builds).

.github/workflows/relative-ci.yaml
name: RelativeCI
on:
workflow_run:
workflows: ["Build"]
types:
- completed
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Send webpack stats to RelativeCI
uses: relative-ci/agent-action@v2
with:
key: ${{ secrets.RELATIVE_CI_KEY }}
token: ${{ secrets.GITHUB_TOKEN }}

Secrets

RELATIVE_CI_KEY

(Required) Navigate to https://app.relative-ci.com, go to the project Settings -> API Keys page and copy the project API key.

Inputs

View action.yml

  • key (required): RelativeCI project key
  • token (required): GitHub token
  • webpackStatsFile (required on push/pull_request events): Path to webpack stats file
  • endpoint (required for Enterprise Cloud customers)
  • slug (default GITHUB_REPOSITORY): Your project slug
  • includeCommitMessage ( default true): send commit message
  • debug (default false): Enable debug output
  • artifactName (default relative-ci-artifacts on workflow_run): The name of the artifact with webpack stats uploaded by another workflow
  • artifactWebpackStatsFile (default: webpack-stats.json on workflow_run): The artifact webpack stats file path





Need help?Contact us via email, Twitter, or GitHub!

Start analyzing and monitoring yourwebpack bundle