Skip to content

Commit 17859a6

Browse files
committed
fix: address PR review comments
- Rename TMPDIR → TMPWORKDIR to avoid shadowing POSIX reserved env var - Fix notify-released condition to also accept 'skipped' upload-s3 result - Pin check-package-version to @v2 (floating major tag) - Use fetch-depth: 1 (full history not needed) - Add jq validation of versions.json before uploading to S3
1 parent b064f9b commit 17859a6

File tree

2 files changed

+22
-10
lines changed

2 files changed

+22
-10
lines changed

.github/scripts/upload-posthog-js-s3.sh

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,27 +36,39 @@ aws s3 cp "$DIST_DIR/" "s3://$BUCKET/$VERSION/" \
3636
--content-type "application/javascript"
3737

3838
echo "==> Updating versions.json in s3://$BUCKET/"
39-
TMPDIR="$(mktemp -d)"
40-
trap 'rm -rf "$TMPDIR"' EXIT
39+
TMPWORKDIR="$(mktemp -d)"
40+
trap 'rm -rf "$TMPWORKDIR"' EXIT
4141

4242
# Distinguish "file doesn't exist" from real errors (auth, network).
4343
# A blind fallback to '[]' on any error would silently drop all previous versions.
44-
if aws s3 cp "s3://$BUCKET/versions.json" "$TMPDIR/versions.json"; then
44+
if aws s3 cp "s3://$BUCKET/versions.json" "$TMPWORKDIR/versions.json"; then
4545
echo "Downloaded existing versions.json"
4646
elif aws s3api head-object --bucket "$BUCKET" --key "versions.json" 2>/dev/null; then
4747
echo "ERROR: versions.json exists but could not be downloaded" >&2
4848
exit 1
4949
else
5050
echo "No existing versions.json found, starting fresh"
51-
echo '[]' > "$TMPDIR/versions.json"
51+
echo '[]' > "$TMPWORKDIR/versions.json"
5252
fi
5353

54-
if jq -e --arg v "$VERSION" '.[] | select(.version == $v)' "$TMPDIR/versions.json" > /dev/null 2>&1; then
54+
if jq -e --arg v "$VERSION" '.[] | select(.version == $v)' "$TMPWORKDIR/versions.json" > /dev/null 2>&1; then
5555
echo "Version $VERSION already in versions.json, skipping"
5656
else
5757
jq --arg v "$VERSION" --arg ts "$(date -u +%Y-%m-%dT%H:%M:%SZ)" \
58-
'. + [{"version": $v, "timestamp": $ts}]' "$TMPDIR/versions.json" > "$TMPDIR/versions_updated.json"
59-
aws s3 cp "$TMPDIR/versions_updated.json" "s3://$BUCKET/versions.json" \
58+
'. + [{"version": $v, "timestamp": $ts}]' "$TMPWORKDIR/versions.json" > "$TMPWORKDIR/versions_updated.json"
59+
60+
# Validate the updated manifest before uploading: must be a non-empty JSON array
61+
# where every entry has .version and .timestamp strings.
62+
if ! jq -e 'if type != "array" then error
63+
elif length == 0 then error
64+
elif any(.[]; (.version | type) != "string" or (.timestamp | type) != "string") then error
65+
else true end' "$TMPWORKDIR/versions_updated.json" > /dev/null 2>&1; then
66+
echo "ERROR: versions_updated.json failed validation — aborting upload" >&2
67+
cat "$TMPWORKDIR/versions_updated.json" >&2
68+
exit 1
69+
fi
70+
71+
aws s3 cp "$TMPWORKDIR/versions_updated.json" "s3://$BUCKET/versions.json" \
6072
--content-type "application/json"
6173
echo "Added v$VERSION to versions.json"
6274
fi

.github/workflows/release.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -351,11 +351,11 @@ jobs:
351351
uses: actions/checkout@v6
352352
with:
353353
ref: ${{ needs.version-bump.outputs.commit-hash }}
354-
fetch-depth: 0
354+
fetch-depth: 1
355355

356356
- name: Check posthog-js version
357357
id: check-version
358-
uses: PostHog/check-package-version@v2.1.0
358+
uses: PostHog/check-package-version@v2
359359
with:
360360
path: packages/browser
361361

@@ -434,7 +434,7 @@ jobs:
434434
name: Notify Slack - Released
435435
needs: [notify-approval-needed, publish, upload-s3]
436436
runs-on: ubuntu-latest
437-
if: always() && needs.publish.result == 'success' && needs.upload-s3.result == 'success' && needs.notify-approval-needed.outputs.slack_ts != ''
437+
if: always() && needs.publish.result == 'success' && (needs.upload-s3.result == 'success' || needs.upload-s3.result == 'skipped') && needs.notify-approval-needed.outputs.slack_ts != ''
438438
steps:
439439
- name: Checkout repository
440440
uses: actions/checkout@v6

0 commit comments

Comments
 (0)