Change commands used to manipulate files
These changes were in response to review comments
to PR [1,2,3]
[1]
[2]
[3]
I also took the opportunity to add some comments reflecting the points
discussed during review of that PR.
#!/bin/bash
+
+# This script is intended to be run from the GitHub Action `revert.yml` but may also be run locally.
+# To run locally, you need three command line arguments (see below) as well as having AWS credentials appropriately set.
+
set -x
# data source name corresponding to builds to revert. "gisaid" or "open".
@@ -28,22 +32,26 @@ fi
missing_count=0
for region in $regions; do
- if nextstrain remote list s3://nextstrain-data/ncov_${data_source_name}_${region}_${date}.json; then
- # revert main json
- nextstrain remote download "s3://nextstrain-data/ncov_${data_source_name}_${region}_${date}.json" .
- mv "ncov_${data_source_name}_${region}_${date}.json" "ncov_${data_source_name}_${region}.json"
- nextstrain remote upload "s3://nextstrain-data" "s3://nextstrain-data/ncov_${data_source_name}_${region}.json"
- # revert tip frequencies json
- nextstrain remote download "s3://nextstrain-data/ncov_${data_source_name}_${region}_${date}_tip-frequencies.json" .
- mv "ncov_${data_source_name}_${region}_${date}_tip-frequencies.json" "ncov_${data_source_name}_${region}_tip-frequencies.json"
- nextstrain remote upload "s3://nextstrain-data" "ncov_${data_source_name}_${region}_tip-frequencies.json"
+ if curl -fsLI "https://data.nextstrain.org/ncov_${data_source_name}_${region}_${date}.json" >/dev/null; then
+ ## Download the date-stamped (auspice) JSONs, renaming them to the non-datestamped version.
+ ## Note that if the tip-frequencies don't exist for some reason then the command (& action)
+ ## will fail, but this is preferable to leaving a dataset in a mixed state.
+ ## We skip the root-sequence JSON as this doesn't change day-to-day
+ nextstrain remote download \
+ "s3://nextstrain-data/ncov_${data_source_name}_${region}_${date}.json" \
+ "ncov_${data_source_name}_${region}.json"
+ nextstrain remote download \
+ "s3://nextstrain-data/ncov_${data_source_name}_${region}_${date}_tip-frequencies.json" \
+ "ncov_${data_source_name}_${region}_tip-frequencies.json"
+ ## Upload these, overwriting the canonical (non-datestamped) datasets
+ ## Note that we use the nextstrain-cli here as it performs cloudfront invalidation
+ nextstrain remote upload \
+ "s3://nextstrain-data" \
+ "ncov_${data_source_name}_${region}.json" "ncov_${data_source_name}_${region}_tip-frequencies.json"
else
+ echo "WARNING: The requested dataset for ${data_source_name}_${region}_${date} doesn't exist and thus we can't revert to it."
((missing_count++))
fi
done
-if [[ "$missing_count" -gt 0 ]]; then
- echo "At least one requested dataset doesn't exist and thus we can't revert to it!"
-fi
-
exit $missing_count
