From 4b56629cc14fd53c6b359c2821ae487d0f19b32a Mon Sep 17 00:00:00 2001 From: 35C4n0r Date: Wed, 1 Oct 2025 22:45:53 +0530 Subject: [PATCH] feat: fix delete preview --- .../workflows/pr-preview-cleanup-signal.yml | 25 ++++++++++ .github/workflows/pr-preview-cleanup.yml | 47 ++++++++++++++----- 2 files changed, 59 insertions(+), 13 deletions(-) create mode 100644 .github/workflows/pr-preview-cleanup-signal.yml diff --git a/.github/workflows/pr-preview-cleanup-signal.yml b/.github/workflows/pr-preview-cleanup-signal.yml new file mode 100644 index 0000000..4650411 --- /dev/null +++ b/.github/workflows/pr-preview-cleanup-signal.yml @@ -0,0 +1,25 @@ +name: PR Preview Cleanup Signal + +on: + pull_request: + types: [closed] + + +jobs: + cleanup-signal: + name: Signal Cleanup + runs-on: ubuntu-latest + permissions: + contents: write + + steps: + - name: Save PR number for cleanup + run: | + mkdir -p ./cleanup + echo ${{ github.event.pull_request.number }} > ./cleanup/number + + - name: Upload cleanup signal + uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 + with: + name: cleanup-signal + path: cleanup/ \ No newline at end of file diff --git a/.github/workflows/pr-preview-cleanup.yml b/.github/workflows/pr-preview-cleanup.yml index ba7ced5..889752f 100644 --- a/.github/workflows/pr-preview-cleanup.yml +++ b/.github/workflows/pr-preview-cleanup.yml @@ -1,21 +1,42 @@ name: PR Preview Cleanup on: - pull_request: - types: [closed] + workflow_run: + workflows: ["PR Preview Cleanup Signal"] + types: + - completed permissions: - contents: write + contents: write + pull-requests: write jobs: - cleanup: - name: Delete PR Release - runs-on: ubuntu-latest + cleanup: + name: Delete PR Release + runs-on: ubuntu-latest + if: ${{ github.event.workflow_run.conclusion == 'success' }} - steps: - - name: Delete PR Release - env: - GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} - RELEASE_TAG: 'agentapi_${{ github.event.pull_request.number }}' - run: | - gh release delete "$RELEASE_TAG" --cleanup-tag --yes --repo ${{ github.repository }} || true \ No newline at end of file + steps: + - name: Download cleanup signal + uses: actions/download-artifact@v4 + with: + name: cleanup-signal + github-token: ${{ secrets.GITHUB_TOKEN }} + run-id: ${{ github.event.workflow_run.id }} + + - name: Read PR number + id: pr + run: echo "number=$(cat number)" >> "${GITHUB_OUTPUT}" + + - name: Delete PR Release + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + RELEASE_TAG: "agentapi_${{ steps.pr.outputs.number }}" + run: | + # Check if release exists and delete it + if gh release view "$RELEASE_TAG" --repo ${{ github.repository }} &>/dev/null; then + echo "Deleting release $RELEASE_TAG" + gh release delete "$RELEASE_TAG" --cleanup-tag --yes --repo ${{ github.repository }} + else + echo "Release $RELEASE_TAG does not exist, nothing to delete" + fi \ No newline at end of file