Skip to content
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

build(ci): don't spam us with native code notification #9384

Merged
merged 11 commits into from
Oct 9, 2023
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