Skip to content

Commit 43178e6

Browse files
committed
Refactor GitHub Actions workflow to improve output capture and results parsing
1 parent c83777b commit 43178e6

File tree

1 file changed

+19
-9
lines changed

1 file changed

+19
-9
lines changed

.github/workflows/aoc-runner.yaml

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,38 +22,48 @@ jobs:
2222

2323
- name: Run solutions
2424
run: |
25-
IFS=$'\n' read -r -d '' -a results < <(go run main.go && printf '\0')
26-
echo "AOC_RESULT=${#results[@]}" >> $GITHUB_ENV
25+
# Capture output in a more reliable way
26+
output=$(go run main.go)
27+
echo "$output"
28+
29+
# Get the STARS value from the last line
30+
stars=$(echo "$output" | grep "STARS=" | cut -d'=' -f2)
31+
echo "AOC_RESULT=$stars" >> $GITHUB_ENV
32+
33+
# Store all results
2734
echo "RESULTS<<EOF" >> $GITHUB_ENV
28-
printf "%s\n" "${results[@]}" >> $GITHUB_ENV
35+
echo "$output" >> $GITHUB_ENV
2936
echo "EOF" >> $GITHUB_ENV
3037
3138
- name: Update README progress
3239
run: |
3340
progress=$(cat README.md)
3441
stars=${{ env.AOC_RESULT }}
35-
IFS=$'\n' read -r -d '' -a results <<< "${{ env.RESULTS }}"
42+
43+
# Fix the results array parsing
44+
readarray -t results < <(echo "${{ env.RESULTS }}" | grep "DAY")
3645
3746
# Create new progress table with results
3847
new_table="| Day | Results | Stars |\n|:---:|:-------:|:-----:|\n"
3948
current_day=1
40-
for ((i=0; i<${#results[@]}; i+=2)); do
41-
p1="${results[i]:-}"
42-
p2="${results[i+1]:-}"
49+
i=0
50+
while [ $i -lt ${#results[@]} ]; do
51+
p1=$(echo "${results[$i]}" | grep "DAY.*P1" | cut -d'=' -f2)
52+
p2=$(echo "${results[$((i+1))]}" | grep "DAY.*P2" | cut -d'=' -f2)
4353
4454
result_text=""
4555
star=""
4656
4757
if [ -n "$p1" ] && [ -n "$p2" ]; then
4858
result_text="P1: $p1, P2: $p2"
49-
star=" ⭐" # Only one star when both parts are done
59+
star=" ⭐"
5060
elif [ -n "$p1" ]; then
5161
result_text="P1: $p1"
52-
star="" # No star for partial completion
5362
fi
5463
5564
new_table+="| [Day $current_day](aoc24/day$current_day) | $result_text | $star |\n"
5665
((current_day++))
66+
((i+=2))
5767
done
5868
5969
# Fill remaining days

0 commit comments

Comments
 (0)