Skip to content

Commit

Permalink
fix release script to support git lfs
Browse files Browse the repository at this point in the history
  • Loading branch information
jriguera committed Jun 21, 2022
1 parent a62723e commit a6d3586
Showing 1 changed file with 15 additions and 40 deletions.
55 changes: 15 additions & 40 deletions create-final-public-release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@ set -e
RELEASE="mtail"
DESCRIPTION="Mtail Bosh Release"
GITHUB_REPO="SpringerPE/mtail-boshrelease"
# Do not define this variable if the repo uses git lfs
# https://starkandwayne.com/blog/bosh-releases-with-git-lfs/
RELEASE_BUCKET="mtail-boshrelease"

###

Expand Down Expand Up @@ -50,23 +47,6 @@ then
exit 1
fi

if [ -n "$RELEASE_BUCKET" ]
then
# You need s3cmd installed and with you credentials
if ! [ -x "$(command -v $S3CMD)" ]
then
echo "$S3CMD command not found!"
exit 1
fi
# Checking if the bucket is there. If not, create it first (this just a check to
# be sure that s3cmd is properly setup and with the correct credentials
if ! $S3CMD ls | grep "s3://$RELEASE_BUCKET" >/dev/null 2>&1
then
echo "Bucket 's3://$RELEASE_BUCKET' not found! Please create it first!"
exit 1
fi
fi

case $# in
0)
echo "*** Creating a new release. Automatically calculating next release version number"
Expand Down Expand Up @@ -125,22 +105,16 @@ else
$BOSH_CLI create-release --force --final --tarball="/tmp/$RELEASE-$$.tgz" --name "$RELEASE" --version "$version"
fi

# Create a release in Github
sha1=$($SHA1 "/tmp/$RELEASE-$$.tgz" | cut -d' ' -f1)
cat <<EOF > manifest/vars-release-version.yml
releases:
- name: $RELEASE
url: https://github.com/${GITHUB_REPO}/releases/download/v${version}/${RELEASE}-${version}.tgz
version: $version
sha1: $sha1
EOF
# Create a new tag and update the changes
echo "* Commiting git changes ..."
git add .final_builds releases/$RELEASE/index.yml "releases/$RELEASE/$RELEASE-$version.yml" config/blobs.yml manifest/vars-release-version.yml
git add .final_builds releases/$RELEASE/index.yml "releases/$RELEASE/$RELEASE-$version.yml" config/blobs.yml blobstore
git commit -m "$RELEASE v$version Boshrelease"
git push
git push --tags

# Create a release in Github
echo "* Creating a new release in Github ... "
sha1=$($SHA1 "/tmp/$RELEASE-$$.tgz" | cut -d' ' -f1)
description=$(cat <<EOF
# $RELEASE version $version
Expand All @@ -154,30 +128,31 @@ $git_changes
releases:
- name: $RELEASE
url: https://github.com/${GITHUB_REPO}/releases/download/v${version}/${RELEASE}-${version}.tgz
url: https://github.com/${GITHUB_REPO}/releases/download/v${version}/${RELEASE}.tgz
version: $version
sha1: $sha1
or to always point to latest release:
releases:
- name: $RELEASE
url: https://github.com/${GITHUB_REPO}/releases/latest/download/${RELEASE}.tgz
version: latest
EOF
)
echo "* Creating a new release in Github ... "
printf -v DATA '{"tag_name": "v%s","target_commitish": "master","name": "v%s","body": %s,"draft": false, "prerelease": false}' "$version" "$version" "$(echo "$description" | $JQ -R -s '@text')"
releaseid=$($CURL -H "Authorization: token $GITHUB_TOKEN" -H "Content-Type: application/json" -XPOST --data "$DATA" "https://api.github.com/repos/$GITHUB_REPO/releases" | $JQ '.id')

# Upload the release
echo "* Uploading tarball to Github releases section ... "
echo -n " URL: "
$CURL -H "Authorization: token $GITHUB_TOKEN" -H "Content-Type: application/octet-stream" --data-binary @"/tmp/$RELEASE-$$.tgz" "https://uploads.github.com/repos/$GITHUB_REPO/releases/$releaseid/assets?name=$RELEASE-$version.tgz" | $JQ -r '.browser_download_url'
$CURL -H "Authorization: token $GITHUB_TOKEN" -H "Content-Type: application/octet-stream" --data-binary @"/tmp/$RELEASE-$$.tgz" "https://uploads.github.com/repos/$GITHUB_REPO/releases/$releaseid/assets?name=$RELEASE.tgz" | $JQ -r '.browser_download_url'

# Delete the release
rm -f "/tmp/$RELEASE-$$.tgz"

if [ -n "$RELEASE_BUCKET" ]
then
# Update ACLs on bucket
echo "* Assigning public ACL to new blobs in bucket ... "
$S3CMD setacl "s3://${RELEASE_BUCKET}" --acl-public --recursive
fi

echo
echo "*** Description https://github.com/$GITHUB_REPO/releases/tag/v$version: "
echo
Expand Down

0 comments on commit a6d3586

Please sign in to comment.