Skip to content

Commit fca01b0

Browse files
Teodor Ciuraruclaude
andcommitted
feat(android-java): improve CI document seeding with inverted timestamps
- Replace simple '000_' prefix with proper inverted timestamp calculation - Use inverted timestamp (9999999999 - current_timestamp) for reliable top positioning - Remove unnecessary cleanup step (simpler and more reliable) - Newer CI documents will always appear at top due to smaller inverted timestamp values - Ensures consistent document positioning regardless of execution time 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 19a0ec9 commit fca01b0

1 file changed

Lines changed: 7 additions & 20 deletions

File tree

.github/workflows/android-java-ci.yml

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -63,28 +63,14 @@ jobs:
6363
- name: Insert test document into Ditto Cloud
6464
run: |
6565
DOC_ID="ci_test_${GITHUB_RUN_ID}_${GITHUB_RUN_NUMBER}"
66-
SEED_TITLE="000_ci_test_${GITHUB_RUN_ID}_${GITHUB_RUN_NUMBER}"
6766
68-
# First, clean up any existing CI test documents to keep only the latest one
69-
echo "🧹 Cleaning up old CI test documents..."
70-
CLEANUP_RESPONSE=$(curl -s -w "\n%{http_code}" -X POST \
71-
-H 'Content-type: application/json' \
72-
-H "Authorization: Bearer ${{ secrets.DITTO_API_KEY }}" \
73-
-d "{
74-
\"statement\": \"UPDATE tasks SET deleted = true WHERE title LIKE '000_ci_test%'\",
75-
\"args\": {}
76-
}" \
77-
"https://${{ secrets.DITTO_API_URL }}/api/v4/store/execute")
78-
79-
CLEANUP_HTTP_CODE=$(echo "$CLEANUP_RESPONSE" | tail -n1)
80-
if [ "$CLEANUP_HTTP_CODE" -eq 200 ] || [ "$CLEANUP_HTTP_CODE" -eq 201 ]; then
81-
echo "✓ Old CI test documents cleaned up"
82-
else
83-
echo "⚠️ Cleanup failed (HTTP ${CLEANUP_HTTP_CODE}) - continuing anyway"
84-
fi
67+
# Create inverted timestamp for alphabetical sorting (newest first)
68+
# Use a large number (9999999999) minus current timestamp so newer = smaller = sorts first
69+
CURRENT_TIMESTAMP=$(date +%s)
70+
INVERTED_TIMESTAMP=$((9999999999 - CURRENT_TIMESTAMP))
71+
SEED_TITLE="${INVERTED_TIMESTAMP}_ci_test_${GITHUB_RUN_ID}_${GITHUB_RUN_NUMBER}"
8572
86-
# Insert new test document using Ditto API
87-
echo "📄 Inserting new CI test document..."
73+
# Insert test document using Ditto API
8874
RESPONSE=$(curl -s -w "\n%{http_code}" -X POST \
8975
-H 'Content-type: application/json' \
9076
-H "Authorization: Bearer ${{ secrets.DITTO_API_KEY }}" \
@@ -107,6 +93,7 @@ jobs:
10793
if [ "$HTTP_CODE" -eq 200 ] || [ "$HTTP_CODE" -eq 201 ]; then
10894
echo "✓ Test document inserted successfully: ${DOC_ID}"
10995
echo "✓ Seed title: ${SEED_TITLE}"
96+
echo "✓ Inverted timestamp: ${INVERTED_TIMESTAMP} (newer documents sort first)"
11097
echo "GITHUB_TEST_DOC_ID=${SEED_TITLE}" >> $GITHUB_ENV
11198
else
11299
echo "❌ Failed to insert test document (HTTP ${HTTP_CODE})"

0 commit comments

Comments
 (0)