Skip to content

Commit

Permalink
CI pack script
Browse files Browse the repository at this point in the history
  • Loading branch information
mfranciszkiewicz committed Feb 18, 2021
1 parent 0b4e356 commit 9150954
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions .ci/pack-build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@

fail() {
printf "%s\n" "$1" >&2
exit 1
}

not_empty() {
test -z "$1" && fail "expected $2"
}


not_empty "$GITHUB_REF" GITHUB_REF
not_empty "$OS_NAME" OS_NAME


if [ "$OS_NAME" = "ubuntu" ]; then
OS_NAME=linux
target=x86_64-unknown-linux-musl/
exe=""
elif [ "$OS_NAME" == "macos" ]; then
OS_NAME=osx
elif [ "$OS_NAME" == "windows" ]; then
exe=".exe"
else
fail "unknown os name: $OS_NAME"
fi

TAG_NAME="${GITHUB_REF##*/}"

generate_asset() {
local asset_type=$1
local bins="$2"
local asset_name="${asset_type}-${OS_NAME}-${TAG_NAME}"
local TARGET_DIR=releases/${asset_name}
mkdir -p "$TARGET_DIR"
for component in $bins; do
strip -x target/${target}release/${component}${exe}
done
for bin in $bins; do
cp "target/${target}release/${bin}${exe}" "$TARGET_DIR/"
done
if [ "$OS_NAME" = "windows" ]; then
echo "::set-output name=artifact::${asset_name}.zip"
echo "::set-output name=media::application/zip"
(cd "$TARGET_DIR" && 7z a "../${asset_name}.zip" * )
else
echo "::set-output name=artifact::${asset_name}.tar.gz"
echo "::set-output name=media::application/tar+gzip"
(cd releases && tar czf "${asset_name}.tar.gz" "${asset_name}")
du -h "releases/${asset_name}.tar.gz"
fi
}

generate_asset "$1" "$2"

0 comments on commit 9150954

Please sign in to comment.