Skip to content

Destroying review app for PR "Feat/remove old infrastructure" #395

Destroying review app for PR "Feat/remove old infrastructure"

Destroying review app for PR "Feat/remove old infrastructure" #395

name: review-app-destroy
run-name: Destroying review app for PR "${{ github.event.pull_request.title }}"
on:
pull_request:
types: ["unlabeled", "closed", "converted_to_draft"]
workflow_dispatch:
workflow_call:
inputs:
pr_number:
required: true
type: string
env:
PR_NUMBER: ${{ inputs.pr_number || github.event.pull_request.number }}
CLUSTER: dev-eks-platform
jobs:
destroy:
name: Destroy Review Environment
runs-on: ubuntu-22.04
permissions:
id-token: write
contents: read
issues: write
pull-requests: write
if: github.event.label.name == 'Review app' || inputs.pr_number
steps:
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: "arn:aws:iam::979633842206:role/EnergyAppsDeployment"
role-session-name: energy-app-actions-workflow
aws-region: eu-west-1
- name: Get Kube Config
run: aws eks update-kubeconfig --name=${{ env.CLUSTER }}
- name: Set Environment Variables
run: echo "NAMESPACE=review-${{ env.PR_NUMBER }}-energy-apps" >> $GITHUB_ENV
- name: Destroy Review App
run: |
if [[ $(helm status -n ${{ env.NAMESPACE }} ${{ env.NAMESPACE }}) ]] ; then
kubectl delete subnamespaceanchor ${{ env.NAMESPACE }} -n dev-energy-apps
fi
- name: Remove Review app label
if: contains(github.event.pull_request.labels.*.name, 'Review app') || inputs.pr_number
uses: actions-ecosystem/[email protected]
with:
labels: "Review app"
number: ${{ github.event.issue.number || github.event.pull_request.number || inputs.pr_number }}
- name: Find Comment
uses: peter-evans/find-comment@v3
id: find-comment
with:
issue-number: ${{ env.PR_NUMBER }}
comment-author: "github-actions[bot]"
body-includes: A review app has been created in the Kubernetes namespace
direction: last
- name: Update Comment
uses: peter-evans/create-or-update-comment@v4
if: steps.find-comment.outputs.comment-id
with:
issue-number: ${{ env.PR_NUMBER }}
edit-mode: replace
comment-id: ${{ steps.find-comment.outputs.comment-id }}
body: |
A review app has been created in the Kubernetes namespace `${{ env.NAMESPACE }}` in the `${{ env.CLUSTER }}` cluster.
---
Edit: The review environment and namespace has been destroyed and the label `Review app` has been removed from the PR. Re-apply the `Review app` label to recreate it.