Use FSL with GitHub Actions

This shows you how to leverage FSL in your CI/CD workflow by using GitHub Actions to streamline your database management and operations. This allows you to manipulate schema programmatically when doing local development.

In your project, create a .github/workflows/main.yml file with the following code snippet that defines your CI/CD pipeline:

name: Main CI

# Trigger the workflow on a push to the 'main' branch
on:


  push:
    branches: [ main ]

# Define jobs to be run by the workflow
jobs:
  ci:  # This is the identifier for the job
    runs-on: ubuntu-latest  # Specifies that the job should run on the latest Ubuntu runner
    env:
      # Set an environment variable using a secret stored in the repository's secrets
      FAUNA_SECRET_KEY: ${{ secrets.FAUNA_SECRET_KEY }}

    strategy:
      matrix:
        node-version: [18.x]

    # Steps to be run as part of this job
    steps:
    - uses: actions/checkout@v3  # Checks out the repository code

    - name: Use Node.js ${{ matrix.node-version }}
      uses: actions/setup-node@v3  # Sets up the Node.js environment
      with:
        node-version: ${{ matrix.node-version }}  # Use the Node.js version from the strategy matrix

    - name: Install dependencies
      run: npm install  # Install npm dependencies specified in package.json

    - name: Install Fauna CLI
      run : npm install -g fauna-shell  # Install Fauna CLI globally with npm

    # Push the schema to a test database, potentially overwriting existing schema
    - name: Push schema to Test Database
      run: fauna schema push --force --secret $FAUNA_SECRET_KEY # Using the force flag will omit user confirmation input
      env:
        FAUNA_SECRET_KEY: ${{ secrets.FAUNA_SECRET_KEY }}

    - name: Run tests
      run: npm test  # Run tests using the npm test script

    # Reset the test database by pushing a cleanup schema
    - name: Reset Test Database
      run: fauna schema push --dir=./cleanup/ --force --secret $FAUNA_SECRET_KEY
      # An additional environment variable for this step
      env:
        FAUNA__SECRET_KEY: ${{ secrets.FAUNA_SECRET_KEY }}

Is this article helpful? 

Tell Fauna how the article can be improved:
Visit Fauna's forums or email docs@fauna.com

Thank you for your feedback!