Skip to main content

GitHub Action: preview-labels-cleanup

Remove labels used to control deployments with github-action-preview-environment-controller

Introduction

On close a pull request we need to cleanup all labels that specify a preview environments where the PR was deployed. This GitHub action integrates with github-action-preview-environment-controller action

Usage

  name: Pull Request
on:
pull_request:
branches: [ 'main' ]
types: [opened, synchronize, reopened, closed, labeled, unlabeled]

jobs:
context:
runs-on: ubuntu-latest
steps:
- name: Preview deployments controller
uses: cloudposse/github-action-preview-environment-[email protected]
id: controller
with:
labels: ${{ toJSON(github.event.pull_request.labels.*.name) }}
open: ${{ github.event.pull_request.state == 'open' }}
env-label: |
preview: deploy

outputs:
labels_env: ${{ steps.controller.outputs.labels_env }}

destroy:
runs-on: ubuntu-latest
if: ${{ github.event.pull_request.state != 'open' }}
needs: [ context ]
steps:
- name: Cleanup label
uses: cloudposse/github-action-preview-labels-cleanup
with:
labels_env: ${{ needs.context.outputs.labels_env }}
env: preview

Inputs

NameDescriptionDefaultRequired
envEnvironmentN/Atrue
labels_envJSON formatted {label}: {environment} map{}true
pr_numberThe number of the pull request, which will default to extracting from the workflow event if not specified.N/Afalse

Outputs

NameDescription