Skip to content

argocd-preview.yml

Comment on PRs with preview URLs and optionally trigger an ArgoCD redeploy for preview environments.

Inputs

InputTypeDescriptionRequiredDefault
APP_URL_TEMPLATEstringTemplate that can include <pr_number>Yes-
PR_NUMBERnumberPull request numberYes-
ARGOCD_APP_NAME_TEMPLATEstringArgoCD app name template (may include <pr_number>)Yes-
ARGOCD_SYNC_PAYLOAD_TEMPLATEstringArgoCD sync payload templateYes-
ARGOCD_URLstringURL of the Argo-CD serverYes-

Secrets

SecretDescriptionRequiredDefault
ARGOCD_TOKENToken used to redeploy the ArgoCD appYes-

Permissions

ScopeAccessDescription
pull-requestswriteRequired to post PR comments
contentsreadRead repository (templates)

Notes

  • The redeploy step runs only when the PR has the preview label and PR_NUMBER is provided. ARGOCD_TOKEN must be set to authenticate redeploy requests. Template inputs accept the <pr_number> placeholder.

Examples

Simple example

yaml
jobs:
  preview:
    uses: this-is-tobi/github-workflows/.github/workflows/argocd-preview.yml@main
    with:
      APP_URL_TEMPLATE: https://app-name.pr-<pr_number>.example.com
      PR_NUMBER: 123
      ARGOCD_APP_NAME_TEMPLATE: app-name-pr-<pr_number>
      ARGOCD_SYNC_PAYLOAD_TEMPLATE: '{"appNamespace":"argocd","prune":true,"dryRun":false,"strategy":{"hook":{"force":true}},"resources":[{"group":"apps","version":"v1","kind":"Deployment","namespace":"app-name-pr-<pr_number>","name":"app-name-pr-<pr_number>-client"},{"group":"apps","version":"v1","kind":"Deployment","namespace":"app-name-pr-<pr_number>","name":"app-name-pr-<pr_number>-server"}],"syncOptions":{"items":["Replace=true"]}}'
      ARGOCD_URL: https://argo-cd.example.com
    secrets:
      ARGOCD_TOKEN: ${{ secrets.ARGOCD_TOKEN }}