summary #489
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: CI/CD | |
on: | |
workflow_dispatch: | |
inputs: | |
forceTurboAll: | |
description: 'force turbo:all' | |
type: boolean | |
forceDeploy: | |
description: 'force a deploy' | |
type: boolean | |
push: | |
branches: | |
- main | |
paths-ignore: | |
- '**.md' | |
jobs: | |
check_and_deploy: | |
name: check and deploy | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Cache .turbo | |
uses: actions/cache@v4 | |
with: | |
path: .turbo | |
key: ${{ runner.os }}-turbo-${{ github.sha }} | |
restore-keys: | | |
${{ runner.os }}-turbo- | |
- name: Setup pnpm | |
uses: pnpm/action-setup@v4 | |
- name: Setup Node | |
uses: actions/setup-node@v4 | |
with: | |
cache: pnpm | |
node-version-file: '.nvmrc' | |
- name: envsubst | |
env: | |
cloudflareAccountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} | |
productionPeerSyncPublicKey: ${{ secrets.PEER_SYNC_PUBLIC_KEY }} | |
VITE_PRODUCTION_AG_GRID_LICENSE: ${{ secrets.AG_GRID_LICENSE }} | |
VITE_PRODUCTION_HUB_DOMAIN: pentive.com | |
VITE_PRODUCTION_HUB_ORIGIN: https://pentive.com | |
productionHubOrigin: https://pentive.com | |
VITE_PRODUCTION_CWA_URL: https://cwa.pentive.com/ | |
VITE_PRODUCTION_AUGC_URL: https://api-ugc-production.alexerrant.workers.dev/ | |
VITE_PRODUCTION_APP_ORIGIN: https://app.pentive.com | |
productionAppOrigin: https://app.pentive.com | |
VITE_PRODUCTION_HUB_UGC_ORIGIN: https://hub-ugc.pages.dev | |
VITE_PRODUCTION_APP_UGC_ORIGIN: https://app-ugc.pages.dev | |
VITE_PRODUCTION_PEER_HOST: 0.peerjs.com | |
VITE_PRODUCTION_PEER_PORT: 443 | |
run: | | |
envsubst < ./cwa/example.wrangler.toml > ./cwa/wrangler.toml | |
envsubst < ./api-ugc/example.wrangler.toml > ./api-ugc/wrangler.toml | |
envsubst < ./hub/example.wrangler.toml > ./hub/wrangler.toml | |
envsubst < ./hub/.example.env.production > ./hub/.env.production | |
envsubst < ./app/.example.env.production > ./app/.env.production | |
- name: pnpm install | |
run: pnpm install | |
# https://github.com/microsoft/playwright/issues/7249#issuecomment-1385567519 | |
- name: Store Playwright's Version | |
run: | | |
PLAYWRIGHT_VERSION=$(pnpm ls @playwright/test --filter app-playwright --json | jq '.[0].devDependencies["@playwright/test"].version' --raw-output) | |
echo "Playwright's Version: $PLAYWRIGHT_VERSION" | |
echo "PLAYWRIGHT_VERSION=$PLAYWRIGHT_VERSION" >> $GITHUB_ENV | |
- name: Cache Playwright Browsers for Playwright's Version | |
id: cache-playwright-browsers | |
uses: actions/cache@v4 | |
with: | |
path: ~/.cache/ms-playwright | |
key: playwright-browsers-${{ env.PLAYWRIGHT_VERSION }} | |
- name: Install Playwright Browsers | |
if: steps.cache-playwright-browsers.outputs.cache-hit != 'true' | |
working-directory: ./app-playwright | |
run: npx playwright install --with-deps | |
- name: turbo | |
run: pnpm turbo:all --force $FORCE_TURBO_ALL --summarize | |
env: | |
FORCE_TURBO_ALL: ${{ inputs.forceTurboAll || 'false' }} | |
NODE_OPTIONS: '--max_old_space_size=8192' # https://github.com/actions/runner-images/issues/70 | |
- shell: bash | |
name: 'Summarize Turborepo Output' | |
if: always() | |
run: | | |
latest_json=$(ls -t .turbo/runs/*.json | head -1) | |
if [ -z "$latest_json" ]; then | |
echo "No summary found, make sure you add the \`turbo-summarize\` step after your \`turbo\` step." | |
else | |
# Read the file | |
json_content=$(cat "$latest_json") | |
# Define formatting functions | |
formatted_duration() { | |
local duration_in_milliseconds=$1 | |
local duration_in_seconds=$((duration_in_milliseconds / 1000)) | |
local minutes=$((duration_in_seconds / 60)) | |
local seconds=$((duration_in_seconds % 60)) | |
local milliseconds=$((duration_in_milliseconds % 1000)) | |
echo "${minutes}m ${seconds}.${milliseconds}s" | |
} | |
formatted_timestamp() { | |
local timestamp_in_milliseconds=$1 | |
local timestamp_seconds=$((timestamp_in_milliseconds / 1000)) | |
local milliseconds=$((timestamp_milliseconds % 1000)) | |
local formatted_date=$(date -u -d "@$timestamp_seconds" +"%Y-%m-%d %H:%M:%S.$milliseconds") | |
echo "$formatted_date" | |
} | |
# Extract run details | |
run_command=$(echo "$json_content" | jq -r '.execution.command') | |
run_id=$(echo "$json_content" | jq -r '.id') | |
turbo_version=$(echo "$json_content" | jq -r '.turboVersion') | |
monorepo=$(echo "$json_content" | jq -r '.monorepo') | |
global_cache_enabled=$(echo "$json_content" | jq -r '.globalCacheInputs != null') | |
packages=$(echo "$json_content" | jq -r '.packages | join(", ")') | |
repository_sha=$(echo "$json_content" | jq -r '.scm.sha') | |
repository_branch=$(echo "$json_content" | jq -r '.scm.branch') | |
repository_type=$(echo "$json_content" | jq -r '.scm.type') | |
run_status=$(echo "$json_content" | jq -r '.execution.exitCode | if . == 0 then "Success" else "Failure" end') | |
total_run_duration=$((($(echo "$json_content" | jq -r '.execution.endTime') - $(echo "$json_content" | jq -r '.execution.startTime')))) | |
execution_attempts=$(echo "$json_content" | jq -r '.execution.attempted') | |
cached_count=$(echo "$json_content" | jq -r '.execution.cached') | |
success_count=$(echo "$json_content" | jq -r '.execution.successful') | |
## If full cached, is full turbo | |
is_full_turbo=$(if [ "$cached_count" = "$execution_attempts" ]; then echo "true"; else echo "false"; fi) | |
markdown_content+="# Turbo summary: \`$run_command\` - $(if [ "$run_status" = "Success" ]; then echo ":white_check_mark: Success"; else echo ":x: Failure"; fi)\n" | |
markdown_content+="*Id: $run_id*\n\n" | |
markdown_content+=" - **Tasks:** $cached_count successful / $execution_attempts total\n" | |
markdown_content+=" - **Cached:** $cached_count cached / $execution_attempts total\n" | |
markdown_content+=" - **Time:** $(formatted_duration $total_run_duration)$(if [ "$is_full_turbo" = "true" ]; then echo " **>> FULL TURBO :rocket:**"; fi)\n\n\n" | |
markdown_content+="\n" | |
markdown_content+="| Task ID | Status | Duration | Cache | Time Saved | Started At | Completed At |\n" | |
markdown_content+="|---------|---------|----------------|------------|------------|---------------------|---------------------|\n" | |
# Extract task information and format as Markdown | |
tasks=$(echo "$json_content" | jq -c '.tasks[]') | |
while IFS= read -r task; do | |
task_id=$(echo "$task" | jq -r '.taskId') | |
status=$(echo "$task" | jq -r '.execution.exitCode | if . == 0 then ":white_check_mark: Success" else ":x: Failure" end') | |
start_time=$(echo "$task" | jq -r '.execution.startTime') | |
end_time=$(echo "$task" | jq -r '.execution.endTime') | |
duration=$((end_time - start_time)) | |
cache_status=$(echo "$task" | jq -r '.cache.status') | |
cache_type=$(echo "$task" | jq -r '.cache.remote | if . then "Remote" else "Local" end') | |
time_saved=$(echo "$task" | jq -r '.cache.timeSaved') | |
formatted_duration=$(formatted_duration "$duration") | |
formatted_time_saved=$(formatted_duration "$time_saved") | |
formatted_start_time=$(formatted_timestamp "$start_time") | |
formatted_end_time=$(formatted_timestamp "$end_time") | |
markdown_content+="| $task_id | $status | $formatted_duration | $cache_status ($cache_type) | $formatted_time_saved | $formatted_start_time | $formatted_end_time |\n" | |
done <<< "$tasks" | |
markdown_content+="\n" | |
markdown_content+="<details>\n<summary>\n<b>Run details</b>\n</summary>\n\n" | |
markdown_content+=" - **ID:** $run_id\n" | |
markdown_content+=" - **Packages used:** $packages\n" | |
markdown_content+=" - **Turbo version**: $turbo_version\n" | |
markdown_content+=" - **Monorepo**: $(if [ "$monorepo" = "true" ]; then echo "Yes"; else echo "No"; fi)\n" | |
markdown_content+=" - **Global cache enabled:** $(if [ "$global_cache_enabled" = "true" ]; then echo "Yes"; else echo "No"; fi)\n" | |
markdown_content+=" - **Repository:** SHA: $repository_sha, Branch: $repository_branch, Type: $repository_type\n" | |
markdown_content+="\n" | |
markdown_content+="</details>\n" | |
markdown_content+="\n<details>\n<summary>\n<b>Full Summary JSON Output</b>\n</summary>\n\n" | |
markdown_content+="\`\`\`json\n$json_content\n\`\`\`\n\n" | |
markdown_content+="</details>\n" | |
markdown_content+="\n" | |
fi | |
markdown_content+="---\n" | |
markdown_content+="\n" | |
markdown_content+="[Turbo](https://turbo.build) - The build system that makes ship happen\n" | |
markdown_content+="\n" | |
# Write markdown content to the summary file | |
echo -e "$markdown_content" >> $GITHUB_STEP_SUMMARY | |
echo "$markdown_content" | |
- name: Upload App Playwright report | |
uses: actions/upload-artifact@v4 | |
if: always() | |
with: | |
name: app-playwright-report | |
path: app-playwright/playwright-report/ | |
retention-days: 30 | |
- name: deploy | |
run: pnpm run deploy-only --force $FORCE_DEPLOY | |
env: | |
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }} | |
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} | |
FORCE_DEPLOY: ${{ inputs.forceDeploy || 'false' }} |