-
-
Notifications
You must be signed in to change notification settings - Fork 3.4k
121 lines (98 loc) · 4.25 KB
/
build-pr.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#
# build-pr.yml
# Build Marlin with the new / updated configs in the PR
#
name: PR Test Build
on:
pull_request:
branches:
- import-2.1.x
paths-ignore:
- '**/*.md'
jobs:
build:
name: Test Build
if: github.repository == 'MarlinFirmware/Configurations'
runs-on: ubuntu-latest
steps:
- name: Check out the PR
uses: actions/checkout@v4
# Get the list of directories containing changed config files:
- name: Get changed directories
run: |
# Get the base branch of the Pull Request
BASE_BRANCH=$(jq -r .pull_request.base.ref <$GITHUB_EVENT_PATH)
# Get origin for comparison
git fetch --depth=1 origin $BASE_BRANCH
# Use `git diff` to get a list of folders with altered .h files
# between the current commit and the base branch of the Pull Request
DIRS=$(git diff --name-only --diff-filter=AMR origin/$BASE_BRANCH HEAD | grep -E ".+\.h" | while IFS= read -r f; do dirname "$f"; done | uniq)
# Exit if nothing testable changed
[[ -z $DIRS ]] && { echo "No Configuration changes detected."; exit ; }
# Set DIRS in the persistent environment
echo -e "DIRS<<EOF\n$DIRS\nEOF" >>$GITHUB_ENV
- name: Cache pip
uses: actions/cache@v4
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
restore-keys: |
${{ runner.os }}-pip-
- name: Cache PlatformIO
uses: actions/cache@v4
with:
path: ~/.platformio
key: ${{ runner.os }}-${{ hashFiles('**/lockfiles') }}
- name: Select Python 3.9
uses: actions/setup-python@v5
with:
python-version: '3.9' # Version range or exact version of a Python version to use, using semvers version range syntax.
architecture: 'x64' # optional x64 or x86. Defaults to x64 if not specified
- name: Install PlatformIO
run: |
pip install -U platformio
pio upgrade --dev
pio pkg update --global
# Fetch the code from the other repo and compile it:
- name: Clone Marlin
run: |
git clone https://github.com/MarlinFirmware/Marlin.git
# For each directory containing a changed config file, copy the .h files and build the code:
- name: Test all changed config files
run: |
cd Marlin
IFS=$'\n'
for dir in $DIRS; do
# Copy all .h files from the directory into the Marlin subfolder
echo "Building Configurations in $dir ..."
cp ../"$dir"/*.h Marlin/
# Suppress fatal warnings
echo -e "\n#define NO_CONTROLLER_CUSTOM_WIRING_WARNING" >> Marlin/Configuration.h
# Strip out #error lines so it can build
sed -i~ -e "20,30{/#error/d}" "Marlin/Configuration.h"
rm -f "Marlin/Configuration.h~"
# Build Marlin with PlatformIO
MB=$( grep -E "^\s*#define MOTHERBOARD" Marlin/Configuration.h | awk '{ print $3 }' | sed 's/BOARD_//;s/\r//' )
[[ -z $MB ]] && { echo "::error::Can't read MOTHERBOARD setting." ; exit 3; }
BLINE=$( grep -E "define\s+BOARD_$MB\b" Marlin/src/core/boards.h )
BNUM=$( sed -E 's/^.+BOARD_[^ ]+ +([0-9]+)(.|$)+$/\1/' <<<"$BLINE" )
BDESC=$( sed -E 's/^.+\/\/ *(.+)$/\1/' <<<"$BLINE" )
[[ -z $BNUM ]] && { echo "::error::Can't find BOARD_$MB in core/boards.h." ; exit 3; }
if [ "$MB" == "SIMULATED" ]
then
ENVS=$"simulator_linux_release"
# Install Simulator dependencies
sudo apt-get install build-essential
sudo apt-get install libsdl2-dev
sudo apt-get install libsdl2-net-dev
sudo apt-get install libglm-dev
else
ENVS=( $( grep -EA1 "MB\(.*\b$MB\b.*\)" Marlin/src/pins/pins.h | grep -E "#include.+//.+env:[^ ]+" | grep -oE "env:[^ ]+" | sed -E "s/env://" ) )
fi
[[ -z $ENVS ]] && { echo "::error::Can't find target(s) for $MB ($BNUM)." ; exit 3; }
[[ ${#ENVS[*]} == 1 ]] && TARGET=$ENVS || TARGET="${ENVS[0]}"
echo "Building environment $TARGET for board $MB ($BNUM)..." ; echo
pio run -s -e $TARGET
# Reset the repo directory so the next iteration starts clean
git reset --hard HEAD
done