WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Commit 6676a01

Browse files
committed
Also test-compile modules that are disabled by default
made by Google Gemini 3, seems to work
1 parent f3b5f8e commit 6676a01

File tree

1 file changed

+129
-4
lines changed

1 file changed

+129
-4
lines changed

.github/workflows/ci.yml

Lines changed: 129 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,122 @@ name: CI
22

33
on:
44
push:
5-
65
pull_request:
76

87
env:
98
ARDUINO_LIBRARY_ENABLE_UNSAFE_INSTALL: false
109

1110
jobs:
11+
# JOB 1: Determine which cores need to be tested based on changed files
12+
setup:
13+
name: Calculate Matrix
14+
runs-on: ubuntu-latest
15+
outputs:
16+
cores: ${{ steps.set-matrix.outputs.cores }}
17+
steps:
18+
- name: Checkout
19+
uses: actions/checkout@v4
20+
with:
21+
fetch-depth: 0 # REQUIRED: 0 means "all history". Needed to compare commit ranges for push events.
22+
23+
- name: Determine Cores to Build
24+
id: set-matrix
25+
run: |
26+
# 1. Define lists
27+
# List of ALL available cores for detection
28+
ALL_CORES="ENABLE_2600 ENABLE_5200 ENABLE_7800 ENABLE_JAGUAR ENABLE_LYNX ENABLE_ATARI8 ENABLE_BALLY ENABLE_LJ ENABLE_LJPRO ENABLE_PCW ENABLE_PV1000 ENABLE_COLV ENABLE_C64 ENABLE_VIC20 ENABLE_ARC ENABLE_FAIRCHILD ENABLE_FLASH ENABLE_FLASH8 ENABLE_FLASH16 ENABLE_GBX ENABLE_INTV ENABLE_LEAP ENABLE_NGP ENABLE_N64 ENABLE_NES ENABLE_ODY2 ENABLE_MSX ENABLE_PCE ENABLE_POKE ENABLE_RCA ENABLE_SMS ENABLE_MD ENABLE_SFM ENABLE_SV ENABLE_ST ENABLE_GPC ENABLE_SNES ENABLE_TI99 ENABLE_PYUUTA ENABLE_TRS80 ENABLE_VECTREX ENABLE_VBOY ENABLE_VSMILE ENABLE_WSV ENABLE_WS ENABLE_SUPRACAN ENABLE_LOOPY ENABLE_CPS3"
29+
30+
# List of cores enabled by default in Config.h (Standard Build)
31+
DEFAULT_CORES_LIST="ENABLE_GBX ENABLE_N64 ENABLE_NES ENABLE_SMS ENABLE_MD ENABLE_SNES"
32+
33+
# 2. Get changed files (ROBUST METHOD)
34+
echo "Event: ${{ github.event_name }}"
35+
36+
if [ "${{ github.event_name }}" == "pull_request" ]; then
37+
# Compare the PR branch tip against the base branch (usually main/master)
38+
CHANGED_FILES=$(git diff --name-only origin/${{ github.base_ref }} HEAD)
39+
elif [ "${{ github.event_name }}" == "push" ]; then
40+
if [ "${{ github.event.before }}" == "0000000000000000000000000000000000000000" ]; then
41+
# New branch push: Compare HEAD against its parent (fallback)
42+
CHANGED_FILES=$(git diff --name-only HEAD^ HEAD)
43+
else
44+
# Standard push: Compare the 'before' SHA (previous state) with 'after' SHA (current state)
45+
CHANGED_FILES=$(git diff --name-only ${{ github.event.before }} ${{ github.event.after }})
46+
fi
47+
else
48+
# Manual triggers or other events: Fallback to last commit
49+
CHANGED_FILES=$(git diff --name-only HEAD^ HEAD)
50+
fi
51+
52+
echo "Changed files:"
53+
echo "$CHANGED_FILES"
54+
55+
# Temporary file to collect results
56+
touch cores_to_run.txt
57+
58+
# 3. Global File Check
59+
if echo "$CHANGED_FILES" | grep -q -E "Cart_Reader/Config.h|Cart_Reader/Cart_Reader.ino|Cart_Reader/OSCR.cpp|Cart_Reader/OSCR.h|Cart_Reader/ClockedSerial.cpp|Cart_Reader/ClockedSerial.h"; then
60+
echo "Global file changed. Adding ALL_DEFAULTS run."
61+
# Write to parent file because we might be inside Cart_Reader later
62+
echo "ALL_DEFAULTS" >> cores_to_run.txt
63+
fi
64+
65+
# 4. Module Logic: Check specific .ino files
66+
cd Cart_Reader
67+
68+
# Loop through all available cores
69+
for core in $ALL_CORES; do
70+
# Check every .ino file (except the main one) to see if it defines/uses this core
71+
for file in $(ls *.ino | grep -v "Cart_Reader.ino"); do
72+
73+
# Improved header check: first 10 lines
74+
if head -n 10 "$file" | grep -q "$core"; then
75+
76+
# We found the file for this core. Did it change?
77+
if echo "$CHANGED_FILES" | grep -q "Cart_Reader/$file"; then
78+
echo "File '$file' changed (matched $core). Adding to build list."
79+
echo "$core" >> ../cores_to_run.txt
80+
fi
81+
fi
82+
done
83+
done
84+
cd ..
85+
86+
# 5. OPTIMIZATION: Remove redundant default cores if ALL_DEFAULTS is present
87+
if grep -q "ALL_DEFAULTS" cores_to_run.txt; then
88+
echo "ALL_DEFAULTS detected. Removing redundant default cores from individual test list..."
89+
for def_core in $DEFAULT_CORES_LIST; do
90+
# Delete lines matching the default core exactly
91+
sed -i "/^$def_core$/d" cores_to_run.txt
92+
done
93+
fi
94+
95+
# 6. Output JSON for the matrix
96+
if [ -s cores_to_run.txt ]; then
97+
# Sort and remove duplicates
98+
UNIQUE_CORES=$(sort -u cores_to_run.txt)
99+
100+
# Convert list to JSON array ["CORE1","CORE2"]
101+
JSON_ARRAY=$(echo "$UNIQUE_CORES" | jq -R -s -c 'split("\n")[:-1]')
102+
103+
echo "Matrix to build: $JSON_ARRAY"
104+
echo "cores=$JSON_ARRAY" >> $GITHUB_OUTPUT
105+
else
106+
echo "No relevant changes found."
107+
echo "cores=[]" >> $GITHUB_OUTPUT
108+
fi
109+
110+
# JOB 2: Run the actual compilation using the dynamic matrix
12111
ci:
13-
name: ${{ matrix.hwVersion }}
112+
needs: setup
113+
# Skip if the cores list is empty
114+
if: ${{ needs.setup.outputs.cores != '[]' && needs.setup.outputs.cores != '' }}
115+
name: ${{ matrix.hwVersion }}-${{ matrix.core }}
14116
runs-on: ubuntu-latest
15117
strategy:
16118
matrix:
17-
hwVersion: [HW5, HW4, HW3, HW2, HW1]
119+
hwVersion: [HW3, HW5]
120+
core: ${{ fromJson(needs.setup.outputs.cores) }}
18121

19122
steps:
20123
- name: Install Arduino CLI
@@ -45,6 +148,28 @@ jobs:
45148
- name: Compile
46149
run: |
47150
cd Cart_Reader/
48-
# Select hardware version by uncommenting it (using regular expression)
151+
152+
# 1. Set Hardware Version (Always needed)
49153
sed -i 's/^\/\/[\t ]*#define ${{ matrix.hwVersion }}/#define ${{ matrix.hwVersion }}/g' Config.h
154+
155+
# 2. Configure Cores
156+
if [ "${{ matrix.core }}" == "ALL_DEFAULTS" ]; then
157+
echo "BUILD TYPE: ALL_DEFAULTS"
158+
echo "Keeping default Config.h (Enables: GBX, N64, NES, SMS, MD, SNES simultaneously)"
159+
# We do NOT comment out the default cores here.
160+
else
161+
echo "BUILD TYPE: SINGLE CORE (${{ matrix.core }})"
162+
163+
# Comment out all cores that are enabled by default
164+
sed -i 's/^#define ENABLE_GBX/\/\/#define ENABLE_GBX/g' Config.h
165+
sed -i 's/^#define ENABLE_N64/\/\/#define ENABLE_N64/g' Config.h
166+
sed -i 's/^#define ENABLE_NES/\/\/#define ENABLE_NES/g' Config.h
167+
sed -i 's/^#define ENABLE_SMS/\/\/#define ENABLE_SMS/g' Config.h
168+
sed -i 's/^#define ENABLE_MD/\/\/#define ENABLE_MD/g' Config.h
169+
sed -i 's/^#define ENABLE_SNES/\/\/#define ENABLE_SNES/g' Config.h
170+
171+
# Uncomment only the core being tested
172+
sed -i 's/^\/\/[\t ]*#define ${{ matrix.core }}/#define ${{ matrix.core }}/g' Config.h
173+
fi
174+
50175
arduino-cli compile --fqbn arduino:avr:mega --warnings all --build-property compiler.cpp.extra_flags="-DGITHUB_CI"

0 commit comments

Comments
 (0)