How do I maintain preview environment URLs and cleanup when using custom PR approval workflows?

Last updated: September 12, 2025

Context

When customizing GitHub Actions workflows to create preview environments only after PR approval (using pull_request_review event), the default Porter preview environment features like automatic URL posting to PR comments and environment cleanup after merge are no longer automatically handled.

Answer

While automatic URL posting and cleanup aren't supported with custom PR approval workflows, you can manually retrieve and manage these features:

To get the preview environment URL:

  1. After the preview environment is created, run the following command to get the domain:

    porter app run -x <pr-branch> <app-name> -- env | grep PORTER_DOMAINS

    This will return a comma-separated list of domains linked to your preview environment.

To cleanup the preview environment after merge:

  1. When the PR is merged or closed, run:

    porter target delete --name <pr-branch>

    This will remove the preview environment and clean up associated resources.

Note that these manual steps are necessary because the custom workflow using the pull_request_review event doesn't integrate with Porter's default preview environment handling system.