Aam-Digital/ndb-core

View on GitHub
.github/workflows/pull-request-closed.yml

Summary

Maintainability
Test Coverage
name: Pull Request - Clean Up

on:
  pull_request_target:
    types: [closed]

env:
  GH_TOKEN: ${{ github.token }}

jobs:
  remove-deployment:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout repository files
        uses: actions/checkout@v4

      - name: Stop container and remove folder
        uses: appleboy/ssh-action@master
        continue-on-error: true
        with:
          host: ${{ secrets.SSH_HOST }}
          username: ${{ secrets.SSH_USERNAME }}
          key: ${{ secrets.SSH_KEY }}
          script: |
            cd /var/docker/pr-${{ github.event.number }}
            docker compose down
            cd ..
            rm -r pr-${{ github.event.number }}

      - name: Delete Docker tag
        continue-on-error: true
        run: |
          token=$(curl -s -L 'https://hub.docker.com/v2/users/login' -H 'Content-Type: application/json' -d '{ "username": "${{ secrets.DOCKER_USERNAME }}", "password": "${{ secrets.DOCKER_PASSWORD }}"}')
          token=${token#*\"token\":\"}
          token=${token%%\"*}
          curl -s -L -X DELETE "https://hub.docker.com/v2/namespaces/aamdigital/repositories/ndb-server/tags/pr-${{ github.event.number }}" -H "Authorization: Bearer $token"

      - name: Delete github caches for current branch
        run: |
          gh cache list -L 200 --ref "refs/pull/${{ github.event.number }}/merge" --json id --jq '.[] | .id' | while read -r id; do
            gh cache delete "$id"
          done