-
Notifications
You must be signed in to change notification settings - Fork 0
63 lines (56 loc) · 1.87 KB
/
cd-test-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
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
name: CD Test Cleanup
on:
# use target so secrets are not exposed
pull_request_target:
types: [ closed ]
branches: [ dependencies ]
env:
NAMESPACE: pr-${{ github.event.pull_request.number }}
jobs:
Undeploy:
runs-on: ubuntu-latest
steps:
- name: Retrieve Source Code
uses: actions/checkout@v4
- name: Install Kubectl
uses: Azure/setup-kubectl@v4
- name: Configure Kubectl
env:
K8S_CONFIG: ${{ secrets.K8S_CONFIG }}
run: |
mkdir -p $HOME/.kube
echo "${K8S_CONFIG}" | base64 --decode > $HOME/.kube/config
shell: bash
- name: Delete Namespace
run: |
kubectl delete namespace $NAMESPACE --ignore-not-found
shell: bash
- name: Set all deployments to inactive
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GH_PAT }}
script: |
const { NAMESPACE } = process.env
// set all deployments to inactive
const deployments = await github.rest.repos.listDeployments({
owner: context.repo.owner,
repo: context.repo.repo,
environment: `test/${NAMESPACE}`,
per_page: 100,
})
for (const deployment of deployments.data) {
await github.rest.repos.createDeploymentStatus({
owner: context.repo.owner,
repo: context.repo.repo,
deployment_id: deployment.id,
state: 'inactive',
environment: `test/${NAMESPACE}`,
})
}
// delete environment
/* currently not supported
await github.rest.repos.deleteEnvironment({
owner: context.repo.owner,
repo: context.repo.repo,
environment_name: `test/${NAMESPACE}`,
}) */