The following example shows how to use Momentic with GitHub Actions.

For more usage examples, see the momentic-ai/examples repository.

For a given root package.json:

package.json
{
  "name": "my-momentic-repo",
  "scripts": {},
  "devDependencies": {
    "momentic": "latest"
  }
}

Create a file called .github/workflows/ci.yml in your repository with the following contents:

ci.yml
name: CI

on:
  push:
    branches: ["main"]
  pull_request:
    types: [opened, synchronize]

jobs:
  build:
    name: Test
    timeout-minutes: 15
    runs-on: ubuntu-latest

    steps:
      - name: Check out code
        uses: actions/checkout@v4
        with:
          fetch-depth: 2

      - name: Setup Node.js environment
        uses: actions/setup-node@v4
        with:
          node-version: 20
          cache: "npm"

      - name: Install dependencies
        run: npm install

      - name: Install browsers
        run: npx momentic install-browsers --all

      - name: Test
        run: npx momentic run
        continue-on-error: true

      - name: Upload results
        run: npx momentic results upload test-results

Authentication

To run any commands, you must authenticate with Momentic. You can do this by adding the MOMENTIC_API_KEY environment variable to your GitHub Actions workflow.

  1. Create an API key in Momentic Cloud.

Copy the value to a safe place. You’ll need it in a moment.

  1. Go to your GitHub repository settings and click on the Secrets and then Actions tab. Create a new secret called MOMENTIC_API_KEY and enter the value of your API key.
  1. At the top of your GitHub Actions workflow, provide the following environment variables to jobs that use momentic:
ci.yml
# ...

jobs:
  build:
    name: Build and Test
    timeout-minutes: 15
    runs-on: ubuntu-latest
    # To authenticate, set the following environment variables.
    env:
      MOMENTIC_API_KEY: ${{ secrets.MOMENTIC_API_KEY }}

    steps:
      - name: Check out code
        uses: actions/checkout@v4
        with:
          fetch-depth: 2
    # ...