Skip to content

Commit 0e10fad

Browse files
committed
Build system overhaul
1 parent 7dbfa98 commit 0e10fad

11 files changed

+321
-24
lines changed

.github/workflows/cron.yml

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
name: Cron Build
2+
3+
on:
4+
schedule:
5+
# ┌───────────── minute (0 - 59)
6+
# │ ┌───────────── hour (0 - 23)
7+
# │ │ ┌───────────── day of the month (1 - 31)
8+
# │ │ │ ┌───────────── month (1 - 12 or JAN-DEC)
9+
# │ │ │ │ ┌───────────── day of the week (0 - 6 or SUN-SAT)
10+
# │ │ │ │ │
11+
# │ │ │ │ │
12+
# │ │ │ │ │
13+
# * * * * *
14+
- cron: '0 */6 * * *'
15+
16+
jobs:
17+
run:
18+
name: Build with IDF ${{ matrix.idf_branch }}
19+
runs-on: ubuntu-latest
20+
21+
strategy:
22+
matrix:
23+
idf_branch: [release/v3.2]
24+
steps:
25+
- uses: actions/checkout@v1
26+
- name: Install dependencies
27+
run: sudo apt-get install git wget curl libssl-dev libncurses-dev flex bison gperf python python-pip python-setuptools python-serial python-click python-cryptography python-future python-pyparsing python-pyelftools cmake ninja-build ccache
28+
- name: Install Python Wheel
29+
run: pip install wheel
30+
- name: Build
31+
env:
32+
GITHUB_TOKEN: ${{ secrets.PUSH_TOKEN }}
33+
IDF_BRANCH: ${{ matrix.idf_branch }}
34+
run: bash ./tools/cron.sh
35+
# - name: Upload archive
36+
# uses: actions/upload-artifact@v1
37+
# with:
38+
# name: arduino-libs
39+
# path: dist

.github/workflows/main.yml renamed to .github/workflows/push.yml

+2-5
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ on:
66
- master
77
- release/*
88
pull_request:
9-
repository_dispatch:
109

1110
jobs:
1211

@@ -20,10 +19,8 @@ jobs:
2019
- name: Install Python Wheel
2120
run: pip install wheel
2221
- name: Build Arduino Libs
23-
env:
24-
TRAVIS_BUILD_DIR: ${{ github.workspace }}
25-
run: bash $TRAVIS_BUILD_DIR/build.sh
26-
- name: Archive libs
22+
run: bash ./build.sh
23+
- name: Upload archive
2724
uses: actions/upload-artifact@v1
2825
with:
2926
name: arduino-libs
+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
name: Remote Trigger
2+
3+
on: repository_dispatch
4+
5+
jobs:
6+
run:
7+
name: Dispatch Event
8+
runs-on: ubuntu-latest
9+
10+
steps:
11+
- uses: actions/checkout@v1
12+
- name: Install dependencies
13+
run: sudo apt-get install git wget curl libssl-dev libncurses-dev flex bison gperf python python-pip python-setuptools python-serial python-click python-cryptography python-future python-pyparsing python-pyelftools cmake ninja-build ccache
14+
- name: Install Python Wheel
15+
run: pip install wheel
16+
- name: Handle Event
17+
env:
18+
GITHUB_TOKEN: ${{ secrets.PUSH_TOKEN }}
19+
run: bash ./tools/repository_dispatch.sh

build.sh

+4-4
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,14 @@ if ! [ -x "$(command -v stat)" ]; then
3535
exit 1
3636
fi
3737

38-
# install esp-idf and gcc toolchain
39-
source ./tools/install-esp-idf.sh
40-
if [ $? -ne 0 ]; then exit 1; fi
41-
4238
# update components from git
4339
./tools/update-components.sh
4440
if [ $? -ne 0 ]; then exit 1; fi
4541

42+
# install esp-idf and gcc toolchain
43+
source ./tools/install-esp-idf.sh
44+
if [ $? -ne 0 ]; then exit 1; fi
45+
4646
# build and prepare libs
4747
./tools/build-libs.sh
4848
if [ $? -ne 0 ]; then exit 1; fi

tools/archive-build.sh

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
#!/bin/bash
22

3+
IDF_COMMIT=$(git -C $IDF_PATH rev-parse --short HEAD)
4+
IDF_BRANCH=$(git -C $IDF_PATH symbolic-ref --short HEAD)
5+
36
idf_version_string=${IDF_BRANCH//\//_}"-$IDF_COMMIT"
47
archive_path="dist/arduino-esp32-libs-$idf_version_string.tar.gz"
58

tools/config.sh

+54-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#!/bin/bash
2-
IDF_REPO="https://github.com/espressif/esp-idf.git"
3-
IDF_BRANCH="release/v3.2"
2+
43
IDF_COMPS="$IDF_PATH/components"
54
IDF_TOOLCHAIN="xtensa-esp32-elf"
65
IDF_TOOLCHAIN_LINUX_ARMEL="https://dl.espressif.com/dl/xtensa-esp32-elf-linux-armel-1.22.0-87-gb57bad3-5.2.0.tar.gz"
@@ -9,10 +8,25 @@ IDF_TOOLCHAIN_LINUX64="https://dl.espressif.com/dl/xtensa-esp32-elf-linux64-1.22
98
IDF_TOOLCHAIN_WIN32="https://dl.espressif.com/dl/xtensa-esp32-elf-win32-1.22.0-80-g6c4433a-5.2.0.zip"
109
IDF_TOOLCHAIN_MACOS="https://dl.espressif.com/dl/xtensa-esp32-elf-osx-1.22.0-80-g6c4433a-5.2.0.tar.gz"
1110

12-
CAMERA_REPO="https://github.com/espressif/esp32-camera.git"
13-
FACE_REPO="https://github.com/espressif/esp-face.git"
11+
if [ -z $IDF_BRANCH ]; then
12+
IDF_BRANCH="release/v3.2"
13+
fi
14+
15+
# Owner of the target ESP32 Arduino repository
16+
AR_USER="me-no-dev"
17+
18+
# The full name of the repository
19+
AR_REPO="$AR_USER/arduino-esp32"
20+
21+
IDF_REPO_URL="https://github.com/espressif/esp-idf.git"
22+
CAMERA_REPO_URL="https://github.com/espressif/esp32-camera.git"
23+
FACE_REPO_URL="https://github.com/espressif/esp-face.git"
24+
AR_REPO_URL="https://github.com/$AR_REPO.git"
25+
26+
if [ -n $GITHUB_TOKEN ]; then
27+
AR_REPO_URL="https://$GITHUB_TOKEN@github.com/$AR_REPO.git"
28+
fi
1429

15-
AR_REPO="https://github.com/espressif/arduino-esp32.git"
1630
AR_ROOT="$PWD"
1731
AR_COMPS="$AR_ROOT/components"
1832
AR_OUT="$AR_ROOT/out"
@@ -56,3 +70,38 @@ if [[ "$AR_OS" == "macos" ]]; then
5670
export SED="gsed"
5771
export SSTAT="stat -f %z"
5872
fi
73+
74+
function git_commit_exists(){ #git_commit_exists <repo-path> <commit-message>
75+
local repo_path="$1"
76+
local commit_message="$2"
77+
local commits_found=`git -C "$repo_path" log --all --grep="$commit_message" | grep commit`
78+
if [ -n "$commits_found" ]; then echo 1; else echo 0; fi
79+
}
80+
81+
function git_branch_exists(){ # git_branch_exists <repo-path> <branch-name>
82+
local repo_path="$1"
83+
local branch_name="$2"
84+
local branch_found=`git -C "$repo_path" ls-remote --heads origin "$branch_name"`
85+
if [ -n "$branch_found" ]; then echo 1; else echo 0; fi
86+
}
87+
88+
function git_pr_exists(){ # git_pr_exists <branch-name>
89+
local pr_num=`curl -s -k -H "Authorization: token $GITHUB_TOKEN" -H "Accept: application/vnd.github.v3.raw+json" "https://api.github.com/repos/$AR_REPO/pulls?head=$AR_USER:$1&state=open" | jq -r '.[].number'`
90+
if [ ! "$pr_num" == "" ] && [ ! "$pr_num" == "null" ]; then echo 1; else echo 0; fi
91+
}
92+
93+
function git_create_pr(){ # git_create_pr <branch> <title>
94+
local pr_branch="$1"
95+
local pr_title="$2"
96+
local pr_body=""
97+
for component in `ls "$AR_COMPS"`; do
98+
if [ ! $component == "arduino" ] && [ -d "$AR_COMPS/$component/.git" ]; then
99+
pr_body+="$component: "$(git -C "$AR_COMPS/$component" symbolic-ref --short HEAD)" "$(git -C "$AR_COMPS/$component" rev-parse --short HEAD)"\r\n"
100+
fi
101+
done
102+
local pr_data="{\"title\": \"$pr_title\", \"body\": \"$pr_body\", \"head\": \"$AR_USER:$pr_branch\", \"base\": \"master\"}"
103+
git_create_pr_res=`echo "$pr_data" | curl -k -H "Authorization: token $GITHUB_TOKEN" -H "Accept: application/vnd.github.v3.raw+json" --data @- "https://api.github.com/repos/$AR_REPO/pulls"`
104+
local done_pr=`echo "$git_create_pr_res" | jq -r '.title'`
105+
if [ ! "$done_pr" == "" ] && [ ! "$done_pr" == "null" ]; then echo 1; else echo 0; fi
106+
}
107+

tools/cron.sh

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/bin/bash
2+
3+
if [ ! $GITHUB_EVENT_NAME == "schedule" ]; then
4+
echo "Wrong event '$GITHUB_EVENT_NAME'!"
5+
exit 1
6+
fi
7+
8+
echo "Event: $GITHUB_EVENT_NAME, Repo: $GITHUB_REPOSITORY, Path: $GITHUB_WORKSPACE, Ref: $GITHUB_REF"
9+
10+
git checkout "$IDF_BRANCH" #local branches should match what the matrix wants to build
11+
12+
source ./build.sh
13+
14+
bash ./tools/push-to-arduino.sh
15+
#bash ./tools/archive-build.sh

tools/install-esp-idf.sh

+49-7
Original file line numberDiff line numberDiff line change
@@ -9,25 +9,67 @@ fi
99

1010
if [ -z "$IDF_PATH" ]; then
1111
echo "ESP-IDF is not installed! Installing local copy"
12+
idf_was_installed="1"
1213
if ! [ -d esp-idf ]; then
13-
git clone $IDF_REPO -b $IDF_BRANCH
14+
git clone $IDF_REPO_URL -b $IDF_BRANCH
1415
fi
1516
export IDF_PATH="$AR_ROOT/esp-idf"
16-
cd $IDF_PATH
17-
git fetch origin && git pull origin $IDF_BRANCH
18-
git submodule update --init --recursive
19-
python -m pip install -r requirements.txt
20-
cd "$AR_ROOT"
2117
fi
2218

2319
if [ "$IDF_COMMIT" ]; then
2420
git -C $IDF_PATH checkout $IDF_COMMIT
25-
git -C $IDF_PATH submodule update
21+
commit_predefined="1"
2622
fi
2723

2824
export IDF_COMMIT=$(git -C $IDF_PATH rev-parse --short HEAD)
2925
export IDF_BRANCH=$(git -C $IDF_PATH symbolic-ref --short HEAD)
3026

27+
if [ "$GITHUB_EVENT_NAME" == "schedule" ] || [ "$GITHUB_EVENT_NAME" == "repository_dispatch" -a "$GITHUB_EVENT_ACTION" == "deploy" ]; then
28+
# format new branch name and pr title
29+
if [ -x $commit_predefined ]; then #commit was not specified at build time
30+
AR_NEW_BRANCH_NAME="idf-$IDF_BRANCH"
31+
AR_NEW_COMMIT_MESSAGE="IDF $IDF_BRANCH $IDF_COMMIT"
32+
AR_NEW_PR_TITLE="IDF $IDF_BRANCH"
33+
else
34+
AR_NEW_BRANCH_NAME="idf-$IDF_COMMIT"
35+
AR_NEW_COMMIT_MESSAGE="IDF $IDF_COMMIT"
36+
AR_NEW_PR_TITLE="$AR_NEW_COMMIT_MESSAGE"
37+
fi
38+
39+
AR_HAS_COMMIT=`git_commit_exists "$AR_COMPS/arduino" "$AR_NEW_COMMIT_MESSAGE"`
40+
AR_HAS_BRANCH=`git_branch_exists "$AR_COMPS/arduino" "$AR_NEW_BRANCH_NAME"`
41+
AR_HAS_PR=`git_pr_exists "$AR_NEW_BRANCH_NAME"`
42+
43+
if [ "$AR_HAS_COMMIT" == "1" ]; then
44+
echo "Commit '$AR_NEW_COMMIT_MESSAGE' Already Exists"
45+
exit 0
46+
fi
47+
48+
if [ "$AR_HAS_BRANCH" == "1" ]; then
49+
echo "Branch '$AR_NEW_BRANCH_NAME' Already Exists"
50+
fi
51+
52+
if [ "$AR_HAS_PR" == "1" ]; then
53+
echo "PR '$AR_NEW_PR_TITLE' Already Exists"
54+
fi
55+
56+
export AR_NEW_BRANCH_NAME
57+
export AR_NEW_COMMIT_MESSAGE
58+
export AR_NEW_PR_TITLE
59+
60+
export AR_HAS_COMMIT
61+
export AR_HAS_BRANCH
62+
export AR_HAS_PR
63+
fi
64+
65+
if [ -x $idf_was_installed ]; then
66+
git -C $IDF_PATH fetch origin && git -C $IDF_PATH pull origin $IDF_BRANCH
67+
git -C $IDF_PATH submodule update --init --recursive
68+
else
69+
git -C $IDF_PATH submodule update --init --recursive
70+
cd $IDF_PATH && python -m pip install -r requirements.txt && cd "$AR_ROOT"
71+
fi
72+
3173
if ! [ -x "$(command -v $IDF_TOOLCHAIN-gcc)" ]; then
3274
echo "GCC toolchain is not installed! Installing local copy"
3375

tools/push-to-arduino.sh

+92
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
#!/bin/bash
2+
source ./tools/config.sh
3+
4+
if [ -x $GITHUB_TOKEN ]; then
5+
echo "ERROR: GITHUB_TOKEN was not defined"
6+
exit 1
7+
fi
8+
9+
if ! [ -d "$AR_COMPS/arduino" ]; then
10+
echo "ERROR: Target arduino folder does not exist!"
11+
exit 1
12+
fi
13+
14+
# # format new branch name and pr title
15+
# if [ -x $1 ]; then #commit was not specified at build time
16+
# AR_NEW_BRANCH_NAME="idf-$IDF_BRANCH"
17+
# AR_NEW_COMMIT_MESSAGE="IDF $IDF_BRANCH $IDF_COMMIT"
18+
# AR_NEW_PR_TITLE="IDF $IDF_BRANCH"
19+
# else
20+
# AR_NEW_BRANCH_NAME="idf-$IDF_COMMIT"
21+
# AR_NEW_COMMIT_MESSAGE="IDF $IDF_COMMIT"
22+
# AR_NEW_PR_TITLE="$AR_NEW_COMMIT_MESSAGE"
23+
# fi
24+
25+
# AR_HAS_COMMIT=`git_commit_exists "$AR_COMPS/arduino" "$AR_NEW_COMMIT_MESSAGE"`
26+
# AR_HAS_BRANCH=`git_branch_exists "$AR_COMPS/arduino" "$AR_NEW_BRANCH_NAME"`
27+
# AR_HAS_PR=`git_pr_exists "$AR_NEW_BRANCH_NAME"`
28+
29+
#
30+
# CREATE/UPDATE BRANCH
31+
#
32+
33+
if [ $AR_HAS_COMMIT == "0" ]; then
34+
cd $AR_COMPS/arduino
35+
36+
# setup git for pushing
37+
git config --global github.user "$GITHUB_ACTOR"
38+
git config --global user.name "$GITHUB_ACTOR"
39+
git config --global user.email "$GITHUB_ACTOR@github.com"
40+
41+
# create or checkout the branch
42+
if [ ! $AR_HAS_BRANCH == "0" ]; then
43+
echo "Switching to branch '$AR_NEW_BRANCH_NAME'..."
44+
git checkout $AR_NEW_BRANCH_NAME
45+
else
46+
echo "Creating branch '$AR_NEW_BRANCH_NAME'..."
47+
git checkout -b $AR_NEW_BRANCH_NAME
48+
fi
49+
if [ $? -ne 0 ]; then
50+
echo "ERROR: Checkour of branch '$AR_NEW_BRANCH_NAME' failed"
51+
exit 1
52+
fi
53+
54+
# make changes to the files
55+
echo "Patching files in branch '$AR_NEW_BRANCH_NAME'..."
56+
rm -rf $AR_COMPS/arduino/tools/sdk
57+
cp -Rf $AR_SDK $AR_COMPS/arduino/tools/sdk
58+
cp -f $AR_ESPTOOL_PY $AR_COMPS/arduino/tools/esptool.py
59+
cp -f $AR_GEN_PART_PY $AR_COMPS/arduino/tools/gen_esp32part.py
60+
cp -f $AR_PLATFORMIO_PY $AR_COMPS/arduino/tools/platformio-build.py
61+
cp -f $AR_PLATFORM_TXT $AR_COMPS/arduino/platform.txt
62+
63+
# did any of the files change?
64+
if [ -n "$(git status --porcelain)" ]; then
65+
echo "Pushing changes to branch '$AR_NEW_BRANCH_NAME'..."
66+
git add . && git commit --message "$AR_NEW_COMMIT_MESSAGE" && git push -u origin $AR_NEW_BRANCH_NAME
67+
if [ $? -ne 0 ]; then
68+
echo "ERROR: Pushing to branch '$AR_NEW_BRANCH_NAME' failed"
69+
exit 1
70+
fi
71+
else
72+
echo "No changes in branch '$AR_NEW_BRANCH_NAME'"
73+
if [ $AR_HAS_BRANCH == "0" ]; then
74+
echo "Delete created branch '$AR_NEW_BRANCH_NAME'"
75+
git branch -d $AR_NEW_BRANCH_NAME
76+
fi
77+
exit 0
78+
fi
79+
fi
80+
81+
#
82+
# CREATE PULL REQUEST
83+
#
84+
85+
if [ "$AR_HAS_PR" == "0" ]; then
86+
pr_created=`git_create_pr "$AR_NEW_BRANCH_NAME" "$AR_NEW_PR_TITLE"`
87+
if [ $pr_created == "0" ]; then
88+
echo "ERROR: Failed to create PR '$AR_NEW_PR_TITLE': "`echo "$git_create_pr_res" | jq -r '.message'`": "`echo "$git_create_pr_res" | jq -r '.errors[].message'`
89+
exit 1
90+
fi
91+
fi
92+
exit 0

0 commit comments

Comments
 (0)