-
Notifications
You must be signed in to change notification settings - Fork 240
chore: upload posthog-js dist to S3 on release #3307
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+174
−3
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
0526f48
chore: upload posthog-js dist to S3 on release
dustinbyrne 09f9d9d
chore: pin aws-actions/configure-aws-credentials to SHA
dustinbyrne b064f9b
ci: split build and upload into distinct jobs
dustinbyrne 33ae2d8
fix: rename TMPDIR to TMPWORKDIR to avoid shadowing POSIX reserved en…
dustinbyrne 41e40e9
fix: validate versions.json structure before uploading to S3
dustinbyrne bbeadb3
fix: use floating major tag for check-package-version (@v2)
dustinbyrne fa44b4a
fix: use fetch-depth 1 for build-s3-artifacts checkout (full history …
dustinbyrne a8c6f89
fix: allow notify-released when upload-s3 is skipped (non-posthog-js …
dustinbyrne 2e0d22c
fix: validate versions.json length is exactly original + 1
dustinbyrne File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| #!/usr/bin/env bash | ||
| # | ||
| # Upload posthog-js dist artifacts to S3 and append the version to versions.json. | ||
| # | ||
| # Usage: | ||
| # VERSION=1.365.0 ./upload-posthog-js-s3.sh <bucket> | ||
| # | ||
| # VERSION must be set as an environment variable (not an argument) to avoid | ||
| # shell injection if the value were ever attacker-influenced. | ||
| # | ||
| # Expects AWS credentials to be configured before invocation. | ||
| # | ||
| set -euo pipefail | ||
|
|
||
| BUCKET="${1:?Usage: VERSION=x.y.z $0 <bucket>}" | ||
| DIST_DIR="packages/browser/dist" | ||
|
|
||
| if [[ -z "${VERSION:-}" ]]; then | ||
| echo "ERROR: VERSION environment variable is required" >&2 | ||
| exit 1 | ||
| fi | ||
|
|
||
| # Validate version is strict semver (e.g. 1.365.0 or 1.365.0-beta.1). | ||
| # Prevents path traversal — no slashes, dots only in expected positions. | ||
| if [[ ! "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+([-][a-zA-Z0-9.]+)?$ ]]; then | ||
| echo "ERROR: Invalid version format: '$VERSION'" >&2 | ||
| exit 1 | ||
| fi | ||
|
|
||
| echo "==> Uploading posthog-js v$VERSION to s3://$BUCKET/$VERSION/" | ||
| aws s3 cp "$DIST_DIR/" "s3://$BUCKET/$VERSION/" \ | ||
| --recursive \ | ||
| --exclude "*" \ | ||
| --include "*.js" \ | ||
| --cache-control "public, max-age=31536000, immutable" \ | ||
| --content-type "application/javascript" | ||
|
|
||
| echo "==> Updating versions.json in s3://$BUCKET/" | ||
| TMPWORKDIR="$(mktemp -d)" | ||
| trap 'rm -rf "$TMPWORKDIR"' EXIT | ||
|
|
||
| # Distinguish "file doesn't exist" from real errors (auth, network). | ||
| # A blind fallback to '[]' on any error would silently drop all previous versions. | ||
| if aws s3 cp "s3://$BUCKET/versions.json" "$TMPWORKDIR/versions.json"; then | ||
| echo "Downloaded existing versions.json" | ||
| elif aws s3api head-object --bucket "$BUCKET" --key "versions.json" 2>/dev/null; then | ||
| echo "ERROR: versions.json exists but could not be downloaded" >&2 | ||
| exit 1 | ||
| else | ||
| echo "No existing versions.json found, starting fresh" | ||
| echo '[]' > "$TMPWORKDIR/versions.json" | ||
| fi | ||
|
|
||
| if jq -e --arg v "$VERSION" '.[] | select(.version == $v)' "$TMPWORKDIR/versions.json" > /dev/null 2>&1; then | ||
| echo "Version $VERSION already in versions.json, skipping" | ||
| else | ||
| jq --arg v "$VERSION" --arg ts "$(date -u +%Y-%m-%dT%H:%M:%SZ)" \ | ||
| '. + [{"version": $v, "timestamp": $ts}]' "$TMPWORKDIR/versions.json" > "$TMPWORKDIR/versions_updated.json" | ||
|
|
||
| # Validate the updated manifest before uploading: must be a non-empty JSON array | ||
| # where every entry has .version and .timestamp strings, and length is exactly original + 1. | ||
| EXPECTED_LENGTH=$(( $(jq 'length' "$TMPWORKDIR/versions.json") + 1 )) | ||
| if ! jq -e --argjson expected "$EXPECTED_LENGTH" 'if type != "array" then error | ||
| elif length != $expected then error | ||
| elif any(.[]; (.version | type) != "string" or (.timestamp | type) != "string") then error | ||
| else true end' "$TMPWORKDIR/versions_updated.json" > /dev/null 2>&1; then | ||
| echo "ERROR: versions_updated.json failed validation — aborting upload" >&2 | ||
| cat "$TMPWORKDIR/versions_updated.json" >&2 | ||
| exit 1 | ||
| fi | ||
|
|
||
| aws s3 cp "$TMPWORKDIR/versions_updated.json" "s3://$BUCKET/versions.json" \ | ||
| --content-type "application/json" | ||
| echo "Added v$VERSION to versions.json" | ||
| fi |
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The aws script is racey, so verified this workflow already limits concurrency to 1 👍