Run @relative-ci/cli on GitHub Actions

This page contains the setup guide for the RelativeCI agent v5. Go to RelativeCI agent v4 to follow the setup guide for the previous version.

Update configuration

Update .github/workflow/WORKFLOW.yml to run @relative-ci/cli after the build step is done:

.github/workflow/build.yml
name: Build
on:
push:
jobs:
build:
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Setup nodejs
uses: actions/setup-node@v4
- name: Install dependencies
run: npm ci
- name: Build application and export webpack stats
run: npm run build --json webpack-stats.json
- name: Send webpack stats and build information to RelativeCI
run: npx relative-ci
env:
RELATIVE_CI_KEY: ${{ secrets.RELATIVE_CI_KEY }}

Run from the project root directory

You can run the CLI from the project root directory using --config-dir / -c argument:

npx relative-ci --config-dir packages/components

pull_request event

When the action runs during the pull_request event, GitHub action checks out and reports the merge commit information:

GITHUB_REF='refs/pull/123/merge'
GITHUB_SHA='Merge #abcd124 into #abcd123'

In order to collect the information for the commit that triggered the pull request, the agent extracts the commit id from the GitHub action event data (event.json).

To extract the commit message, you can use one of the following methods:

  1. Git history
  2. GitHub API

Extract commit message from git history

To collect the corresponding commit message from the git history, configure the GitHub action to checkout a range of commits that includes the commit that triggered the pull request:

.github/workflow/build.yml
name: Build
on:
push:
branches:
- master
pull_request:
jobs:
build:
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
# Fetch latest 2 commits to allow relative-ci/agent-action
# to lookup the pull request corresponding commit message
fetch-depth: 2
- name: Setup nodejs
uses: actions/setup-node@v4
- name: Install dependencies
run: npm ci
- name: Build application and export webpack stats
run: npm run build --json webpack-stats.json
- name: Send webpack stats and build information to RelativeCI
run: npx relative-ci
env:
RELATIVE_CI_KEY: ${{ secrets.RELATIVE_CI_KEY }}

In case the agent fails to look up the commit that triggered the pull request, consider increasing the fetch-depth value.

Extract commit message using GitHub API

To collect the corresponding commit message using the GitHub API, pass GITHUB_TOKEN secret to the agent. When the token is present , the agent will fetch the corresponding commit from GitHub.

contents: read permission is required to fetch the commit details from the GitHub API. Read more about GITHUB_TOKEN permissions


.github/workflow/build.yml
name: Build
on:
push:
branches:
- master
pull_request:
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 'latest'
# 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 webpack stats and build information to RelativeCI
run: npx relative-ci
env:
RELATIVE_CI_KEY: ${{ secrets.RELATIVE_CI_KEY }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

Forked repositories and dependabot workflows

GitHub actions do not share secrets with workflows triggered by forked repositories or insecure workflows.

With the exception of GITHUB_TOKEN, secrets are not passed to the runner when a workflow is triggered from a forked repository. (Using encrypted secrets in a workflow)

To securely run @relative-ci/agent for builds triggered by forked repositories or insecure workflows(eg: dependabot), use RelativeCI/agent GitHub Action.





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