Update configuration
Update .github/workflow/WORKFLOW.yml
to run @relative-ci/cli after the build step is done:
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:
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:
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, add a step to fetch the commit information and set the RELATIVE_CI_COMMIT_MESSAGE
environment variable:
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
# Read pull request commit message - name: Read pull request commit message id: pull-request-commit-message run: | # Get the pull request commit's SHA/ID from the event data file COMMIT_SHA=$(cat $GITHUB_EVENT_PATH | jq -r ".pull_request.head.sha")
# Fetch commit data from the GitHub API and pick the commit message value COMMIT_MESSAGE=$(gh api /repos/$GITHUB_REPOSITORY/commits/$COMMIT_SHA --jq .commit.message)
# Set output echo "commit-message=$COMMIT_MESSAGE" > $GITHUB_OUTPUT env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# 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 }} RELATIVE_CI_COMMIT_MESSAGE: ${{ steps.pull-request-commit-message.outputs.commit-message }}
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.