From c239d951316fce3b482eb3ebf93db767b6f1bdc2 Mon Sep 17 00:00:00 2001 From: Anthony Stirling <77850077+Frooodle@users.noreply.github.com> Date: Wed, 20 Nov 2024 08:41:29 +0000 Subject: [PATCH] Update PR-Demo-cleanup.yml --- .github/workflows/PR-Demo-cleanup.yml | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/.github/workflows/PR-Demo-cleanup.yml b/.github/workflows/PR-Demo-cleanup.yml index b18b88b5..94f8bd3f 100644 --- a/.github/workflows/PR-Demo-cleanup.yml +++ b/.github/workflows/PR-Demo-cleanup.yml @@ -10,6 +10,7 @@ permissions: env: SERVER_IP: ${{ secrets.VPS_IP }} # Add this to your GitHub secrets + CLEANUP_PERFORMED: 'false' # Add flag to track if cleanup occurred jobs: cleanup: @@ -24,9 +25,9 @@ jobs: sudo chmod 600 ../private.key - name: Cleanup PR deployment + id: cleanup run: | - ssh -i ../private.key -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -T ${{ secrets.VPS_USERNAME }}@${{ secrets.VPS_HOST }} << 'ENDSSH' - # Check if directory exists before attempting cleanup + CLEANUP_STATUS=$(ssh -i ../private.key -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -T ${{ secrets.VPS_USERNAME }}@${{ secrets.VPS_HOST }} << 'ENDSSH' if [ -d "/stirling/PR-${{ github.event.pull_request.number }}" ]; then echo "Found PR directory, proceeding with cleanup..." @@ -43,13 +44,22 @@ jobs: # Remove the Docker image docker rmi --no-prune ${{ secrets.DOCKER_HUB_USERNAME }}/test:pr-${{ github.event.pull_request.number }} || true - echo "Cleanup completed successfully" + echo "PERFORMED_CLEANUP" else echo "PR directory not found, nothing to clean up" + echo "NO_CLEANUP_NEEDED" fi ENDSSH + ) + + if [[ $CLEANUP_STATUS == *"PERFORMED_CLEANUP"* ]]; then + echo "cleanup_performed=true" >> $GITHUB_OUTPUT + else + echo "cleanup_performed=false" >> $GITHUB_OUTPUT + fi - name: Post cleanup notice to PR + if: steps.cleanup.outputs.cleanup_performed == 'true' uses: actions/github-script@v7 with: script: |