-
Notifications
You must be signed in to change notification settings - Fork 156
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -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: | ||||||||||
|
@@ -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 | ||||||||||
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 | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||||||||||
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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I understand this runs even if the previous step succeeded ? — which seems fine either way. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, the motivation is to remove it completely. |
||||||||||
|
||||||||||
echo "Cleanup check completed" |
There was a problem hiding this comment.
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.
Copilot uses AI. Check for mistakes.