GitHub action agent

Step 1. Output bundle stats JSON file

Follow the steps on Output bundle stats JSON file guide.

Step 2. Configure GitHub action

Depending on your GitHub workflow, you can use the following scenarious to configure relative-ci/agent-action:

push / pull_request

One-step setup for private or small projects

workflow_run

Two steps workflow recommended for open-source projects, projects that use forks, or teams with increased security requirements

push/pull_request event

Add relative-ci/agent-action after your build step(the build step will output the bundle 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@v3
- uses: actions/setup-node@v3
with:
node-version: '18.x'
# Install dependencies
- run: npm ci
# Build and output bundle stats to webpack-stats.json
- run: npm run build --json webpack-stats.json
# Send bundle stats and build information to RelativeCI
- name: Send bundle 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 runs during the pull_request event, GitHub reports 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 actual 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 bundle stats from the artifacts uploaded during the build workflow(build.yaml)

Workflow 1: Build and upload bundle stats artifacts

Build and upload bundle 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@v3
- uses: actions/setup-node@v3
with:
node-version: '18.x'
# Install dependencies
- run: npm ci
# Build and output bunle 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 bundle stats and build information to RelativeCI

Create a new workflow triggered by the previous build workflow (Build) to download the bundle stat artifact and send it to RelativeCI. The workflow runs securely in the default branch context(ex: main). relative-ci/agent-action uses the build information (commit, message, branch) corresponding to the commit that triggered the Build workflow.

.github/workflows/relative-ci.yaml
name: RelativeCI
on:
workflow_run:
workflows: ["Build"]
types:
- completed
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Send bundle stats and build information 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): Get current commit message (git log -1 --pretty=%B) and send it to RelativeCI as part of the build informatin
  • debug (default false): Enable debug output
  • artifactName (default relative-ci-artifacts on workflow_run): The name of the artifact with bundle stats uploaded by another workflow
  • artifactWebpackStatsFile (default: webpack-stats.json on workflow_run): The artifact bundle stats file path





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

Start analyzing and monitoring yourbundle stats