Automatic mirroring

Automatic mirroring

You define lekkos as functions in your code that control pieces of your system’s behavior. However, to support dynamic changes and allow sharing of lekkos across projects, Lekko maintains a separate source of truth repository for all of your lekkos.

But if that’s the case, how do you get lekko changes from one project into another project? After making a change on the web UI, how do you pull changes from the source of truth into your project?

This is where automatic mirroring comes in. Lekko integrates with GitHub to ensure your configuration changes are propagated throughout your whole system.

Lekko to code

Lekko integrates with GitHub webhooks to mirror changes you make to your lekkos via the web UI to your connected projects. When following our Getting Started guide, the Lekko GitHub app is added to your GitHub organization and given access to relevant project repositories. This is what allows Lekko’s services to identify which projects need to be updated.

When a change is received from the web UI (or from another project, as described in the next section), the relevant changes are translated to your projects' languages and applied. Then, pull requests are automatically opened based on these changes.

You can choose whether to allow these generated pull requests to be auto-merged or not in your team’s settings.

Code to Lekko

Lekko publishes lekkodev/push-action (opens in a new tab) as a GitHub Action to automatically detect when pull requests in your projects contain lekko changes.

You can add this Action to your CI workflow like the following example:

.github/workflows/ci.yaml
name: ci
on:
  # Run this workflow when pull requests are opened or updated against main
  pull_request:
    branches:
      - main
  # Run this workflow when a commit is pushed to main (e.g. a pull request is merged)
  push:
    branches:
      - main
permissions:
  contents: read
jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      # It is required to checkout and install dependencies for your project before the Lekko push step
      - name: Checkout project
        uses: actions/checkout@v4
      - name: Set up language-specific environment
        uses: actions/setup-node@v4
        with:
          node-version: 18
      - name: Install project dependencies
        run: npm install
      - name: Other CI steps
        run: |
          npm run build
          npm run test
      - uses: lekkodev/push-action@v1.0.2
        with:
          api_key: ${{ secrets.LEKKO_API_KEY }}

This Action detects lekko changes and comments their names and statuses on your pull requests via the Lekko GitHub app.

Push Action example

Then, when your changes are merged, the changes are pushed and applied to the source of truth repository automatically.

Handling conflicts

There are cases where a lekko change from your project might conflict with a change made on the web UI (or from another project) at the same time and so the change cannot be mirrored automatically.

When this happens, the Action handles automatically opening a fix pull request that you can checkout. This pull request comes with step-by-step instructions that you can follow to resolve the conflict.

Fix PR example