release.sh raw

   1  #!/bin/bash
   2  set -e
   3  
   4  VERSION=$(git describe --tags --abbrev=0)
   5  if [ -z "$VERSION" ]; then
   6      echo "error: no git tag found" >&2
   7      exit 1
   8  fi
   9  
  10  DIRTY=$(git diff --quiet HEAD -- && echo "" || echo "-dirty")
  11  if [ -n "$DIRTY" ]; then
  12      echo "warning: working tree is dirty" >&2
  13  fi
  14  
  15  ARCH=$(uname -m)
  16  case "$ARCH" in
  17      x86_64) ARCH=amd64 ;;
  18      aarch64) ARCH=arm64 ;;
  19      *) echo "error: unsupported arch $ARCH" >&2; exit 1 ;;
  20  esac
  21  
  22  OS=linux
  23  NAME="moxie-${VERSION}-${OS}-${ARCH}"
  24  STAGE="/tmp/${NAME}"
  25  TARBALL="/tmp/${NAME}.tar.gz"
  26  
  27  echo "building release $NAME ..." >&2
  28  
  29  # build moxie compiler
  30  ./build.sh
  31  
  32  # stage the release tree
  33  rm -rf "$STAGE"
  34  mkdir -p "$STAGE/bin"
  35  
  36  cp moxie "$STAGE/bin/"
  37  
  38  # stdlib sources
  39  cp -a src "$STAGE/src"
  40  
  41  # lib - dereference symlinks so tarball is self-contained
  42  cp -aL lib "$STAGE/lib"
  43  
  44  # jsruntime
  45  cp -a jsruntime "$STAGE/jsruntime"
  46  
  47  # strip
  48  strip "$STAGE/bin/moxie" 2>/dev/null || true
  49  
  50  echo "creating tarball ..." >&2
  51  tar czf "$TARBALL" -C /tmp "$NAME"
  52  
  53  SIZE=$(du -h "$TARBALL" | cut -f1)
  54  echo "tarball: $TARBALL ($SIZE)" >&2
  55  
  56  # push to releases repo
  57  RELEASES_DIR="/tmp/moxie-releases-stage"
  58  rm -rf "$RELEASES_DIR"
  59  
  60  git clone -b main git@orly:moxie-releases.git "$RELEASES_DIR"
  61  
  62  cp "$TARBALL" "$RELEASES_DIR/"
  63  
  64  cd "$RELEASES_DIR"
  65  git add "$(basename "$TARBALL")"
  66  git commit -m "release ${VERSION} ${OS}/${ARCH}"
  67  git tag -f "$VERSION"
  68  git push origin main
  69  git push origin "$VERSION" -f
  70  cd - >/dev/null
  71  
  72  rm -rf "$STAGE" "$RELEASES_DIR"
  73  echo "released $VERSION -> git.smesh.lol/moxie-releases" >&2
  74