diff --git a/.gitignore b/.gitignore index 80a53c6..88be451 100644 --- a/.gitignore +++ b/.gitignore @@ -20,3 +20,5 @@ devenv.local.nix node_modules/ appcast/dist/ +appcast/logs/ +appcast/report/ diff --git a/BuildScripts/appcast-report.sh b/BuildScripts/appcast-report.sh new file mode 100755 index 0000000..4c24663 --- /dev/null +++ b/BuildScripts/appcast-report.sh @@ -0,0 +1,29 @@ +#!/bin/sh + +set -eu + +project_dir=$(CDPATH= cd -- "$(dirname -- "$0")/.." && pwd) +logs_dir="$project_dir/appcast/logs" +report_dir="$project_dir/appcast/report" +account_id=$(aws sts get-caller-identity --query Account --output text) +log_source="s3://tmpdisk-appcast-logs-prod/AWSLogs/$account_id/CloudFront/tmpdisk/" + +mkdir -p "$logs_dir" "$report_dir" +aws s3 sync "$log_source" "$logs_dir" --exclude "*" --include "*.gz" + +log_paths=$(find "$logs_dir" -type f -name "*.gz" -print) +if [ -z "$log_paths" ]; then + echo "no appcast logs found at $log_source" >&2 + exit 1 +fi + +# CloudFront-generated object names contain no whitespace, so splitting the +# newline-delimited find output produces one argument per log file. +# shellcheck disable=SC2086 +"$project_dir/node_modules/.bin/twinkle" report \ + "$project_dir/appcast/current.json" \ + $log_paths \ + --html "$report_dir/index.html" \ + > "$report_dir/report.json" + +cat "$report_dir/report.json" diff --git a/appcast/README.md b/appcast/README.md index d144615..d6d4442 100644 --- a/appcast/README.md +++ b/appcast/README.md @@ -24,3 +24,13 @@ AWS_PROFILE=cg-prod npm run appcast:publish ``` Publishing validates both manifests before any upload. Published objects are versioned in S3; CloudFront caches them for five minutes. + +## Offline metrics + +Download the retained CloudFront logs and generate local JSON and HTML reports: + +```sh +AWS_PROFILE=cg-prod npm run appcast:report +``` + +Outputs are written to the gitignored `appcast/report/` directory. Raw logs remain local in `appcast/logs/`. The report counts update checks and estimates version adoption; it does not measure installations or completed downloads. diff --git a/package-lock.json b/package-lock.json index 05a7f77..976cf3f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -6,13 +6,13 @@ "": { "name": "tmpdisk-release-tools", "devDependencies": { - "twinkle-appcast": "https://github.com/cosmicglue-io/twinkle/archive/8fdf6eb74ca51ba9d5d587d3c94e1032b68c79eb.tar.gz" + "twinkle-appcast": "https://github.com/cosmicglue-io/twinkle/archive/e45e3be7f9bf684ee123c9b790e9850feef14ae0.tar.gz" } }, "node_modules/twinkle-appcast": { "version": "0.1.0", - "resolved": "https://github.com/cosmicglue-io/twinkle/archive/8fdf6eb74ca51ba9d5d587d3c94e1032b68c79eb.tar.gz", - "integrity": "sha512-TL+w+dbtJryfgXOzD3lSE8ortQbhb2v3ZRmXeSD3sDAwkYYLji5Y6kIrd48ztPvrjSRrIcsqCYIF1AP/8u6XDA==", + "resolved": "https://github.com/cosmicglue-io/twinkle/archive/e45e3be7f9bf684ee123c9b790e9850feef14ae0.tar.gz", + "integrity": "sha512-u5rTK/BTWyfUPt/Bq06BHiOOr2YkxgjwlyuuN5YRMX40alxYgLYfwkz9wQo56CNwLaHJLeyEAPXWfMFkSuM5HQ==", "dev": true, "license": "Apache-2.0", "bin": { diff --git a/package.json b/package.json index 8024b87..0325bdb 100644 --- a/package.json +++ b/package.json @@ -3,9 +3,10 @@ "private": true, "scripts": { "appcast:render": "sh BuildScripts/appcast.sh render all", - "appcast:publish": "sh BuildScripts/appcast.sh publish" + "appcast:publish": "sh BuildScripts/appcast.sh publish", + "appcast:report": "sh BuildScripts/appcast-report.sh" }, "devDependencies": { - "twinkle-appcast": "https://github.com/cosmicglue-io/twinkle/archive/8fdf6eb74ca51ba9d5d587d3c94e1032b68c79eb.tar.gz" + "twinkle-appcast": "https://github.com/cosmicglue-io/twinkle/archive/e45e3be7f9bf684ee123c9b790e9850feef14ae0.tar.gz" } }