Skip to content

Application Selection

Rendering the manifests generated by all applications in the repository on each pull request can be slow. Limiting the number of applications rendered can speed up the rendering process significantly. By default, argocd-diff-preview will render all applications in the repository.

Here are 4 ways to limit which applications are rendered:

Rendering only changed applications

You can configure the tool to render only the applications affected by changes in a pull request. This optimizes the rendering process by focusing on the applications directly impacted by the modified files.

To achieve this, you need to add the annotation: argocd-diff-preview/watch-pattern to all your Applications/ApplicationSets, and provide the tool with a list of changed files. If no list is provided, the annotation will be ignored. The watch-pattern annotation takes a comma-separated list of file paths or regex patterns. The tool will render the application if any of the patterns match the changed files.

Example:

By adding the annotation argocd-diff-preview/watch-pattern: "examples/helm/charts/myApp/.*, examples/helm/values/filtered.yaml" to the Application manifest, the my-app application will only be rendered if the filtered.yaml file or a file in the examples/helm/charts/myApp/ folder is modified in the PR. However, the my-app application will also be rendered if its own Application manifest is changed, so there's no need to include the application's file path in the watch-pattern annotation.

Application
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
  name: my-app
  namespace: argocd
  annotations:
    argocd-diff-preview/watch-pattern: "examples/helm/charts/myApp/.*, examples/helm/values/filtered.yaml"
spec:
  sources:
    - repoURL: https://github.com/dag-andersen/argocd-diff-preview
      ref: local-files
    - path: examples/helm/charts/myApp
      repoURL: https://github.com/dag-andersen/argocd-diff-preview
      helm:
        valueFiles:
          - $local-files/examples/helm/values/filtered.yaml
  ...

How to use it in a GitHub Actions Workflow

You can use the tj-actions/changed-files action in your workflow and pass the output to the argocd-diff-preview tool. Providing the tool with a list of changed files will ensure you only render applications that watch those file paths. Any application without the argocd-diff-preview/watch-pattern annotation will be ignored.

.github/workflows/generate-diff.yml
name: Generate Diff Tool Change

on:
  pull_request:
    branches:
      - "main"

jobs:
  build:
    runs-on: ubuntu-latest
    permissions:
      contents: read
      pull-requests: write

    steps:
      - name: Get changed files
        id: changed-files
        uses: tj-actions/changed-files@v45

      - uses: actions/checkout@v4
        with:
          path: pull-request

      - uses: actions/checkout@v4
        with:
          ref: main
          path: main

      - name: Generate Diff
        run: |
          docker run \
            --network=host \
            -v /var/run/docker.sock:/var/run/docker.sock \
            -v $(pwd)/main:/base-branch \
            -v $(pwd)/pull-request:/target-branch \
            -v $(pwd)/output:/output \
            -e TARGET_BRANCH=${{ github.head_ref }} \
            -e REPO=${{ github.repository }} \
            -e FILES_CHANGED="${{ steps.changed-files.outputs.all_changed_files }}"
            dagandersen/argocd-diff-preview:v0.0.24

Ignoring individual applications

You can exclude specific applications from rendering by adding the annotation argocd-diff-preview/ignore: "true" to their manifest. This is useful for skipping applications that don’t require a diff preview.

Examples:

Application
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
  name: my-app
  namespace: argocd
  annotations:
    argocd-diff-preview/ignore: "true"
spec:
  ...

ApplicationSet
apiVersion: argoproj.io/v1alpha1
kind: ApplicationSet
metadata:
  name: my-app
  annotations:
    argocd-diff-preview/ignore: "true"
spec:
  ...

Label Selectors

Run the tool with the --selector option to filter applications based on labels. The option supports =, ==, and !=.

Example:

argocd-diff-preview --selector "team=a"
This command :arrow_up: will target the following application :arrow_down: and ignore all applications that do not have the label team: a.

Application
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
  name: my-app
  labels:
    team: a
spec:
  ...

Application File Path Regex

Alternatively, use the --file-regex option to limit rendering to Applications whose file paths match a regular expression. This is helpful when rendering changes from specific teams or directories.

Example:

If someone in your organization from Team A changes one of their applications, the tool can be run with:

argocd-diff-preview --file-regex="/Team-A/"
This ensures only applications in folders matching */Team-A/* are rendered.