Skip to content

Commit

Permalink
Merge pull request #58 from SmartCityFlensburg/feature/run-cleanup-ac…
Browse files Browse the repository at this point in the history
…tion-only-when-needed

ci: run cleanup action only when needed
  • Loading branch information
choffmann authored Jun 20, 2024
2 parents 22179ec + 266ef4b commit 7cd8e4c
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 3 deletions.
6 changes: 6 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,9 @@ indent_size = 4

[*.json]
indent_size = 2

[*.yaml]
indent_size = 2

[*.yml]
indent_size = 2
47 changes: 44 additions & 3 deletions .github/workflows/cleanup_pull_request.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,47 @@ on:
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
Expand All @@ -22,10 +60,13 @@ jobs:
kubeconfig: ${{ secrets.KUBE_CONFIG }}

- name: Delete Helm Chart
if: needs.check-resources.outputs.helm_exists == 'true'
run: |
helm delete project-website-pr-${{ github.event.number }} --namespace project-website-pr-${{ github.event.number }}
RELEASE_NAME=project-website-pr-${{ github.event.number }}
helm delete $RELEASE_NAME --namespace $RELEASE_NAME
- name: Delete Namespace
if: always()
if: needs.check-resources.outputs.namespace_exists == 'true'
run: |
kubectl delete namespace project-website-pr-${{ github.event.number }}
NAMESPACE=project-website-pr-${{ github.event.number }}
kubectl delete namespace $NAMESPACE

0 comments on commit 7cd8e4c

Please sign in to comment.