Skip to content

Bump to 4.15.0

Bump to 4.15.0 #188

name: JavaScript Web CI
on:
pull_request:
paths:
- "javascript-web/**"
- ".github/workflows/javascript-web-ci.yml"
workflow_dispatch:
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
lint:
name: Lint
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: "22"
cache: "npm"
cache-dependency-path: javascript-web/package-lock.json
- name: Install dependencies
working-directory: javascript-web
run: npm ci
- name: Run linter
working-directory: javascript-web
run: npm run lint
build:
name: Build
runs-on: ubuntu-latest
needs: lint
timeout-minutes: 10
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: "22"
cache: "npm"
cache-dependency-path: javascript-web/package-lock.json
- name: Create .env file
run: |
echo "DITTO_APP_ID=${{ secrets.DITTO_APP_ID }}" > .env
echo "DITTO_PLAYGROUND_TOKEN=${{ secrets.DITTO_PLAYGROUND_TOKEN }}" >> .env
echo "DITTO_AUTH_URL=${{ secrets.DITTO_AUTH_URL }}" >> .env
echo "DITTO_WEBSOCKET_URL=${{ secrets.DITTO_WEBSOCKET_URL }}" >> .env
- name: Install dependencies
working-directory: javascript-web
run: npm ci
- name: Build application
working-directory: javascript-web
run: npm run build
- name: Upload build artifact
uses: actions/upload-artifact@v4
with:
name: javascript-web-dist
path: javascript-web/dist/
retention-days: 1
browserstack-web:
name: BrowserStack Tests
runs-on: ubuntu-latest
needs: build
timeout-minutes: 150
outputs:
build_id: ${{ steps.test.outputs.build_id }}
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: "22"
- name: Download build artifact
uses: actions/download-artifact@v4
with:
name: javascript-web-dist
path: javascript-web/dist
- name: Install http-server
run: npm install -g http-server
- name: Start web server
working-directory: javascript-web
run: |
nohup http-server dist -p 3000 -c-1 --cors > server.log 2>&1 &
sleep 5
curl -f http://localhost:3000/ || (echo "Server failed to start" && cat server.log && exit 1)
echo "Web server started on http://localhost:3000"
- name: Install BrowserStack Local binary
run: |
wget "https://www.browserstack.com/browserstack-local/BrowserStackLocal-linux-x64.zip"
unzip BrowserStackLocal-linux-x64.zip
chmod +x BrowserStackLocal
# Create config file with restricted permissions
echo "key: ${{ secrets.BROWSERSTACK_ACCESS_KEY }}" > browserstack.yml
chmod 600 browserstack.yml
nohup ./BrowserStackLocal --config-file ./browserstack.yml --daemon start &
sleep 20
echo "BrowserStack Local tunnel established"
- name: Generate BrowserStack names
id: build-info
uses: ./.github/actions/generate-browserstack-names
- name: Make test script executable
run: chmod +x .github/scripts/browserstack-test.py
- name: Seed and execute tests on BrowserStack
id: test
uses: nick-fields/retry@v3
env:
BROWSERSTACK_USERNAME: ${{ secrets.BROWSERSTACK_USERNAME }}
BROWSERSTACK_ACCESS_KEY: ${{ secrets.BROWSERSTACK_ACCESS_KEY }}
BROWSERSTACK_PROJECT: ${{ steps.build-info.outputs.project-name }}
BROWSERSTACK_BUILD_NAME: ${{ steps.build-info.outputs.build-name }}
GITHUB_RUN_NUMBER: ${{ github.run_number }}
GITHUB_RUN_ID: ${{ github.run_id }}
with:
max_attempts: 5
timeout_minutes: 20
retry_wait_seconds: 900
command: |
# Seed test task to Ditto Cloud
echo "Seeding test task to Ditto Cloud..."
TIMESTAMP=$(date +%s)
INVERTED_TIMESTAMP=$((9999999999 - TIMESTAMP))
SEED_RESPONSE=$(curl -s -w "\n%{http_code}" -X POST \
-H 'Content-type: application/json' \
-H "Authorization: Bearer ${{ secrets.DITTO_API_KEY }}" \
-d "{
\"statement\": \"INSERT INTO tasks DOCUMENTS (:newTask) ON ID CONFLICT DO UPDATE\",
\"args\": {
\"newTask\": {
\"_id\": \"${INVERTED_TIMESTAMP}_javascript-web_ci_test_${{ github.run_id }}_${{ github.run_number }}\",
\"title\": \"${INVERTED_TIMESTAMP}_javascript-web_ci_test_${{ github.run_id }}_${{ github.run_number }}\",
\"done\": false,
\"deleted\": false
}
}
}" \
"https://${{ secrets.DITTO_API_URL }}/api/v4/store/execute")
HTTP_CODE=$(echo "$SEED_RESPONSE" | tail -n1)
BODY=$(echo "$SEED_RESPONSE" | sed '$d')
if [ "$HTTP_CODE" -eq 200 ] || [ "$HTTP_CODE" -eq 201 ]; then
TASK_TITLE="${INVERTED_TIMESTAMP}_javascript-web_ci_test_${{ github.run_id }}_${{ github.run_number }}"
echo "Seeded task: $TASK_TITLE"
else
echo "Error: Failed to seed task. HTTP Status: $HTTP_CODE"
echo "Response: $BODY"
exit 1
fi
# Set environment variable for Python script
export DITTO_CLOUD_TASK_TITLE="$TASK_TITLE"
# Install Python dependencies
pip3 install selenium pyyaml
# Run the test script
python3 .github/scripts/browserstack-test.py
# Query BrowserStack API to get the build ID
echo "Fetching build ID from BrowserStack..."
BUILDS_RESPONSE=$(curl -s -u "${{ secrets.BROWSERSTACK_USERNAME }}:${{ secrets.BROWSERSTACK_ACCESS_KEY }}" \
"https://api.browserstack.com/automate/builds.json?limit=1")
BUILD_ID=$(echo "$BUILDS_RESPONSE" | yq eval '.[0].hashed_id' -)
if [ "$BUILD_ID" != "null" ] && [ -n "$BUILD_ID" ]; then
echo "build_id=$BUILD_ID" >> $GITHUB_OUTPUT
echo "✅ Build ID: $BUILD_ID"
else
echo "⚠️ Could not retrieve build ID from BrowserStack API"
fi
- name: Stop BrowserStack Local tunnel
if: always()
run: ./BrowserStackLocal --key "${{ secrets.BROWSERSTACK_ACCESS_KEY }}" --daemon stop || true
- name: Upload test artifacts
if: always()
uses: actions/upload-artifact@v4
with:
name: test-results
path: |
javascript-web/dist/
javascript-web/server.log
*screenshot*.png
summary:
name: CI Report
runs-on: ubuntu-latest
needs: [lint, build, browserstack-web]
if: always()
steps:
- name: Report Results
run: |
echo "## 🌐 JavaScript Web CI" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
# Overall status
if [[ "${{ needs.lint.result }}" == "success" && \
"${{ needs.build.result }}" == "success" && \
"${{ needs.browserstack-web.result }}" == "success" ]]; then
echo "**Overall Status:** ✅ All checks passed" >> $GITHUB_STEP_SUMMARY
else
echo "**Overall Status:** ❌ Failed" >> $GITHUB_STEP_SUMMARY
fi
echo "" >> $GITHUB_STEP_SUMMARY
echo "| Job | Status |" >> $GITHUB_STEP_SUMMARY
echo "|-----|--------|" >> $GITHUB_STEP_SUMMARY
echo "| Lint | ${{ needs.lint.result == 'success' && '✅ Passed' || '❌ Failed' }} |" >> $GITHUB_STEP_SUMMARY
echo "| Build | ${{ needs.build.result == 'success' && '✅ Passed' || '❌ Failed' }} |" >> $GITHUB_STEP_SUMMARY
echo "| BrowserStack Tests | ${{ needs.browserstack-web.result == 'success' && '✅ Passed' || '❌ Failed' }} |" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
# BrowserStack info
if [ -n "${{ needs.browserstack-web.outputs.build_id }}" ]; then
echo "### BrowserStack Session" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "🔗 [View Test Results](https://automate.browserstack.com/dashboard/v2/builds/${{ needs.browserstack-web.outputs.build_id }}/)" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "**Tested Browsers:**" >> $GITHUB_STEP_SUMMARY
echo "- Chrome 120.0 (Windows 11)" >> $GITHUB_STEP_SUMMARY
echo "- Firefox 121.0 (Windows 11)" >> $GITHUB_STEP_SUMMARY
fi