Debian Codegraph @

scripts/create-releases.sh

raw symbols SCIP
1 #!/bin/bash
2
3 # Copyright The Soci Snapshotter Authors.
4
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
8
9 # http://www.apache.org/licenses/LICENSE-2.0
10
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16
17 # A script to generate release artifacts.
18 # This will create a folder in your project root called release.
19 # This will contain the dynamic + static binaries
20 # as well as their respective sha256 checksums.
21 # NOTE: this will mutate your $SOCI_SNAPSHOTTER_PROJECT_ROOT/out folder.
22
23 set -eux -o pipefail
24
25 CUR_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
26 SOCI_SNAPSHOTTER_PROJECT_ROOT="$(cd -- "$CUR_DIR"/.. && pwd)"
27 OUT_DIR="${SOCI_SNAPSHOTTER_PROJECT_ROOT}/out"
28 RELEASE_DIR="${SOCI_SNAPSHOTTER_PROJECT_ROOT}/release"
29 LICENSE_FILE=${SOCI_SNAPSHOTTER_PROJECT_ROOT}/THIRD_PARTY_LICENSES
30 NOTICE_FILE=${SOCI_SNAPSHOTTER_PROJECT_ROOT}/NOTICE.md
31 TAG_REGEX="v[0-9]+.[0-9]+.[0-9]+"
32
33 ARCH=""
34 case $(uname -m) in
35 x86_64) ARCH="amd64" ;;
36 aarch64) ARCH="arm64" ;;
37 *) echo "Error: Unsupported arch"; exit 1 ;;
38 esac
39
40 if [ "$#" -ne 1 ]; then
41 echo "Expected 1 parameter, got $#."
42 echo "Usage: $0 [release_tag]"
43 exit 1
44 fi
45
46 if ! [[ "$1" =~ $TAG_REGEX ]]; then
47 echo "Improper tag format. Format should match regex $TAG_REGEX"
48 exit 1
49 fi
50
51 if [ -d "$RELEASE_DIR" ]; then
52 rm -rf "${RELEASE_DIR:?}"/*
53 else
54 mkdir "$RELEASE_DIR"
55 fi
56
57 release_version=${1/v/} # Remove v from tag name
58 dynamic_binary_name=soci-snapshotter-${release_version}-linux-${ARCH}.tar.gz
59 static_binary_name=soci-snapshotter-${release_version}-linux-${ARCH}-static.tar.gz
60
61 make build
62 cp "$NOTICE_FILE" "$LICENSE_FILE" "${OUT_DIR}"
63 tar -czvf "$RELEASE_DIR"/"$dynamic_binary_name" "$OUT_DIR"
64 rm -rf "{$OUT_DIR:?}"/*
65
66 STATIC=1 make build
67 cp "$NOTICE_FILE" "$LICENSE_FILE" "$OUT_DIR"
68 tar -czvf "$RELEASE_DIR"/"$static_binary_name" "$OUT_DIR"
69 rm -rf "{$OUT_DIR:?}"/*
70
71 sha256sum "$RELEASE_DIR"/"$dynamic_binary_name" > "$RELEASE_DIR"/"$dynamic_binary_name".sha256sum
72 sha256sum "$RELEASE_DIR"/"$static_binary_name" > "$RELEASE_DIR"/"$static_binary_name".sha256sum