Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions .github/workflows/pr-preview-cleanup-signal.yml
Original file line number Diff line number Diff line change
@@ -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/
47 changes: 34 additions & 13 deletions .github/workflows/pr-preview-cleanup.yml
Original file line number Diff line number Diff line change
@@ -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
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 }}

Comment on lines +20 to +26
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you explain the significance of this artifact?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@johnstcn gh release create/delete/update commands don't work from a PR from a fork as the GITHUB_TOKEN doesn't have enough access.

eg: Check the second step here
https://github.com/coder/agentapi/actions/runs/18270399274/job/52011769517

That's why I had to break this into two parts (similar to the pr release preview).

So now, the signal is created when a PR is closed and then the actual release operations are done on the coder/agentapi repo.

- 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