Calibre’s CLI is optimised for use in CI/CD environments. You can use the CLI to automate performance testing of your sites in Calibre.
Prerequisites#
- Create an API token for the Calibre API. Add the API Token to a GitHub Repository secret.
- Use
CALIBRE_API_TOKENenvironment variable to authenticate with Calibre CLI. - Obtain a Site slug identifier from Calibre by visiting Site → Settings → General. Add the Site slug to a GitHub Repository secret named
CALIBRE_SITE_SLUG. - Create a
.github/workflows/calibre.ymlworkflow file in your repository.
Check Command Line Interface documentation for more information about the available commands.
Example workflow: Compare performance of a Pull Request to a production environment#
Detect Pull Request preview deployments from GitHub. Each time a Pull Request is deployed to a preview environment, Calibre will run a performance test and compare the results to the production environment.
./github/workflows/calibre-pull-request-review.yml
name: Calibre Pull Request Review
on: [deployment_status]
jobs:
# Start a new Pull Request Review.
# Output will be written to the GitHub Step Summary.
# See https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#adding-a-job-summary for more info.
pr_review:
# Only run this job if the deployment status is successful
# Only complete this job if the deployment's branch corresponds to a Pull Request
# Optional: filter by environment name or URL - contains(github.event.deployment_status.environment_url, 'onrender.com')
if: github.event.deployment_status.state == 'success' && contains(github.event.deployment_status.environment_url, 'onrender.com')
name: Pull Request Review
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4 # Required for `gh pr view`
- id: pr
env:
GH_TOKEN: ${{ github.token }}
run: |
echo "PR_TITLE=$(gh pr view "${{ github.ref_name }}" --json 'title' --jq '.title')" >> "$GITHUB_OUTPUT"
- name: Run Pull Request Review
id: pull_request_review
if: steps.pr.outputs.PR_TITLE != null
env:
CALIBRE_API_TOKEN: ${{ secrets.CALIBRE_API_TOKEN }}
run: |
echo "PULL_REQUEST_REVIEW_REPORT=$(npx calibre site create-pull-request-review \
--title="${{ steps.pr.outputs.PR_TITLE }}" \
--site="${{ secrets.CALIBRE_SITE_SLUG }}" \
--branch="${{ github.ref_name }}" \
--sha="${{ github.sha }}" \
--url="${{ github.event.deployment_status.environment_url }}" \
--waitForResult \
--markdown)" >> $GITHUB_OUTPUT
- name: Post PR comment
if: steps.pr.outputs.PR_TITLE != null
env:
GH_TOKEN: ${{ github.token }}
run: |
gh pr comment "${{ github.ref_name }}" --body "${{ steps.pull_request_review.outputs.PULL_REQUEST_REVIEW_REPORT }}"
- name: Post Job summary
if: steps.pr.outputs.PR_TITLE != null
env:
GH_TOKEN: ${{ github.token }}
run: |
echo "${{ steps.pull_request_review.outputs.PULL_REQUEST_REVIEW_REPORT }}" > $GITHUB_STEP_SUMMARYExample workflow: Notify Calibre of a production deploy#
Merges to the main branch will trigger the workflow and create a deploy marker in Calibre.
./github/workflows/calibre-production-deploy-notification.yml
name: Notify Calibre of production deploy
on:
push:
branches:
- main
jobs:
build:
name: Notify Calibre
runs-on: ubuntu-latest
steps:
- name: Create deploy
uses: actions/setup-node@v3
env:
CALIBRE_API_TOKEN: ${{ secrets.CALIBRE_API_TOKEN }}
run: |
npx calibre site create-deploy --site=${{ secrets.CALIBRE_SITE_SLUG }} --revision=${{ env.GITHUB_SHA }} --repository https://github.com/${{ env.GITHUB_REPOSITORY }}
- name: Get result
run: echo "${{steps.set-result.outputs.result}}"