37 lines
1.4 KiB
YAML
37 lines
1.4 KiB
YAML
name: Cleanup Environment
|
|
on: [delete]
|
|
|
|
jobs:
|
|
cleanup:
|
|
runs-on: ubuntu-latest
|
|
if: github.event.ref_type == 'branch'
|
|
|
|
steps:
|
|
- name: Prepare Variables
|
|
run: |
|
|
REPO_LOWER=$(echo "${{ gitea.repository }}" | cut -d'/' -f2 | tr '[:upper:]' '[:lower:]')
|
|
BRANCH_NAME=${{ github.event.ref }}
|
|
BRANCH_LOWER=$(echo "$BRANCH_NAME" | tr '[:upper:]' '[:lower:]' | sed 's/[^a-z0-9-]/-/g')
|
|
TARGET_NS="${REPO_LOWER}-${BRANCH_LOWER}"
|
|
echo "TARGET_NS=$TARGET_NS" >> $GITHUB_ENV
|
|
|
|
- name: Protect Main
|
|
if: env.TARGET_NS == 'escape-teacher-main' || env.TARGET_NS == 'escape-teacher-master'
|
|
run: |
|
|
echo "❌ Main darf nicht gelöscht werden!"
|
|
exit 1
|
|
|
|
- name: Setup Kubectl
|
|
run: |
|
|
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"
|
|
chmod +x kubectl
|
|
mv kubectl /usr/local/bin/
|
|
mkdir -p $HOME/.kube
|
|
echo "${{ secrets.KUBE_CONFIG }}" > $HOME/.kube/config
|
|
chmod 600 $HOME/.kube/config
|
|
sed -i 's|server: https://.*:6443|server: https://kubernetes.default.svc:443|g' $HOME/.kube/config
|
|
|
|
- name: Delete Namespace
|
|
run: |
|
|
echo "🗑️ Lösche Namespace: ${{ env.TARGET_NS }}"
|
|
kubectl delete namespace ${{ env.TARGET_NS }} --ignore-not-found --wait=false |