-
Notifications
You must be signed in to change notification settings - Fork 0
72 lines (64 loc) · 2.19 KB
/
cleanup_pull_request.yaml
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
name: 'Cleanup Pull Request'
on:
pull_request:
types: [closed]
jobs:
check-resources:
name: "Check Resources"
runs-on: ubuntu-latest
outputs:
helm_exists: ${{ steps.check_helm.outputs.exists }}
namespace_exists: ${{ steps.check_namespace.outputs.exists }}
steps:
- name: Kubernetes login
uses: azure/k8s-set-context@v4
with:
method: kubeconfig
kubeconfig: ${{ secrets.KUBE_CONFIG }}
- name: Check Helm Chart
id: check_helm
run: |
RELEASE_NAME=project-website-pr-${{ github.event.number }}
if helm list --all --namespace $RELEASE_NAME | grep $RELEASE_NAME; then
echo "::set-output name=exists::true"
else
echo Helm Chart $RELEASE_NAME does not exist
echo "::set-output name=exists::false"
fi
- name: Check Namespace
id: check_namespace
run: |
NAMESPACE=project-website-pr-${{ github.event.number }}
if kubectl get namespace $NAMESPACE; then
echo "::set-output name=exists::true"
else
echo Namespace $NAMESPACE does not exist
echo "::set-output name=exists::false"
fi
cleanup-pr:
name: "Cleanup Pull Request"
runs-on: ubuntu-latest
needs: check-resources
if: needs.check-resources.outputs.helm_exists == 'true' || needs.check-resources.outputs.namespace_exists == 'true'
continue-on-error: true
permissions:
contents: read
packages: write
actions: write
pull-requests: write
steps:
- name: Kubernetes login
uses: azure/k8s-set-context@v4
with:
method: kubeconfig
kubeconfig: ${{ secrets.KUBE_CONFIG }}
- name: Delete Helm Chart
if: needs.check-resources.outputs.helm_exists == 'true'
run: |
RELEASE_NAME=project-website-pr-${{ github.event.number }}
helm delete $RELEASE_NAME --namespace $RELEASE_NAME
- name: Delete Namespace
if: needs.check-resources.outputs.namespace_exists == 'true'
run: |
NAMESPACE=project-website-pr-${{ github.event.number }}
kubectl delete namespace $NAMESPACE