Skip to content

Commit 754e73f

Browse files
fix: photon cache invalidation for local dev (#2109)
* fix: improve photon cache invalidation for local dev - Track both version AND commit in install log (photon:version:commit) - Validate PHOTON_VERSION and PHOTON_COMMIT are set before install - Use portable sed -i for macOS/Linux compatibility - Clean up old log entries when version/commit changes - Verify binary exists after installation - Add --force to CLI install message suggestions - Update VERSIONS array in shared.sh to track commit * add workflow_dispatch for forester-tests
1 parent 5fd3235 commit 754e73f

4 files changed

Lines changed: 50 additions & 23 deletions

File tree

.github/workflows/forester-tests.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ permissions:
44
contents: read
55

66
on:
7+
workflow_dispatch:
78
push:
89
branches: [main]
910
paths:

cli/src/utils/processPhotonIndexer.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,11 @@ async function isExpectedPhotonVersion(
2828

2929
function getPhotonInstallMessage(): string {
3030
if (USE_PHOTON_FROM_GIT && PHOTON_GIT_COMMIT) {
31-
return `\nLatest Photon indexer not found. Please install it by running: "cargo install --git ${PHOTON_GIT_REPO} --rev ${PHOTON_GIT_COMMIT} --locked"`;
31+
return `\nPhoton indexer ${PHOTON_VERSION} (commit ${PHOTON_GIT_COMMIT}) not found. Please install it by running: "cargo install --git ${PHOTON_GIT_REPO} --rev ${PHOTON_GIT_COMMIT} --locked --force"`;
3232
} else if (USE_PHOTON_FROM_GIT) {
33-
return `\nLatest Photon indexer not found. Please install it by running: "cargo install --git ${PHOTON_GIT_REPO} --locked"`;
33+
return `\nPhoton indexer ${PHOTON_VERSION} not found. Please install it by running: "cargo install --git ${PHOTON_GIT_REPO} --locked --force"`;
3434
} else {
35-
return `\nLatest Photon indexer not found. Please install it by running: "cargo install photon-indexer --version ${PHOTON_VERSION} --locked"`;
35+
return `\nPhoton indexer ${PHOTON_VERSION} not found. Please install it by running: "cargo install photon-indexer --version ${PHOTON_VERSION} --locked --force"`;
3636
}
3737
}
3838

scripts/devenv/install-photon.sh

Lines changed: 45 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,33 +4,59 @@ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
44
source "${SCRIPT_DIR}/shared.sh"
55

66
install_photon() {
7-
local expected_version=$(get_version "photon")
8-
local photon_installed=false
9-
local photon_correct_version=false
7+
local expected_version="${PHOTON_VERSION}"
8+
local expected_commit="${PHOTON_COMMIT}"
9+
local install_marker="photon:${expected_version}:${expected_commit}"
10+
11+
# Validate required variables
12+
if [ -z "${expected_version}" ] || [ -z "${expected_commit}" ]; then
13+
echo "ERROR: PHOTON_VERSION or PHOTON_COMMIT not set in versions.sh"
14+
exit 1
15+
fi
1016

1117
export CARGO_HOME="${PREFIX}/cargo"
1218
export PATH="${PREFIX}/cargo/bin:${PATH}"
1319

14-
if ! is_installed "photon"; then
15-
if [ -f "${PREFIX}/cargo/bin/photon" ]; then
16-
photon_installed=true
17-
if photon_version=$(${PREFIX}/cargo/bin/photon --version 2>/dev/null); then
18-
if echo "$photon_version" | grep -q "$expected_version"; then
19-
photon_correct_version=true
20-
fi
21-
fi
22-
fi
20+
# Ensure directories and log file exist
21+
mkdir -p "${PREFIX}/cargo/bin"
22+
touch "$INSTALL_LOG"
2323

24-
if [ "$photon_installed" = false ] || [ "$photon_correct_version" = false ]; then
25-
echo "Installing Photon indexer (version $expected_version)..."
26-
RUSTFLAGS="-A dead-code" cargo install --git https://github.com/helius-labs/photon.git --rev ${PHOTON_COMMIT} --locked --force
27-
log "photon"
24+
# Portable sed -i (macOS vs Linux)
25+
sed_inplace() {
26+
if [[ "$OSTYPE" == "darwin"* ]]; then
27+
sed -i '' "$@"
2828
else
29-
echo "Photon already installed with correct version, skipping..."
29+
sed -i "$@"
30+
fi
31+
}
32+
33+
# Check if exact version+commit combo is already installed
34+
if grep -q "^${install_marker}$" "$INSTALL_LOG" 2>/dev/null; then
35+
# Double-check binary actually exists
36+
if [ -f "${PREFIX}/cargo/bin/photon" ]; then
37+
echo "Photon ${expected_version} (commit ${expected_commit}) already installed, skipping..."
38+
return 0
3039
fi
31-
else
32-
echo "Photon already installed with correct version, skipping..."
40+
# Binary missing despite log entry - remove stale log entry
41+
sed_inplace "/^photon:/d" "$INSTALL_LOG" 2>/dev/null || true
42+
fi
43+
44+
# Remove any old photon entries from log (different version/commit)
45+
sed_inplace "/^photon:/d" "$INSTALL_LOG" 2>/dev/null || true
46+
sed_inplace "/^photon$/d" "$INSTALL_LOG" 2>/dev/null || true
47+
48+
echo "Installing Photon indexer ${expected_version} (commit ${expected_commit})..."
49+
RUSTFLAGS="-A dead-code" cargo install --git https://github.com/helius-labs/photon.git --rev ${expected_commit} --locked --force
50+
51+
# Verify installation succeeded
52+
if [ ! -f "${PREFIX}/cargo/bin/photon" ]; then
53+
echo "ERROR: Photon installation failed - binary not found"
54+
exit 1
3355
fi
56+
57+
# Log the exact version+commit installed
58+
echo "${install_marker}" >> "$INSTALL_LOG"
59+
echo "Photon ${expected_version} (commit ${expected_commit}) installed successfully"
3460
}
3561

3662
install_photon

scripts/devenv/shared.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ VERSIONS=(
1818
"solana:${SOLANA_VERSION}"
1919
"anchor:${ANCHOR_VERSION}"
2020
"jq:${JQ_TAG}"
21-
"photon:${PHOTON_VERSION}"
21+
"photon:${PHOTON_VERSION}:${PHOTON_COMMIT}"
2222
"redis:${REDIS_VERSION}"
2323
)
2424

0 commit comments

Comments
 (0)