Skip to content

Commit

Permalink
build(ci): don't spam us with native code notification (#9384)
Browse files Browse the repository at this point in the history
* run on my branch to test

* try using s3 instead for native hash storage

* echo beta last, codepush will deploy otherwise

* fix s3 upload output being captured by var

* fix s3 download being captured by var

* add new script to limit number of notifications

* hardcode to beta to test

* try updating the upload command

* revert test changes
  • Loading branch information
brainbicycle authored Oct 9, 2023
1 parent 88fd267 commit 30c1e37
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 11 deletions.
10 changes: 3 additions & 7 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -188,22 +188,18 @@ jobs:
- checkout
- install-node
- install-gems
- restore_cache:
key: native-hash-main
- setup-awscli
- run:
name: Determine Deployment Type
command: |
DEPLOYMENT_TYPE=$(./scripts/codepush/determine-deployment-type.sh)
echo "export DEPLOYMENT_TYPE=$DEPLOYMENT_TYPE" >> $BASH_ENV
- save_cache:
key: native-hash-main
paths:
- ./native-hash.txt
- run:
name: Handle Deployment for beta
command: |
if [ "$DEPLOYMENT_TYPE" == "beta" ]; then
echo "Native code changed, notifying new beta needed!"
echo "Native code changed, new beta needed!"
./scripts/codepush/maybe_notify_beta_needed.sh
circleci-agent step halt
fi
- install-node-modules
Expand Down
11 changes: 7 additions & 4 deletions scripts/codepush/determine-deployment-type.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
#!/bin/bash
set -euxo pipefail

S3_BUCKET_PATH="s3://artsy-citadel/eigen/native-hash.txt"

# Calculate the current native hash
current_native_hash=$(./scripts/codepush/calculate-native-hash.sh)

# Read the previous native hash from the cache
aws s3 cp $S3_BUCKET_PATH ./native-hash.txt > /dev/null || echo "No previous native hash found." >&2

if [ -f ./native-hash.txt ]; then
previous_native_hash=$(cat ./native-hash.txt)
else
Expand All @@ -13,12 +16,12 @@ fi

# Compare the current native hash with the previous one
if [ "$current_native_hash" != "$previous_native_hash" ]; then
# Save the current native hash to S3
echo $current_native_hash | aws s3 cp - $S3_BUCKET_PATH > /dev/null

# If the native hash has changed, then we need to deploy a new native build
echo "beta"
else
# If the native hash has not changed, then we can deploy using codepush
echo "codepush"
fi

# Save the current native hash for the next build
echo $current_native_hash > ./native-hash.txt
23 changes: 23 additions & 0 deletions scripts/codepush/maybe_notify_beta_needed.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/bash
set -euxo pipefail

S3_TIMESTAMP_PATH="s3://artsy-citadel/eigen/last-notified.txt"

# Attempt to fetch the last notification timestamp
aws s3 cp $S3_TIMESTAMP_PATH ./last-notified.txt > /dev/null || echo "No previous timestamp found." >&2

if [ -f ./last-notified.txt ]; then
last_notified=$(cat ./last-notified.txt)
else
last_notified=0
fi

current_time=$(date +%s) # Current time in seconds since 1970-01-01
time_difference=$((current_time - last_notified))

# Check if 24 hours (86400 seconds) have passed since the last notification
if [ $time_difference -ge 86400 ]; then
bundle exec fastlane notify_beta_needed
# Update the timestamp
echo $current_time | aws s3 cp - $S3_TIMESTAMP_PATH
fi

0 comments on commit 30c1e37

Please sign in to comment.