Skip to content

Commit 860d4e7

Browse files
authored
Merge pull request #4 from solana-developers/fix-anchor-cache
Fix anchor cache
2 parents e8241c3 + 41cfc78 commit 860d4e7

File tree

2 files changed

+100
-16
lines changed

2 files changed

+100
-16
lines changed

extract-versions/action.yaml

Lines changed: 90 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: "Extract Versions"
2-
description: "Extracts Solana and Anchor versions from Cargo.lock"
2+
description: "Extracts Solana and Anchor versions from anchor.toml or Cargo.lock"
33
outputs:
44
solana_version:
55
description: "Detected Solana version"
@@ -14,30 +14,106 @@ runs:
1414
- id: extract
1515
shell: bash
1616
run: |
17-
# Extract Solana version from Cargo.lock or use override
17+
set +e # Don't exit on error
18+
19+
# Debug information
20+
echo "=== Debug Information ==="
21+
echo "Current directory: $(pwd)"
22+
echo "Directory contents:"
23+
ls -la
24+
echo "Looking for Anchor.toml/anchor.toml..."
25+
find . -iname "anchor.toml" || echo "No anchor.toml found in directory tree"
26+
echo "======================="
27+
28+
# Function to extract version from anchor.toml
29+
extract_from_anchor_toml() {
30+
local key=$1
31+
local version=""
32+
# Try both uppercase and lowercase variants
33+
if [ -f "Anchor.toml" ]; then
34+
echo "Found Anchor.toml in current directory" >&2
35+
version=$(grep -i "^${key}_version *= *\".*\"" Anchor.toml | cut -d'"' -f2 || true)
36+
elif [ -f "anchor.toml" ]; then
37+
echo "Found anchor.toml in current directory" >&2
38+
version=$(grep -i "^${key}_version *= *\".*\"" anchor.toml | cut -d'"' -f2 || true)
39+
# Then try to find it in subdirectories
40+
else
41+
anchor_toml=$(find . -iname "anchor.toml" -type f | head -n 1)
42+
if [ -n "$anchor_toml" ]; then
43+
echo "Found anchor.toml at: $anchor_toml" >&2
44+
version=$(grep -i "^${key}_version *= *\".*\"" "$anchor_toml" | cut -d'"' -f2 || true)
45+
fi
46+
fi
47+
echo "$version"
48+
}
49+
50+
# Extract Solana version
1851
if [ -n "${{ github.event.inputs.solana_version }}" ]; then
1952
SOLANA_VERSION="${{ github.event.inputs.solana_version }}"
2053
echo "Using override Solana version: ${SOLANA_VERSION}"
2154
else
22-
SOLANA_VERSION=$(grep -A 2 'name = "solana-program"' Cargo.lock | grep 'version' | head -n 1 | cut -d'"' -f2)
23-
echo "Detected Solana version: ${SOLANA_VERSION}"
55+
# First try anchor.toml
56+
SOLANA_VERSION=$(extract_from_anchor_toml "solana")
57+
if [ -n "${SOLANA_VERSION}" ]; then
58+
echo "Detected Solana version from anchor.toml: ${SOLANA_VERSION}"
59+
else
60+
echo "No Solana version found in anchor.toml, checking Cargo.lock..."
61+
# Fallback to Cargo.lock
62+
if [ -f "Cargo.lock" ]; then
63+
SOLANA_VERSION=$(grep -A 2 'name = "solana-program"' Cargo.lock | grep 'version' | head -n 1 | cut -d'"' -f2 || true)
64+
if [ -n "${SOLANA_VERSION}" ]; then
65+
echo "Detected Solana version from Cargo.lock: ${SOLANA_VERSION}"
66+
else
67+
echo "⚠️ No Solana version found in Cargo.lock"
68+
fi
69+
else
70+
echo "⚠️ Cargo.lock not found"
71+
fi
72+
fi
2473
fi
25-
echo "solana_version=${SOLANA_VERSION}" >> $GITHUB_OUTPUT
26-
echo "SOLANA_VERSION=${SOLANA_VERSION}" >> $GITHUB_ENV
2774
28-
# Extract Anchor version from Cargo.lock or use override
75+
# Ensure clean version output
76+
if [ -n "${SOLANA_VERSION}" ]; then
77+
# Remove any newlines and ensure we only have the version
78+
SOLANA_VERSION=$(echo "${SOLANA_VERSION}" | tr -d '\n' | grep -o '[0-9]\+\.[0-9]\+\.[0-9]\+' || true)
79+
if [ -n "${SOLANA_VERSION}" ]; then
80+
echo "solana_version=${SOLANA_VERSION}" >> $GITHUB_OUTPUT
81+
echo "SOLANA_VERSION=${SOLANA_VERSION}" >> $GITHUB_ENV
82+
fi
83+
fi
84+
85+
# Extract Anchor version
2986
if [ -n "${{ github.event.inputs.anchor_version }}" ]; then
3087
ANCHOR_VERSION="${{ github.event.inputs.anchor_version }}"
3188
echo "Using override Anchor version: ${ANCHOR_VERSION}"
3289
else
33-
# Check if anchor-lang exists in Cargo.lock
34-
if grep -q 'name = "anchor-lang"' Cargo.lock; then
35-
ANCHOR_VERSION=$(grep -A 2 'name = "anchor-lang"' Cargo.lock | grep 'version' | head -n 1 | cut -d'"' -f2)
36-
echo "Detected Anchor version: ${ANCHOR_VERSION}"
90+
# First try anchor.toml
91+
ANCHOR_VERSION=$(extract_from_anchor_toml "anchor")
92+
if [ -n "${ANCHOR_VERSION}" ]; then
93+
echo "Detected Anchor version from anchor.toml: ${ANCHOR_VERSION}"
94+
else
95+
echo "No Anchor version found in anchor.toml, checking Cargo.lock..."
96+
# Fallback to Cargo.lock
97+
if [ -f "Cargo.lock" ]; then
98+
if grep -q 'name = "anchor-lang"' Cargo.lock; then
99+
ANCHOR_VERSION=$(grep -A 2 'name = "anchor-lang"' Cargo.lock | grep 'version' | head -n 1 | cut -d'"' -f2 || true)
100+
echo "Detected Anchor version from Cargo.lock: ${ANCHOR_VERSION}"
101+
else
102+
echo "⚠️ No Anchor version found in Cargo.lock"
103+
fi
104+
else
105+
echo "⚠️ Cargo.lock not found"
106+
fi
107+
fi
108+
fi
109+
110+
# Ensure clean version output
111+
if [ -n "${ANCHOR_VERSION}" ]; then
112+
# Remove any newlines and ensure we only have the version
113+
ANCHOR_VERSION=$(echo "${ANCHOR_VERSION}" | tr -d '\n' | grep -o '[0-9]\+\.[0-9]\+\.[0-9]\+' || true)
114+
if [ -n "${ANCHOR_VERSION}" ]; then
37115
echo "anchor_version=${ANCHOR_VERSION}" >> $GITHUB_OUTPUT
38116
echo "ANCHOR_VERSION=${ANCHOR_VERSION}" >> $GITHUB_ENV
39-
else
40-
echo "No Anchor version found in Cargo.lock"
41117
fi
42118
fi
43119
@@ -46,6 +122,6 @@ runs:
46122
echo "Content of GITHUB_ENV file:"
47123
cat $GITHUB_ENV
48124
echo "=== Direct Environment Variables ==="
49-
echo "SOLANA_VERSION: $SOLANA_VERSION"
125+
echo "SOLANA_VERSION: ${SOLANA_VERSION:-not found}"
50126
echo "ANCHOR_VERSION: ${ANCHOR_VERSION:-not found}"
51127
echo "==========================="

run-tests/action.yaml

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,14 @@ inputs:
44
program:
55
description: "Program to test"
66
required: true
7+
solana_version:
8+
description: "Solana version used for cache"
9+
required: true
10+
default: ""
11+
anchor_version:
12+
description: "Anchor version used for cache"
13+
required: true
14+
default: ""
715
features:
816
description: "Features that will be passed into the test"
917
required: false
@@ -15,7 +23,7 @@ runs:
1523
uses: actions/cache@v3
1624
with:
1725
path: ./node_modules/
18-
key: node-modules-${{ runner.os }}-build-v0.1
26+
key: node-modules-${{ runner.os }}-build-v0.1-${{ inputs.anchor_version }}-${{ inputs.solana_version }}
1927

2028
- name: Install Node.js dependencies
2129
shell: bash
@@ -30,7 +38,7 @@ runs:
3038
~/.cargo/git/db/
3139
target/
3240
test-ledger/
33-
shared-key: "anchor-test-${{ steps.versions.outputs.anchor_version }}-${{ steps.versions.outputs.solana_version }}"
41+
shared-key: "anchor-test-${{ inputs.anchor_version }}-${{ inputs.solana_version }}"
3442

3543
- name: Run Anchor Tests
3644
shell: bash

0 commit comments

Comments
 (0)