Skip to content

Fix trigger.dev preview environment archiving reliability #2186

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 26, 2025
Merged
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
54 changes: 52 additions & 2 deletions .github/workflows/trigger_dev_preview.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ on:

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
cancel-in-progress: ${{ github.event.action != 'closed' }}

jobs:
trigger_dev:
Expand Down Expand Up @@ -36,4 +36,54 @@ jobs:
TRIGGER_ACCESS_TOKEN: ${{ secrets.TRIGGER_ACCESS_TOKEN }}
TRIGGER_PROJECT_ID: ${{ vars.TRIGGER_PROJECT_ID }}
run: |
pnpm --filter @liam-hq/jobs exec trigger preview archive --branch ${{ github.head_ref }}
echo "Archiving trigger.dev preview for branch: ${{ github.head_ref }}"

# Archive with retry logic
MAX_RETRIES=3
RETRY_COUNT=0

while [ $RETRY_COUNT -lt $MAX_RETRIES ]; do
echo "Attempt $((RETRY_COUNT + 1)) of $MAX_RETRIES"

if pnpm --filter @liam-hq/jobs exec trigger preview archive --branch "${{ github.head_ref }}"; then
echo "Successfully archived preview environment for branch: ${{ github.head_ref }}"

# Verify archiving by checking if the environment still exists
echo "Verifying archive operation..."
sleep 5

if pnpm --filter @liam-hq/jobs exec trigger preview list --branch "${{ github.head_ref }}" 2>/dev/null | grep -q "${{ github.head_ref }}"; then
echo "Warning: Environment may still be active after archiving"
else
echo "Archive verification successful - environment no longer listed"
fi

exit 0
Comment on lines +55 to +61
Copy link
Preview

Copilot AI Jun 25, 2025

Choose a reason for hiding this comment

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

The verification step logs a warning when the preview environment is still detected but then exits with success. This could lead to false positives where failures are not caught; consider exiting with a non-zero status or adding additional retry logic when the environment is still active.

Suggested change
if pnpm --filter @liam-hq/jobs exec trigger preview list --branch "${{ github.head_ref }}" 2>/dev/null | grep -q "${{ github.head_ref }}"; then
echo "Warning: Environment may still be active after archiving"
else
echo "Archive verification successful - environment no longer listed"
fi
exit 0
MAX_VERIFY_RETRIES=3
VERIFY_RETRY_COUNT=0
while [ $VERIFY_RETRY_COUNT -lt $MAX_VERIFY_RETRIES ]; do
if pnpm --filter @liam-hq/jobs exec trigger preview list --branch "${{ github.head_ref }}" 2>/dev/null | grep -q "${{ github.head_ref }}"; then
echo "Environment still active after archiving. Retrying verification in 10 seconds..."
VERIFY_RETRY_COUNT=$((VERIFY_RETRY_COUNT + 1))
sleep 10
else
echo "Archive verification successful - environment no longer listed"
exit 0
fi
done
echo "Verification failed: Environment still active after maximum retries"
exit 1

Copilot uses AI. Check for mistakes.

else
RETRY_COUNT=$((RETRY_COUNT + 1))
if [ $RETRY_COUNT -lt $MAX_RETRIES ]; then
echo "Archive failed, retrying in 10 seconds..."
sleep 10
else
echo "Archive failed after $MAX_RETRIES attempts"
exit 1
fi
fi
done

- name: Cleanup stale environments
Copy link
Preview

Copilot AI Jun 25, 2025

Choose a reason for hiding this comment

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

[nitpick] The condition combining 'github.event.action == "closed"' with 'always()' in the cleanup step can be confusing. Adding a comment to clarify the intended behavior of running the cleanup step regardless of previous failures while ensuring it only applies when the event is 'closed' would improve maintainability.

Suggested change
- name: Cleanup stale environments
- name: Cleanup stale environments
# This step ensures cleanup of stale environments only when the event action is 'closed'.
# The 'always()' function ensures this step runs regardless of the success or failure of previous steps.

Copilot uses AI. Check for mistakes.

if: github.event.action == 'closed' && always()
shell: bash
env:
TRIGGER_ACCESS_TOKEN: ${{ secrets.TRIGGER_ACCESS_TOKEN }}
TRIGGER_PROJECT_ID: ${{ vars.TRIGGER_PROJECT_ID }}
run: |
echo "Checking for any stale preview environments..."

# List all preview environments and attempt to clean up any that match this branch
echo "Ensuring no preview environments remain for branch: ${{ github.head_ref }}"

# Attempt cleanup even if the previous step failed
pnpm --filter @liam-hq/jobs exec trigger preview archive --branch "${{ github.head_ref }}" 2>/dev/null || true
Comment on lines +86 to +87
Copy link
Member

Choose a reason for hiding this comment

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

Attempt cleanup even if the previous step failed

I understand this runs even if the previous step succeeded ? — which seems fine either way.

Copy link
Member

Choose a reason for hiding this comment

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

Yes, the motivation is to remove it completely.


echo "Cleanup check completed"
Loading