Skip to content

Commit 0e30dc9

Browse files
committed
release.sh: git clone before building
Create a temporary directory inside loop/ directory and make a clone of Git repo to that dir. This ensures that the version built is exactly what is committed without any unstaged files and not dirty.
1 parent 3150aa5 commit 0e30dc9

File tree

1 file changed

+18
-10
lines changed

1 file changed

+18
-10
lines changed

release.sh

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,16 @@
1010
# Exit on errors.
1111
set -e
1212

13+
# Get the directory of the script
14+
SCRIPT_DIR="$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
15+
16+
# Checkout the repo to a subdir to clean from clean from unstaged files and
17+
# build exactly what is committed.
18+
BUILD_DIR="${SCRIPT_DIR}/tmp-build-$(date +%Y%m%d-%H%M%S)"
19+
mkdir -p $BUILD_DIR
20+
cd $BUILD_DIR
21+
git clone --tags "$SCRIPT_DIR" .
22+
1323
TAG=''
1424

1525
check_tag() {
@@ -80,25 +90,21 @@ go mod vendor
8090
tar -cvzf vendor.tar.gz vendor
8191

8292
PACKAGE=loop
83-
MAINDIR=$PACKAGE-$TAG
84-
mkdir -p $MAINDIR
93+
ARTIFACTS_DIR="${SCRIPT_DIR}/${PACKAGE}-${TAG}"
94+
mkdir -p $ARTIFACTS_DIR
8595

86-
cp vendor.tar.gz $MAINDIR/
96+
cp vendor.tar.gz $ARTIFACTS_DIR/
8797
rm vendor.tar.gz
8898
rm -r vendor
8999

90-
PACKAGESRC="$MAINDIR/$PACKAGE-source-$TAG.tar"
100+
PACKAGESRC="${ARTIFACTS_DIR}/${PACKAGE}-source-${TAG}.tar"
91101
git archive -o $PACKAGESRC HEAD
92102
gzip -f $PACKAGESRC > "$PACKAGESRC.gz"
93103

94-
cd $MAINDIR
95-
96104
# If LOOPBUILDSYS is set the default list is ignored. Useful to release
97105
# for a subset of systems/architectures.
98106
SYS=${LOOPBUILDSYS:-"windows-amd64 linux-386 linux-amd64 linux-armv6 linux-armv7 linux-arm64 darwin-arm64 darwin-amd64 freebsd-amd64 freebsd-arm"}
99107

100-
# Use the first element of $GOPATH in the case where GOPATH is a list
101-
# (something that is totally allowed).
102108
PKG="github.com/lightninglabs/loop"
103109
COMMIT=$(git describe --abbrev=40 --dirty)
104110
COMMITFLAGS="-X $PKG/build.Commit=$COMMIT"
@@ -126,12 +132,14 @@ for i in $SYS; do
126132
cd ..
127133

128134
if [[ $OS = "windows" ]]; then
129-
zip -r $PACKAGE-$i-$TAG.zip $PACKAGE-$i-$TAG
135+
zip -r "${ARTIFACTS_DIR}/${PACKAGE}-${i}-${TAG}.zip" "${PACKAGE}-${i}-${TAG}"
130136
else
131-
tar -cvzf $PACKAGE-$i-$TAG.tar.gz $PACKAGE-$i-$TAG
137+
tar -cvzf "${ARTIFACTS_DIR}/${PACKAGE}-${i}-${TAG}.tar.gz" "${PACKAGE}-${i}-${TAG}"
132138
fi
133139

134140
rm -r $PACKAGE-$i-$TAG
135141
done
136142

143+
cd "$ARTIFACTS_DIR"
144+
137145
shasum -a 256 * > manifest-$TAG.txt

0 commit comments

Comments
 (0)