Skip to content

Commit

Permalink
Add script to reproduce GitHub Actions runs locally
Browse files Browse the repository at this point in the history
  • Loading branch information
andreabedini committed Aug 7, 2023
1 parent 67b5e79 commit 6054509
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
1 change: 1 addition & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@
coreutils
curlMinimal.bin
gitMinimal
gh # GitHub CLI tool
gnutar
foliage.packages.${system}.default
];
Expand Down
38 changes: 38 additions & 0 deletions scripts/reproduce-github-actions-run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/usr/bin/env bash

set -o errexit
set -o pipefail

usage() {
echo "Usage: $0 [GHA RUN ID] [(DERIVATION=allPackages)]"
}

REPO="input-output-hk/cardano-haskell-packages"

ghaRunId="$1"
derivation="${2:-allPackages}"

if ! shift; then
usage
exit 0
fi

ARTIFACT_TEMP_DIR="$(mktemp -d)"
trap '{ echo "Cleaning up $ARTIFACT_TEMP_DIR"; rm -rf -- "$ARTIFACT_TEMP_DIR"; }' EXIT

echo "Downloading artifacts for run $ghaRunId in $ARTIFACT_TEMP_DIR"
gh run download --repo "$REPO" "$ghaRunId" --dir "$ARTIFACT_TEMP_DIR"

echo "Unpacking built-repo in $ARTIFACT_TEMP_DIR/_repo"
mkdir "$ARTIFACT_TEMP_DIR/_repo"
tar xf "$ARTIFACT_TEMP_DIR/built-repo/_repo.tar" -C "$ARTIFACT_TEMP_DIR/_repo"

echo -n "Obtaining commit hash ..."
headSha=$(gh run view --repo "$REPO" "$ghaRunId" --json headSha --jq .headSha)
echo " $headSha"

nix build \
"github:$REPO/${headSha}#${derivation}" \
--override-input CHaP "path:$ARTIFACT_TEMP_DIR/_repo" \
--accept-flake-config true \
--print-build-logs --show-trace

0 comments on commit 6054509

Please sign in to comment.