action icon indicating copy to clipboard operation
action copied to clipboard

empty github environment created for each deployment

Open altaurog opened this issue 1 year ago • 2 comments

Pullpreview seems to be creating an empty github deployment environment for each PR. This makes managing real environments rather difficult. What is the purpose and how can we prevent it altogether, or at least have them removed together with the deployment?

altaurog avatar Apr 02 '24 09:04 altaurog

Hi, it's not empty at the time of deploy, but after the PullPreview env gets destroyed indeed it stays as an env, and has to be deleted manually from the Deployments UI. This is a limitation of the GitHub Token given to the PullPreview action, it does not allow removing deployments altogether (understandably since this could have nasty side-effects).

The only solution would be to allow PullPreview to get a PAT or GitHub App token, given as action input. But then that defeats a bit the simplicity, so not sure what to do yet.

crohr avatar Apr 08 '24 19:04 crohr

got it. It was easy enough to delete them via the api, but it is definitely annoying. This worked for me:

gh api /repos/$ORG/$REPO/environments?per_page=100 | 
    jq -r '.environments[]|.name' | 
    grep -E '^gh-[0-9]+-pr-[0-9]+' | 
    while read env
        do gh api --method DELETE /repos/$ORG/$REPO/environments/$env
    done

How is the environment used?

altaurog avatar Apr 09 '24 07:04 altaurog

This can now be auto-cleaned up via #89 and the use of a custom GitHub token (PAT or generated by https://github.com/actions/create-github-app-token) with the correct permissions.

crohr avatar Aug 24 '24 07:08 crohr