Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve scripts/add-revions.sh #332

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -232,11 +232,9 @@ In principle you can change other things too, but this is generally frowned upon

This repository contains a convenience script for adding a revision to CHaP:
```
$ ./scripts/add-revision.sh _repo PACKAGE_NAME PACKAGE_VERSION
$ ./scripts/add-revision.sh PACKAGE_NAME PACKAGE_VERSION
```

`_repo` needs to point to a [built package repository](#how-to-get-the-built-cabal-package-repository).
It will add a new revision and copy the _current_ cabal file in as the revised cabal file.
You can then edit that file and commit the result.

### How to add a patched versions of a Hackage package
Expand Down
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
Copy link
Contributor

@andreabedini andreabedini Jun 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One can do

curl -L https://input-output-hk.github.io/cardano-haskell-packages/01-index.tar.gz | tar xvz cardano-cli/8.0.0/cardano-cli.cabal
``` to get the latest revision for `cardano-cli-8.0.0`.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or even

curl -L https://input-output-hk.github.io/cardano-haskell-packages/package/cardano-cli-8.0.0/cardano-cli.cabal

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this even correct? This downloads only the index. I guess that probably works in this case but I'm not sure. I think it would be safer to get the entire latest repository using one of the methods in https://github.com/input-output-hk/cardano-haskell-packages/pull/323


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