Skip to content

Commit 338f3b4

Browse files
teodorciuraruclaude
andcommitted
refactor: extract Ditto test document insertion into composite action
- Create ditto-test-document-insert composite action to eliminate duplication - Refactor all 3 BrowserStack workflows to use the new action - Reduce ~30 lines of duplicated code across BrowserStack workflows - Enable reuse for future Flutter/React Native Ditto integration tests - Maintain identical functionality with project-type parameterization 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
1 parent 8c2d380 commit 338f3b4

File tree

4 files changed

+68
-105
lines changed

4 files changed

+68
-105
lines changed
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
name: 'Ditto Test Document Insert'
2+
description: 'Insert a GitHub test document into Ditto Cloud for integration testing'
3+
inputs:
4+
project-type:
5+
description: 'Project type identifier (e.g., "android-java", "android-kotlin", "flutter")'
6+
required: true
7+
ditto-api-key:
8+
description: 'Ditto API key for document insertion'
9+
required: true
10+
ditto-api-url:
11+
description: 'Ditto API URL'
12+
required: true
13+
14+
runs:
15+
using: 'composite'
16+
steps:
17+
- name: Insert test document into Ditto Cloud
18+
shell: bash
19+
run: |
20+
# Use GitHub run ID to create deterministic document ID
21+
DOC_ID="github_${{ inputs.project-type }}_${GITHUB_RUN_ID}_${GITHUB_RUN_NUMBER}"
22+
TIMESTAMP=$(date -u +"%Y-%m-%d %H:%M:%S UTC")
23+
24+
# Insert document using curl with correct JSON structure
25+
RESPONSE=$(curl -s -w "\n%{http_code}" -X POST \
26+
-H 'Content-type: application/json' \
27+
-H "Authorization: Bearer ${{ inputs.ditto-api-key }}" \
28+
-d "{
29+
\"statement\": \"INSERT INTO tasks DOCUMENTS (:newTask) ON ID CONFLICT DO UPDATE\",
30+
\"args\": {
31+
\"newTask\": {
32+
\"_id\": \"${DOC_ID}\",
33+
\"title\": \"GitHub Test Task ${{ inputs.project-type }} ${GITHUB_RUN_ID}\",
34+
\"done\": false,
35+
\"deleted\": false
36+
}
37+
}
38+
}" \
39+
"https://${{ inputs.ditto-api-url }}/api/v4/store/execute")
40+
41+
# Extract HTTP status code and response body
42+
HTTP_CODE=$(echo "$RESPONSE" | tail -n1)
43+
BODY=$(echo "$RESPONSE" | head -n-1)
44+
45+
# Check if insertion was successful
46+
if [ "$HTTP_CODE" -eq 200 ] || [ "$HTTP_CODE" -eq 201 ]; then
47+
echo "✓ Successfully inserted test document with ID: ${DOC_ID}"
48+
echo "GITHUB_TEST_DOC_ID=${DOC_ID}" >> $GITHUB_ENV
49+
else
50+
echo "❌ Failed to insert document. HTTP Status: $HTTP_CODE"
51+
echo "Response: $BODY"
52+
exit 1
53+
fi

.github/workflows/android-cpp-browserstack.yml

Lines changed: 5 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -44,41 +44,11 @@ jobs:
4444
ditto-websocket-url: ${{ secrets.DITTO_WEBSOCKET_URL }}
4545

4646
- name: Insert test document into Ditto Cloud
47-
run: |
48-
# Use GitHub run ID to create deterministic document ID
49-
DOC_ID="github_android_cpp_${GITHUB_RUN_ID}_${GITHUB_RUN_NUMBER}"
50-
TIMESTAMP=$(date -u +"%Y-%m-%d %H:%M:%S UTC")
51-
52-
# Insert document using curl with correct JSON structure for Android CPP app
53-
RESPONSE=$(curl -s -w "\n%{http_code}" -X POST \
54-
-H 'Content-type: application/json' \
55-
-H "Authorization: Bearer ${{ secrets.DITTO_API_KEY }}" \
56-
-d "{
57-
\"statement\": \"INSERT INTO tasks DOCUMENTS (:newTask) ON ID CONFLICT DO UPDATE\",
58-
\"args\": {
59-
\"newTask\": {
60-
\"_id\": \"${DOC_ID}\",
61-
\"title\": \"GitHub Test Task CPP ${GITHUB_RUN_ID}\",
62-
\"done\": false,
63-
\"deleted\": false
64-
}
65-
}
66-
}" \
67-
"https://${{ secrets.DITTO_API_URL }}/api/v4/store/execute")
68-
69-
# Extract HTTP status code and response body
70-
HTTP_CODE=$(echo "$RESPONSE" | tail -n1)
71-
BODY=$(echo "$RESPONSE" | head -n-1)
72-
73-
# Check if insertion was successful
74-
if [ "$HTTP_CODE" -eq 200 ] || [ "$HTTP_CODE" -eq 201 ]; then
75-
echo "✓ Successfully inserted test document with ID: ${DOC_ID}"
76-
echo "GITHUB_TEST_DOC_ID=${DOC_ID}" >> $GITHUB_ENV
77-
else
78-
echo "❌ Failed to insert document. HTTP Status: $HTTP_CODE"
79-
echo "Response: $BODY"
80-
exit 1
81-
fi
47+
uses: ./.github/actions/ditto-test-document-insert
48+
with:
49+
project-type: android-cpp
50+
ditto-api-key: ${{ secrets.DITTO_API_KEY }}
51+
ditto-api-url: ${{ secrets.DITTO_API_URL }}
8252

8353
- name: Cache Gradle
8454
uses: ./.github/actions/gradle-cache

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

Lines changed: 5 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -40,41 +40,11 @@ jobs:
4040
ditto-websocket-url: ${{ secrets.DITTO_WEBSOCKET_URL }}
4141

4242
- name: Insert test document into Ditto Cloud
43-
run: |
44-
# Use GitHub run ID to create deterministic document ID
45-
DOC_ID="github_android_java_${GITHUB_RUN_ID}_${GITHUB_RUN_NUMBER}"
46-
TIMESTAMP=$(date -u +"%Y-%m-%d %H:%M:%S UTC")
47-
48-
# Insert document using curl with correct JSON structure for Android Java app
49-
RESPONSE=$(curl -s -w "\n%{http_code}" -X POST \
50-
-H 'Content-type: application/json' \
51-
-H "Authorization: Bearer ${{ secrets.DITTO_API_KEY }}" \
52-
-d "{
53-
\"statement\": \"INSERT INTO tasks DOCUMENTS (:newTask) ON ID CONFLICT DO UPDATE\",
54-
\"args\": {
55-
\"newTask\": {
56-
\"_id\": \"${DOC_ID}\",
57-
\"title\": \"GitHub Test Task Java ${GITHUB_RUN_ID}\",
58-
\"done\": false,
59-
\"deleted\": false
60-
}
61-
}
62-
}" \
63-
"https://${{ secrets.DITTO_API_URL }}/api/v4/store/execute")
64-
65-
# Extract HTTP status code and response body
66-
HTTP_CODE=$(echo "$RESPONSE" | tail -n1)
67-
BODY=$(echo "$RESPONSE" | head -n-1)
68-
69-
# Check if insertion was successful
70-
if [ "$HTTP_CODE" -eq 200 ] || [ "$HTTP_CODE" -eq 201 ]; then
71-
echo "✓ Successfully inserted test document with ID: ${DOC_ID}"
72-
echo "GITHUB_TEST_DOC_ID=${DOC_ID}" >> $GITHUB_ENV
73-
else
74-
echo "❌ Failed to insert document. HTTP Status: $HTTP_CODE"
75-
echo "Response: $BODY"
76-
exit 1
77-
fi
43+
uses: ./.github/actions/ditto-test-document-insert
44+
with:
45+
project-type: android-java
46+
ditto-api-key: ${{ secrets.DITTO_API_KEY }}
47+
ditto-api-url: ${{ secrets.DITTO_API_URL }}
7848

7949
- name: Cache Gradle
8050
uses: ./.github/actions/gradle-cache

.github/workflows/android-kotlin-browserstack.yml

Lines changed: 5 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -40,41 +40,11 @@ jobs:
4040
ditto-websocket-url: ${{ secrets.DITTO_WEBSOCKET_URL }}
4141

4242
- name: Insert test document into Ditto Cloud
43-
run: |
44-
# Use GitHub run ID to create deterministic document ID
45-
DOC_ID="github_android_kotlin_${GITHUB_RUN_ID}_${GITHUB_RUN_NUMBER}"
46-
TIMESTAMP=$(date -u +"%Y-%m-%d %H:%M:%S UTC")
47-
48-
# Insert document using curl with correct JSON structure for Android Kotlin app
49-
RESPONSE=$(curl -s -w "\n%{http_code}" -X POST \
50-
-H 'Content-type: application/json' \
51-
-H "Authorization: Bearer ${{ secrets.DITTO_API_KEY }}" \
52-
-d "{
53-
\"statement\": \"INSERT INTO tasks DOCUMENTS (:newTask) ON ID CONFLICT DO UPDATE\",
54-
\"args\": {
55-
\"newTask\": {
56-
\"_id\": \"${DOC_ID}\",
57-
\"title\": \"GitHub Test Task Kotlin ${GITHUB_RUN_ID}\",
58-
\"done\": false,
59-
\"deleted\": false
60-
}
61-
}
62-
}" \
63-
"https://${{ secrets.DITTO_API_URL }}/api/v4/store/execute")
64-
65-
# Extract HTTP status code and response body
66-
HTTP_CODE=$(echo "$RESPONSE" | tail -n1)
67-
BODY=$(echo "$RESPONSE" | head -n-1)
68-
69-
# Check if insertion was successful
70-
if [ "$HTTP_CODE" -eq 200 ] || [ "$HTTP_CODE" -eq 201 ]; then
71-
echo "✓ Successfully inserted test document with ID: ${DOC_ID}"
72-
echo "GITHUB_TEST_DOC_ID=${DOC_ID}" >> $GITHUB_ENV
73-
else
74-
echo "❌ Failed to insert document. HTTP Status: $HTTP_CODE"
75-
echo "Response: $BODY"
76-
exit 1
77-
fi
43+
uses: ./.github/actions/ditto-test-document-insert
44+
with:
45+
project-type: android-kotlin
46+
ditto-api-key: ${{ secrets.DITTO_API_KEY }}
47+
ditto-api-url: ${{ secrets.DITTO_API_URL }}
7848

7949
- name: Cache Gradle
8050
uses: ./.github/actions/gradle-cache

0 commit comments

Comments
 (0)