#!/usr/bin/env bash
set -euxo pipefail

VERSION=${REF#"refs/tags/"}
DIST=$GITHUB_WORKSPACE/dist
mkdir -p $DIST

echo "Packaging for $TARGET..."

RUSTFLAGS="--deny warnings $TARGET_RUSTFLAGS" \
  cargo build --bin tcping --target $TARGET --release

cp target/$TARGET/release/tcping $DIST/

cd $DIST
ARCHIVE="tcping-$VERSION-$TARGET.tar.gz"
tar czf $ARCHIVE *

# List the contents of the $DIST directory
ls -l

# Print the value of $ARCHIVE
echo "ARCHIVE: $ARCHIVE"

# Write the path of the archive file to GITHUB_ENV
echo "ARCHIVE=$DIST/$ARCHIVE" >> $GITHUB_ENV

# Print the contents of GITHUB_ENV
cat $GITHUB_ENV