Skip to content

Commit

Permalink
Improve scripts/add-revions.sh
Browse files Browse the repository at this point in the history
The need to pass a `BUILT_REPO` arg is very confusing and it is small enough to just DL the latest to a temp dir.

This change also only uses the `BUILT_REPO` if there is no existing revision.  If there is a revision it copies the `.cabal` file from there (in case it is not in the BUILT_REPO yet).

Also uses `date -u` instead of `date --utc` so that we don't have to install `gdate` on macOS to make it work.
  • Loading branch information
hamishmack authored and andreabedini committed Jun 13, 2023
1 parent a8c1882 commit a1e315a
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 16 deletions.
16 changes: 10 additions & 6 deletions scripts/add-revision.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ set -o pipefail
SCRIPT_DIR=$(dirname "$(which "$0")")

function usage {
echo "Usage $(basename "$0") BUILT_REPO PKG_NAME PKG_VERSION"
echo "Usage $(basename "$0") PKG_NAME PKG_VERSION"
echo " Adds a new revision with the existing cabal file for that package"
echo " version. Requires a built repository. Does not commit."
exit
Expand All @@ -28,15 +28,18 @@ done

shift $((OPTIND - 1))

BUILT_REPO=$1
PKG_NAME=$2
PKG_VERSION=$3
PKG_NAME=$1
PKG_VERSION=$2

if ! shift 3; then
if ! shift 2; then
usage
exit 1
fi

BUILT_REPO=$(mktemp -d)
mkdir -p $BUILT_REPO/index
curl -L https://input-output-hk.github.io/cardano-haskell-packages/01-index.tar.gz | tar -C $BUILT_REPO/index -xz

META_DIR="_sources/$PKG_NAME/$PKG_VERSION"
META_FILE="$META_DIR/meta.toml"
REVISIONS_DIR="$META_DIR/revisions"
Expand All @@ -63,10 +66,11 @@ else
LATEST_REVISION=$(echo "$CURRENT_REVISIONS" | sort | tail -n1)
LATEST_REVISION_NUMBER=$(basename "$LATEST_REVISION" | cut -f 1 -d '.')
NEW_REVISION_NUMBER=$((LATEST_REVISION_NUMBER+1))
CURRENT_CABAL_FILE="$REVISIONS_DIR/$LATEST_REVISION_NUMBER.cabal"
fi

NEW_CABAL_FILE="$REVISIONS_DIR/$NEW_REVISION_NUMBER.cabal"
echo "Moving $CURRENT_CABAL_FILE to $NEW_CABAL_FILE"
echo "Copying $CURRENT_CABAL_FILE to $NEW_CABAL_FILE"

mkdir -p "$REVISIONS_DIR"
cp "$CURRENT_CABAL_FILE" "$NEW_CABAL_FILE"
Expand Down
7 changes: 1 addition & 6 deletions scripts/current-timestamp.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
#!/usr/bin/env bash

# Use gnu-tar and gnu-date regardless of whether the OS is Linux
# or BSD-based. The correct command will be assigned to TAR and DATE
# variables.
source "$(dirname "$(which "$0")")/use-gnu-tar.sh"

"$DATE" --utc +%Y-%m-%dT%H:%M:%SZ
date -u +%Y-%m-%dT%H:%M:%SZ
4 changes: 0 additions & 4 deletions scripts/use-gnu-tar.sh
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
#!/usr/bin/env bash

export DATE="date"
export TAR="tar"

if [[ "$(uname -s)" == "Darwin" ]]; then
if [[ "$(which date)" == "/bin/date" ]]; then
export DATE="gdate"
fi
if [[ "$(which tar)" == "/usr/bin/tar" ]]; then
export TAR="gtar"
fi
Expand Down

0 comments on commit a1e315a

Please sign in to comment.