-
Notifications
You must be signed in to change notification settings - Fork 23
38 lines (36 loc) · 1.49 KB
/
branch-preview-cleanup.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
name: Cleanup branch preview
on:
pull_request:
types: [closed]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
ECR_NAME: ${{ secrets.ECR_NAME }}
KUBE_CLUSTER: ${{ secrets.KUBE_CLUSTER }}
KUBE_NAMESPACE: ${{ secrets.KUBE_NAMESPACE }}
jobs:
cleanup-preview:
runs-on: ubuntu-latest
permissions:
id-token: write
contents: read
pull-requests: write
if: contains(github.event.pull_request.labels.*.name, 'preview:active')
steps:
- run: |
echo "${KUBE_CERT}" > ca.crt
kubectl config set-cluster ${KUBE_CLUSTER} --certificate-authority=./ca.crt --server=https://${KUBE_CLUSTER}
kubectl config set-credentials deploy-user --token=${KUBE_TOKEN}
kubectl config set-context ${KUBE_CLUSTER} --cluster=${KUBE_CLUSTER} --user=deploy-user --namespace=${KUBE_NAMESPACE}
kubectl config use-context ${KUBE_CLUSTER}
kubectl delete deployment moj-frontend-${{ github.head_ref }} -n ${KUBE_NAMESPACE}
kubectl delete service moj-frontend-service-${{ github.head_ref }} -n ${KUBE_NAMESPACE}
kubectl delete ingress moj-frontend-ingress-${{ github.head_ref }} -n ${KUBE_NAMESPACE}
env:
KUBE_CERT: ${{ secrets.KUBE_CERT }}
KUBE_TOKEN: ${{ secrets.KUBE_TOKEN }}
KUBE_CLUSTER: ${{ secrets.KUBE_CLUSTER }}
- name: Remove preview:active label
run: |
gh pr edit $PRNUM --remove-label "preview:active"
env:
PRNUM: ${{ github.event.number }}