How do I configure GitHub Workflow for Ephemeral PR Preview Teardown on Merge?
External Action
The configuration described here takes place outside of Wayfinder.
Prerequisites
Why do I need this configuration?
In this section you're configuring the .github/workflows/pr-closed.yaml
file so that it deletes your ephemeral PR Preview environment when you close your PR.
Update .github/workflows/pr.yaml
Update the .github/workflows/pr-closed.yaml
file as per the example.
In the section below you are assigning the values for the workspace access token's variables that you've created earlier.
env:
WAYFINDER_SERVER: ${{ vars.WAYFINDER_SERVER }}
WAYFINDER_WORKSPACE: ${{ vars.WAYFINDER_WORKSPACE }}
WAYFINDER_TOKEN: ${{ secrets.WAYFINDER_TOKEN }}
In the section below you are deleting your ephemeral PR Preview environment when you close your PR.
run: |
export ENV_NAME="pr-${{ github.event.pull_request.number }}"
wf delete appenv ${{ vars.APP_NAME }}-${ENV_NAME} || true
Following below is the complete example that cleans up the resources.
name: pr-preview-teardown
on:
pull_request:
types: [closed]
jobs:
teardown-preview:
runs-on: ubuntu-latest
container:
image: quay.io/appvia-wayfinder/wftoolbox:latest
steps:
- name: Clean up old resources
env:
WAYFINDER_SERVER: ${{ vars.WAYFINDER_SERVER }}
WAYFINDER_WORKSPACE: ${{ vars.WAYFINDER_WORKSPACE }}
WAYFINDER_TOKEN: ${{ secrets.WAYFINDER_TOKEN }}
run: |
export ENV_NAME="pr-${{ github.event.pull_request.number }}"
wf delete appenv ${{ vars.APP_NAME }}-${ENV_NAME} || true
Related Resources
- The main branch of the example repository: wf-example-app