Skip to content

Commit

Permalink
Crash release.sh when an error occur
Browse files Browse the repository at this point in the history
  • Loading branch information
etiennedub committed Aug 26, 2024
1 parent 1df9227 commit 8a3b6ca
Showing 1 changed file with 44 additions and 42 deletions.
86 changes: 44 additions & 42 deletions release.sh
Original file line number Diff line number Diff line change
@@ -1,66 +1,68 @@
#!/bin/bash
set -e
VERSION=$1
shift
CLOUD=($@)

if [ -z "$VERSION" ]; then
echo "Specify the release version number"
echo "Usage: release.sh VERSION"
exit 1
echo "Specify the release version number"
echo "Usage: release.sh VERSION"
exit 1
fi

if [ -z "$CLOUD" ]; then
CLOUD=(aws azure gcp openstack ovh)
CLOUD=(aws azure gcp openstack ovh)
fi

if [ "$(uname)" == "Linux" ]; then
sed_i () {
sed -i "$@"
}
sed_i() {
sed -i "$@"
}
elif [ "$(uname)" == "Darwin" ]; then
sed_i () {
sed -i "" "$@"
}
sed_i() {
sed -i "" "$@"
}
fi

TMPDIR=$(mktemp -d)
FOLDER=$TMPDIR/magic_castle-$VERSION

mkdir -p releases
for provider in "${CLOUD[@]}"; do
cur_folder=$FOLDER/magic_castle-$provider-$VERSION
mkdir -p $cur_folder
cp -RfL common $cur_folder/
rm $cur_folder/common/{variables,outputs}.tf
cp -RfL dns $cur_folder/
cp -RfL $provider $cur_folder/
cp -fL examples/$provider/main.tf $cur_folder
mv $cur_folder/$provider/README.md $cur_folder
sed_i 's;git::https://github.com/ComputeCanada/magic_castle.git//;./;g' $cur_folder/main.tf
sed_i "s;\"main\";\"$VERSION\";" $cur_folder/main.tf
cp LICENSE $cur_folder
cur_folder=$FOLDER/magic_castle-$provider-$VERSION
mkdir -p $cur_folder
cp -RfL common $cur_folder/
rm $cur_folder/common/{variables,outputs}.tf
cp -RfL dns $cur_folder/
cp -RfL $provider $cur_folder/
cp -fL examples/$provider/main.tf $cur_folder
mv $cur_folder/$provider/README.md $cur_folder
sed_i 's;git::https://github.com/ComputeCanada/magic_castle.git//;./;g' $cur_folder/main.tf
sed_i "s;\"main\";\"$VERSION\";" $cur_folder/main.tf
cp LICENSE $cur_folder

## Initialize to create .terraform.lock.hcl file
cd $cur_folder
## Make sure only one module is named "dns"
sed_i '1,/dns/s/dns/cloudflare/' main.tf
## Uncomment DNS modules
sed_i 's/^#\ //g' main.tf
# TODO: skip plugins download once Terraform issue #25813 is fixed
terraform init
rm -rf .terraform
cd -
## Initialize to create .terraform.lock.hcl file
cd $cur_folder
## Make sure only one module is named "dns"
sed_i '1,/dns/s/dns/cloudflare/' main.tf
## Uncomment DNS modules
sed_i 's/^#\ //g' main.tf
# TODO: skip plugins download once Terraform issue #25813 is fixed
terraform init
rm -rf .terraform
cd -

## Recreate a new unmodified main.tf
cp -fL examples/$provider/main.tf $cur_folder
sed_i 's;git::https://github.com/ComputeCanada/magic_castle.git//;./;g' $cur_folder/main.tf
sed_i "s;\"main\";\"$VERSION\";" $cur_folder/main.tf
## Recreate a new unmodified main.tf
cp -fL examples/$provider/main.tf $cur_folder
sed_i 's;git::https://github.com/ComputeCanada/magic_castle.git//;./;g' $cur_folder/main.tf
sed_i "s;\"main\";\"$VERSION\";" $cur_folder/main.tf

cd $FOLDER
tar czvf magic_castle-$provider-$VERSION.tar.gz magic_castle-$provider-$VERSION
zip magic_castle-$provider-$VERSION.zip -r magic_castle-$provider-$VERSION
cd -
cp $FOLDER/magic_castle-$provider-$VERSION.tar.gz releases/
cp $FOLDER/magic_castle-$provider-$VERSION.zip releases/
cd $FOLDER
tar czvf magic_castle-$provider-$VERSION.tar.gz magic_castle-$provider-$VERSION
zip magic_castle-$provider-$VERSION.zip -r magic_castle-$provider-$VERSION
cd -
cp $FOLDER/magic_castle-$provider-$VERSION.tar.gz releases/
cp $FOLDER/magic_castle-$provider-$VERSION.zip releases/
done
rm -rf $TMPDIR
rm -rf $TMPDIR

0 comments on commit 8a3b6ca

Please sign in to comment.