...
1#!/bin/bash
2
3set -e -o pipefail
4
5errusage() {
6 printf >&2 'Usage: %s DIR\n' "$0"
7 if [[ $# -gt 0 ]]; then
8 local msg
9 # shellcheck disable=SC2059
10 printf -v msg "$@"
11 printf >&2 '%s: error: %s\n' "$0" "$msg"
12 fi
13 exit 2
14}
15
16[[ $# == 1 ]] || errusage 'wrong number of args: %d' $#
17[[ -d "$1" ]] || errusage 'DIR is not a directory: %q' "$dir"
18[[ -n "$AWS_ACCESS_KEY_ID" ]] || errusage "AWS_ACCESS_KEY_ID is not set"
19[[ -n "$AWS_SECRET_ACCESS_KEY" ]] || errusage "AWS_SECRET_ACCESS_KEY is not set"
20[[ "${VERSION:-}" == v2.* ]] || errusage "VERSION must be set to a 'v2.*' string"
21dir=$1
22while [[ "$dir" == */ ]]; do
23 dir=${dir%/}
24done
25version=${VERSION#v}
26
27if [[ $version =~ ^[0-9]+\.[0-9]+\.[0-9]+(-ea)?$ ]] ; then
28 # if this is a stable version, working directory must be clean
29 # otherwise this is an rc or test version and we don't care
30 if [ -n "$(git status --porcelain)" ] ; then
31 echo "working tree is dirty, aborting"
32 exit 1
33 fi
34elif [[ "$BUMP_STABLE" = "true" ]] ; then
35 # if this isn't an X.Y.Z version, don't let allow bumping stable
36 echo "Cannot bump stable unless this is an X.Y.Z tag"
37 exit 1
38fi
39
40echo "$version" > stable.txt
41if [ -z "$AWS_S3_BUCKET" ] ; then
42 AWS_S3_BUCKET=datawire-static-files
43fi
44
45# make this something different than ambassador, emissary, or edge-stack
46# so we don't conflict with the new hotness we're doing for 2.0
47unversioned_base_s3_key=yaml/v2-docs/
48base_s3_key=${unversioned_base_s3_key}${version}
49aws s3api put-object \
50 --bucket "$AWS_S3_BUCKET" \
51 --key "${base_s3_key}"
52
53echo "Pushing files to s3..."
54find "$dir" -type f -print0 | while read -r -d '' file; do
55 s3_key=${base_s3_key}/${file#"${dir}/"}
56 aws s3api put-object \
57 --bucket "$AWS_S3_BUCKET" \
58 --key "${s3_key}" \
59 --body "$file"
60 echo "... ${s3_key} pushed"
61done
62
63if [[ "${BUMP_STABLE}" = "true" ]] ; then
64 echo "Bumping stable version for yaml/${dir}"
65 aws s3api put-object \
66 --bucket "$AWS_S3_BUCKET" \
67 --key "${unversioned_base_s3_key}stable.txt" \
68 --body stable.txt
69fi
70
71echo "Done pushing files to s3"
72rm stable.txt
View as plain text