Skip to content

Commit

Permalink
add hooks directly to PR
Browse files Browse the repository at this point in the history
  • Loading branch information
angerman committed May 8, 2024
1 parent ae42acf commit 4575995
Show file tree
Hide file tree
Showing 8 changed files with 63 additions and 3 deletions.
3 changes: 0 additions & 3 deletions .github/workflows/devx.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,8 @@ jobs:
- name: add patched cabal
run: |
mkdir ~/bin
mkdir cabalHooks
curl -L https://ci.zw3rk.com/job/input-output-hk-haskell-nix-example/pullrequest-2/x86_64-linux.cabal-install-static/latest/download/1 | gunzip > ~/bin/cabal
curl -L https://ci.zw3rk.com/job/input-output-hk-haskell-nix-example/pullrequest-2/x86_64-linux.cabal-install-hooks/latest/download/1 | tar xzf - -C ./cabalHooks
chmod +x ~/bin/cabal
chmod +x ./cabalHooks/*Hook*
- name: Cabal update
run: ~/bin/cabal update
Expand Down
4 changes: 4 additions & 0 deletions cabalHooks/postBuildHook
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env bash

#./postBuildHook.local "$@"
postBuildHook.s3 "$@"
10 changes: 10 additions & 0 deletions cabalHooks/postBuildHook.local
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/usr/bin/env bash

CACHE=$HOME/.cabal-build-cache

mkdir -p $CACHE

echo "Uploading $1 to $CACHE"
tar -czf $CACHE/$1.tar.gz --exclude=$3/setup-config $3
exit 0

10 changes: 10 additions & 0 deletions cabalHooks/postBuildHook.s3
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/usr/bin/env bash

. "$(dirname "${BASH_SOURCE[0]}")/s3-credentials.bash"

CACHE_KEY="$1.tar.gz"

echo "Compressing and uploading $1 to S3"
tar -czf $CACHE_KEY --exclude=$3/setup-config $3
aws s3 cp $CACHE_KEY s3://$CACHE_BUCKET/devx-shell/$CACHE_KEY --endpoint-url $AWS_ENDPOINT
rm $CACHE_KEY # Optional: Cleanup local file
4 changes: 4 additions & 0 deletions cabalHooks/preBuildHook
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env bash

#./preBuildHook.local "$@"
preBuildHook.s3 "$@"
14 changes: 14 additions & 0 deletions cabalHooks/preBuildHook.local
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/usr/bin/env bash

CACHE=$HOME/.cabal-build-cache

mkdir -p $CACHE

if [ -f $CACHE/$1.tar.gz ]; then
echo "Cache hit"
tar -xzf $CACHE/$1.tar.gz
exit 0
else
echo "Cache miss"
exit 1
fi
16 changes: 16 additions & 0 deletions cabalHooks/preBuildHook.s3
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/usr/bin/env bash

. "$(dirname "${BASH_SOURCE[0]}")/s3-credentials.bash"

CACHE_KEY="$1.tar.gz"

# Check if artifact exists in S3 (with endpoint and credentials)
aws s3 ls s3://$CACHE_BUCKET/devx-shell/$CACHE_KEY --endpoint-url $AWS_ENDPOINT > /dev/null 2>&1

if [ $? -eq 0 ]; then
echo "Cache hit - downloading from S3"
aws s3 cp s3://$CACHE_BUCKET/devx-shell/$CACHE_KEY - --endpoint-url $AWS_ENDPOINT | tar -xz
else
echo "Cache miss"
exit 1
fi
5 changes: 5 additions & 0 deletions cabalHooks/s3-credentials.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
CACHE_BUCKET="cabal-cache" # Replace with your bucket name
export AWS_ACCESS_KEY_ID=$CABAL_AWS_ACCESS_KEY_ID
export AWS_SECRET_ACCESS_KEY=$CABAL_AWS_SECRET_ACCESS_KEY
export AWS_DEFAULT_REGION=auto
AWS_ENDPOINT="https://c1fe99e5a421ac98af478e51dda5db4f.r2.cloudflarestorage.com"

0 comments on commit 4575995

Please sign in to comment.