Skip to content

Commit 129512a

Browse files
refactor(.github): avoid cloning db-sync repo when using tarball
1 parent 1ef0143 commit 129512a

File tree

1 file changed

+52
-47
lines changed

1 file changed

+52
-47
lines changed

.github/source_dbsync.sh

Lines changed: 52 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -45,37 +45,6 @@ file_is_available() {
4545
esac
4646
}
4747

48-
case "${DBSYNC_REV:-""}" in
49-
"" )
50-
echo "The value for DBSYNC_REV cannot be empty" >&2
51-
exit 1
52-
;;
53-
54-
"master" | "HEAD" )
55-
export DBSYNC_REV="master"
56-
57-
if [ ! -e cardano-db-sync ]; then
58-
git clone --depth 1 https://github.com/IntersectMBO/cardano-db-sync.git
59-
fi
60-
61-
cd cardano-db-sync || exit 1
62-
git fetch origin master
63-
;;
64-
65-
* )
66-
if [ ! -e cardano-db-sync ]; then
67-
git clone https://github.com/IntersectMBO/cardano-db-sync.git
68-
fi
69-
70-
cd cardano-db-sync || exit 1
71-
git fetch
72-
;;
73-
esac
74-
75-
git stash
76-
git checkout "$DBSYNC_REV"
77-
git rev-parse HEAD
78-
7948
DBSYNC_TAR_URL="${DBSYNC_TAR_URL:-""}"
8049

8150
# Check if DBSYNC_TAR_URL is empty and DBSYNC_REV is a version number
@@ -88,29 +57,64 @@ if [[ -z "$DBSYNC_TAR_URL" && "$DBSYNC_REV" =~ ^[0-9]+(\.[0-9]+)*$ ]]; then
8857
fi
8958
fi
9059

91-
9260
if [ -n "$DBSYNC_TAR_URL" ]; then
9361
# download db-sync
94-
DBSYNC_TAR_FILE="$WORKDIR/dbsync_bins.tar.gz"
62+
mkdir -p cardano-db-sync && cd cardano-db-sync || exit 1
63+
DBSYNC_TAR_FILE="$PWD/dbsync_bins.tar.gz"
9564
curl -sSL "$DBSYNC_TAR_URL" > "$DBSYNC_TAR_FILE" || exit 1
96-
rm -rf "${WORKDIR}/dbsync_download"
97-
mkdir -p "${WORKDIR}/dbsync_download/"
98-
tar -C "${WORKDIR}/dbsync_download/" -xzf "$DBSYNC_TAR_FILE" || exit 1
65+
rm -rf "${PWD}/dbsync_download"
66+
mkdir -p "${PWD}/dbsync_download/"
67+
tar -C "${PWD}/dbsync_download/" -xzf "$DBSYNC_TAR_FILE" || exit 1
9968
rm -f "$DBSYNC_TAR_FILE"
10069
rm -f db-sync-node
101-
ln -s "${WORKDIR}/dbsync_download" db-sync-node || exit 1
70+
ln -s "${PWD}/dbsync_download" db-sync-node || exit 1
10271
rm -f smash-server || rm -f smash-server/bin/cardano-smash-server
10372
mkdir -p smash-server/bin
104-
ln -s "${WORKDIR}/dbsync_download/bin/cardano-smash-server" smash-server/bin/cardano-smash-server || exit 1
73+
ln -s "${PWD}/dbsync_download/bin/cardano-smash-server" smash-server/bin/cardano-smash-server || exit 1
74+
DBSYNC_SCHEMA_DIR="$(readlink -m db-sync-node)/schema"
75+
export DBSYNC_SCHEMA_DIR
10576
else
10677
# Build db-sync
78+
case "${DBSYNC_REV:-""}" in
79+
"" )
80+
echo "The value for DBSYNC_REV cannot be empty" >&2
81+
exit 1
82+
;;
83+
84+
"master" | "HEAD" )
85+
export DBSYNC_REV="master"
86+
87+
if [ ! -e cardano-db-sync ]; then
88+
git clone --depth 1 https://github.com/IntersectMBO/cardano-db-sync.git
89+
fi
90+
91+
cd cardano-db-sync || exit 1
92+
git fetch origin master
93+
;;
94+
95+
* )
96+
if [ ! -e cardano-db-sync ]; then
97+
git clone https://github.com/IntersectMBO/cardano-db-sync.git
98+
fi
99+
100+
cd cardano-db-sync || exit 1
101+
git fetch
102+
;;
103+
esac
104+
105+
git stash
106+
git checkout "$DBSYNC_REV"
107+
git rev-parse HEAD
108+
107109
nix build --accept-flake-config .#cardano-db-sync -o db-sync-node \
108110
|| nix build --accept-flake-config .#cardano-db-sync:exe:cardano-db-sync -o db-sync-node \
109111
|| exit 1
110112
# Build cardano-smash-server
111113
if [ "${SMASH:-"false"}" != "false" ]; then
112114
nix build --accept-flake-config .#cardano-smash-server -o smash-server || exit 1
113115
fi
116+
DBSYNC_SCHEMA_DIR="$PWD/schema"
117+
export DBSYNC_SCHEMA_DIR
114118
fi
115119

116120
if [ ! -e db-sync-node/bin/cardano-db-sync ]; then
@@ -125,20 +129,21 @@ if [ -e smash-server/bin/cardano-smash-server ]; then
125129
fi
126130
export PATH_PREPEND
127131

128-
export DBSYNC_SCHEMA_DIR="$PWD/schema"
129-
130132
if [ -n "${DBSYNC_SKIP_INDEXES:-""}" ]; then
131133
# Delete the indexes only after the binaries are ready, so the binaries can be retrieved from
132134
# the nix binary cache if available.
135+
chmod -R u+w "$DBSYNC_SCHEMA_DIR" # Add write permissions
133136
rm -f "$DBSYNC_SCHEMA_DIR"/migration-4-000*
134137

135-
cleanup_dbsync_repo() {
136-
local _origpwd="$PWD"
137-
cd "$DBSYNC_SCHEMA_DIR"/.. || exit 1
138-
# shellcheck disable=SC2015
139-
git stash && git stash drop || :
140-
cd "$_origpwd" || exit 1
141-
}
138+
if [ -z "$DBSYNC_TAR_URL" ]; then
139+
cleanup_dbsync_repo() {
140+
local _origpwd="$PWD"
141+
cd "$DBSYNC_SCHEMA_DIR"/.. || exit 1
142+
# shellcheck disable=SC2015
143+
git stash && git stash drop || :
144+
cd "$_origpwd" || exit 1
145+
}
146+
fi
142147
fi
143148

144149
cd "$REPODIR" || exit 1

0 commit comments

Comments
 (0)