Skip to content

Commit 7355e2f

Browse files
committed
don't emit emtpy version; make check/get/put consitent version wise
- Concourse v8.X doesn't allow emiting the empty version: concourse/concourse#9293
1 parent 5f01797 commit 7355e2f

5 files changed

Lines changed: 25 additions & 13 deletions

File tree

assets/check

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ fi
2424
[ -n "$AWS_DEFAULT_REGION" ] && export AWS_DEFAULT_REGION
2525

2626
# Consider the most recent LastModified timestamp as the most recent version.
27-
timestamps=$(aws s3api list-objects --bucket $bucket --prefix "$prefix" --query 'Contents[].{LastModified: LastModified}')
28-
recent="$(echo $timestamps | jq -r 'max_by(.LastModified)')"
29-
echo "[$recent]"
27+
recent="$("$(dirname $0)/get_version.sh" "$bucket" "$prefix")"
28+
if [ -n "$recent" ]; then
29+
echo "[$recent]"
30+
else
31+
echo "[]"
32+
fi

assets/emit.sh

Lines changed: 0 additions & 8 deletions
This file was deleted.

assets/get_version.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/bin/sh
2+
3+
# Outputs the most recent version object: {"LastModified": "..."}
4+
# Prints nothing when no objects exist under the prefix.
5+
6+
set -e
7+
8+
bucket=$1
9+
prefix=$2
10+
11+
aws s3api list-objects \
12+
--bucket "$bucket" \
13+
--prefix "$prefix" \
14+
--query 'Contents[].{LastModified: LastModified}' \
15+
| jq -c 'if length == 0 then empty else max_by(.LastModified) end'

assets/in

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,5 @@ if [ "$dosync" == "true" ]; then
4141
echo "...done."
4242
fi
4343

44-
source "$(dirname $0)/emit.sh" >&3
44+
version=$(echo "$payload" | jq -c '.version')
45+
echo "{\"version\": $version}" >&3

assets/out

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,5 @@ echo "Running: aws s3 cp $source/$dir \"s3://$bucket/$path\" $options"
4242
eval aws s3 cp $source/$dir "s3://$bucket/$path" $options $put_options
4343
echo "...done."
4444

45-
source "$(dirname $0)/emit.sh" >&3
45+
recent="$("$(dirname $0)/get_version.sh" "$bucket" "$path")"
46+
echo "{\"version\": $recent}" >&3

0 commit comments

Comments
 (0)