Skip to content

Commit e97057b

Browse files
committed
Merge branch 'ci/cron_optimization'
2 parents 6683a0d + 30e5c25 commit e97057b

File tree

5 files changed

+182
-100
lines changed

5 files changed

+182
-100
lines changed

.github/workflows/cron.yml

+166-98
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,128 @@
11
name: Cron Build
22

3-
on:
3+
on:
44
schedule:
55
# ┌───────────── minute (0 - 59)
66
# │ ┌───────────── hour (0 - 23)
77
# │ │ ┌───────────── day of the month (1 - 31)
88
# │ │ │ ┌───────────── month (1 - 12 or JAN-DEC)
99
# │ │ │ │ ┌───────────── day of the week (0 - 6 or SUN-SAT)
10-
# │ │ │ │ │
10+
# │ │ │ │ │
1111
# │ │ │ │ │
1212
# │ │ │ │ │
1313
# * * * * *
1414
- cron: '0 */6 * * *'
15+
workflow_dispatch:
16+
inputs:
17+
idf_branch:
18+
description: 'IDF branch to build (JSON list of strings e.g. ["release/v5.1"] or "all" to build all branches)'
19+
required: true
20+
default: 'all'
21+
target:
22+
description: 'Target to build (JSON list of strings e.g. ["esp32", "esp32s2"] or "all" to build all targets)'
23+
required: true
24+
default: 'all'
1525

1626
defaults:
1727
run:
1828
shell: bash
1929

2030
jobs:
21-
run:
22-
name: Build with IDF ${{ matrix.idf_branch }}
31+
gen-matrix:
32+
name: Generate matrix
2333
runs-on: ubuntu-latest
24-
34+
outputs:
35+
matrix: ${{ steps.gen-matrix.outputs.matrix }}
36+
branches: ${{ steps.gen-matrix.outputs.branches }}
37+
steps:
38+
- name: Generate matrix
39+
id: gen-matrix
40+
run: |
41+
apt update && apt install jq
42+
43+
# Change this based on the IDF branches we want to build
44+
all_branches="[\"release/v5.1\"]"
45+
46+
# Change this based on the COMMON targets for all branches we want to build.
47+
common_targets="[\"esp32\", \"esp32s2\", \"esp32s3\", \"esp32c2\", \"esp32c3\", \"esp32c6\", \"esp32h2\"]"
48+
49+
# For additional targets per branch, add them here
50+
additional_targets="[{\"idf_branch\": \"release/v5.3\", \"target\": \"esp32p4\"}]"
51+
52+
branches="${{ github.event.inputs.idf_branch }}"
53+
targets="${{ github.event.inputs.target }}"
54+
55+
if [ -z "$branches" ] || [ "$branches" == "all" ]; then
56+
branches=$all_branches
57+
fi
58+
59+
if [ -z "$targets" ]; then
60+
targets="all"
61+
fi
62+
63+
echo "Inputs:"
64+
echo "idf_branch: ${{ github.event.inputs.idf_branch }}"
65+
echo "target: ${{ github.event.inputs.target }}"
66+
67+
matrix="{"
68+
matrix+="\"idf_branch\": $branches,"
69+
70+
if [ "$targets" == "all" ]; then
71+
matrix+="\"target\": $common_targets,"
72+
matrix+="\"include\": "
73+
# Add all additional targets that are in the selected branches
74+
matrix+=$(echo $additional_targets | jq --argjson branches "$branches" '[.[] | select(.idf_branch as $branch | $branches | index($branch))]')
75+
else
76+
matrix+="\"target\": $targets"
77+
fi
78+
79+
matrix+="}"
80+
81+
echo "Branches: $branches"
82+
echo "Targets: $targets"
83+
echo "Matrix:"
84+
echo "$matrix" | jq .
85+
echo "matrix=$matrix" >> $GITHUB_OUTPUT
86+
echo "branches=$branches" >> $GITHUB_OUTPUT
87+
88+
check:
89+
name: Check if result should be deployed
90+
runs-on: ubuntu-latest
91+
needs: gen-matrix
2592
strategy:
26-
fail-fast: false
2793
matrix:
28-
idf_branch: [release/v5.1, release/v4.4] #, release/v3.3]
94+
idf_branch: ${{ fromJson(needs.gen-matrix.outputs.branches) }}
95+
outputs:
96+
idf_branch: ${{ steps.check.outputs.idf_branch }}
97+
idf_commit: ${{ steps.check.outputs.idf_commit }}
98+
ar_branch: ${{ steps.check.outputs.ar_branch }}
99+
ar_new_commit_message: ${{ steps.check.outputs.ar_new_commit_message }}
100+
ar_new_branch_name: ${{ steps.check.outputs.ar_new_branch_name }}
101+
ar_new_pr_title: ${{ steps.check.outputs.ar_new_pr_title }}
102+
ar_has_commit: ${{ steps.check.outputs.ar_has_commit }}
103+
ar_has_branch: ${{ steps.check.outputs.ar_has_branch }}
104+
ar_has_pr: ${{ steps.check.outputs.ar_has_pr }}
105+
libs_version: ${{ steps.check.outputs.libs_version }}
106+
libs_has_commit: ${{ steps.check.outputs.libs_has_commit }}
107+
libs_has_branch: ${{ steps.check.outputs.libs_has_branch }}
108+
steps:
109+
- uses: actions/checkout@v3
110+
- id: check
111+
env:
112+
GITHUB_TOKEN: ${{ secrets.PUSH_TOKEN }}
113+
GIT_AUTHOR_EMAIL: ${{ secrets.PUSH_EMAIL }}
114+
GIT_COMMITTER_EMAIL: ${{ secrets.PUSH_EMAIL }}
115+
IDF_BRANCH: ${{ matrix.idf_branch }}
116+
run: bash ./tools/check-deploy-needed.sh
117+
118+
build-libs:
119+
name: Build with IDF ${{ matrix.idf_branch }} for ${{ matrix.target }}
120+
runs-on: ubuntu-latest
121+
needs: [gen-matrix, check]
122+
if: needs.check.outputs.libs_has_commit == '0' || needs.check.outputs.ar_has_commit == '0'
123+
strategy:
124+
fail-fast: false
125+
matrix: ${{ fromJson(needs.gen-matrix.outputs.matrix) }}
29126
steps:
30127
- uses: actions/checkout@v4
31128
with:
@@ -38,107 +135,78 @@ jobs:
38135
GIT_AUTHOR_EMAIL: ${{ secrets.PUSH_EMAIL }}
39136
GIT_COMMITTER_EMAIL: ${{ secrets.PUSH_EMAIL }}
40137
IDF_BRANCH: ${{ matrix.idf_branch }}
138+
TARGETS: ${{ matrix.target }}
41139
run: |
42-
git checkout ${{ matrix.idf_branch }} || echo "Using master branch"
140+
git checkout ${{ env.IDF_BRANCH }} || echo "Using master branch"
43141
bash ./tools/cron.sh
142+
44143
- name: Upload build
45144
if: failure()
46145
uses: actions/upload-artifact@v4
47146
with:
48-
name: build
147+
name: build-${{ matrix.idf_branch }}-${{ matrix.target }}
49148
path: build
50-
- name: Upload archive
149+
150+
- name: Upload library files
51151
uses: actions/upload-artifact@v4
52152
with:
53-
name: artifacts
153+
name: libs-${{ matrix.idf_branch }}-${{ matrix.target }}
54154
path: dist
55155

156+
combine-artifacts:
157+
name: Combine artifacts for IDF ${{ matrix.idf_branch }}
158+
runs-on: ubuntu-latest
159+
needs: [gen-matrix, check, build-libs]
160+
if: needs.check.outputs.libs_has_commit == '0' || needs.check.outputs.ar_has_commit == '0'
161+
strategy:
162+
fail-fast: false
163+
matrix:
164+
idf_branch: ${{ fromJson(needs.gen-matrix.outputs.branches) }}
165+
steps:
166+
- name: Download artifacts
167+
uses: actions/download-artifact@v4
168+
with:
169+
path: dist
170+
pattern: libs-${{ matrix.idf_branch }}-*
171+
merge-multiple: true
172+
173+
- name: Combine artifacts
174+
shell: bash
175+
run: |
176+
set -e
177+
mkdir -p out
178+
find dist -name 'arduino-esp32-libs-esp*.tar.gz'
179+
for file in $files; do
180+
tar zxvf $file -C out
181+
cat out/tools/esp32-arduino-libs/versions.txt >> out/tools/esp32-arduino-libs/versions_full.txt
182+
done
183+
184+
# Merge versions.txt files
185+
awk -i inplace '!seen[$0]++' out/tools/esp32-arduino-libs/versions_full.txt
186+
mv -f out/tools/esp32-arduino-libs/versions_full.txt out/tools/esp32-arduino-libs/versions.txt
187+
188+
cd out/tools/esp32-arduino-libs && tar zcf ../../../dist/esp32-arduino-libs.tar.gz * && cd ../../..
189+
cp out/package_esp32_index.template.json dist/package_esp32_index.template.json
190+
191+
- name: Upload full esp32-arduino-libs archive
192+
uses: actions/upload-artifact@v4
193+
with:
194+
name: esp32-arduino-libs
195+
path: dist/esp32-arduino-libs.tar.gz
56196

57-
# check:
58-
# name: Check if result should be deployed
59-
# runs-on: ubuntu-latest
60-
# strategy:
61-
# matrix:
62-
# branch: [release/v5.1, release/v4.4] #, release/v3.3]
63-
# outputs:
64-
# idf_branch: ${{ steps.check.outputs.idf_branch }}
65-
# idf_commit: ${{ steps.check.outputs.idf_commit }}
66-
# ar_branch: ${{ steps.check.outputs.ar_branch }}
67-
# ar_new_commit_message: ${{ steps.check.outputs.ar_new_commit_message }}
68-
# ar_new_branch_name: ${{ steps.check.outputs.ar_new_branch_name }}
69-
# ar_new_pr_title: ${{ steps.check.outputs.ar_new_pr_title }}
70-
# ar_has_commit: ${{ steps.check.outputs.ar_has_commit }}
71-
# ar_has_branch: ${{ steps.check.outputs.ar_has_branch }}
72-
# ar_has_pr: ${{ steps.check.outputs.ar_has_pr }}
73-
# libs_version: ${{ steps.check.outputs.libs_version }}
74-
# libs_has_commit: ${{ steps.check.outputs.libs_has_commit }}
75-
# libs_has_branch: ${{ steps.check.outputs.libs_has_branch }}
76-
# steps:
77-
# - uses: actions/checkout@v3
78-
# - id: check
79-
# env:
80-
# GITHUB_TOKEN: ${{ secrets.PUSH_TOKEN }}
81-
# GIT_AUTHOR_EMAIL: ${{ secrets.PUSH_EMAIL }}
82-
# GIT_COMMITTER_EMAIL: ${{ secrets.PUSH_EMAIL }}
83-
# IDF_BRANCH: ${{ matrix.idf_branch }}
84-
# run: bash ./tools/check-deploy-needed.sh
85-
86-
# build:
87-
# name: Build Libs for ${{ matrix.target }}
88-
# runs-on: ubuntu-latest
89-
# needs: check
90-
# if: needs.check.outputs.libs_has_commit == '0' || needs.check.outputs.ar_has_commit == '0'
91-
# strategy:
92-
# matrix:
93-
# target: [esp32, esp32s2, esp32s3, esp32c3, esp32c6, esp32h2]
94-
# fail-fast: false
95-
# steps:
96-
# - uses: actions/checkout@v3
97-
# # - name: Install dependencies
98-
# # run: bash ./tools/prepare-ci.sh
99-
# - shell: bash
100-
# name: Build Libs for ${{ matrix.target }}
101-
# run: echo ${{ matrix.target }}
102-
# # run: bash ./build.sh -t ${{ matrix.target }}
103-
# # - name: Upload archive
104-
# # uses: actions/upload-artifact@v3
105-
# # with:
106-
# # name: artifacts
107-
# # path: dist
108-
109-
# deploy:
110-
# name: Deploy build
111-
# runs-on: ubuntu-latest
112-
# needs: [check, build]
113-
# steps:
114-
# - uses: actions/checkout@v3
115-
# - shell: bash
116-
# env:
117-
# GITHUB_TOKEN: ${{ secrets.PUSH_TOKEN }}
118-
# GIT_AUTHOR_EMAIL: ${{ secrets.PUSH_EMAIL }}
119-
# GIT_COMMITTER_EMAIL: ${{ secrets.PUSH_EMAIL }}
120-
# IDF_BRANCH: ${{ needs.check.outputs.idf_branch }}
121-
# IDF_COMMIT: ${{ needs.check.outputs.idf_commit }}
122-
# AR_BRANCH: ${{ needs.check.outputs.ar_branch }}
123-
# AR_NEW_COMMIT_MESSAGE: ${{ needs.check.outputs.ar_new_commit_message }}
124-
# AR_NEW_BRANCH_NAME: ${{ needs.check.outputs.ar_new_branch_name }}
125-
# AR_NEW_PR_TITLE: ${{ needs.check.outputs.ar_new_pr_title }}
126-
# AR_HAS_COMMIT: ${{ needs.check.outputs.ar_has_commit }}
127-
# AR_HAS_BRANCH: ${{ needs.check.outputs.ar_has_branch }}
128-
# AR_HAS_PR: ${{ needs.check.outputs.ar_has_pr }}
129-
# LIBS_VERSION: ${{ needs.check.outputs.libs_version }}
130-
# LIBS_HAS_COMMIT: ${{ needs.check.outputs.libs_has_commit }}
131-
# LIBS_HAS_BRANCH: ${{ needs.check.outputs.libs_has_branch }}
132-
# run: |
133-
# echo "IDF_COMMIT: $IDF_COMMIT"
134-
# echo "AR_BRANCH: $AR_BRANCH"
135-
# echo "AR_NEW_COMMIT_MESSAGE: $AR_NEW_COMMIT_MESSAGE"
136-
# echo "AR_NEW_BRANCH_NAME: $AR_NEW_BRANCH_NAME"
137-
# echo "AR_NEW_PR_TITLE: $AR_NEW_PR_TITLE"
138-
# echo "AR_HAS_COMMIT: $AR_HAS_COMMIT"
139-
# echo "AR_HAS_BRANCH: $AR_HAS_BRANCH"
140-
# echo "AR_HAS_PR: $AR_HAS_PR"
141-
# echo "LIBS_VERSION: $LIBS_VERSION"
142-
# echo "LIBS_HAS_COMMIT: $LIBS_HAS_COMMIT"
143-
# echo "LIBS_HAS_BRANCH: $LIBS_HAS_BRANCH"
197+
- name: Upload package_esp32_index.template.json
198+
uses: actions/upload-artifact@v4
199+
with:
200+
name: package-esp32-index-json
201+
path: dist/package_esp32_index.template.json
144202

203+
- name: Push changes
204+
if: ${{ github.repository == 'espressif/esp32-arduino-lib-builder' }}
205+
env:
206+
GITHUB_TOKEN: ${{ secrets.PUSH_TOKEN }}
207+
GIT_AUTHOR_EMAIL: ${{ secrets.PUSH_EMAIL }}
208+
GIT_COMMITTER_EMAIL: ${{ secrets.PUSH_EMAIL }}
209+
IDF_BRANCH: ${{ matrix.idf_branch }}
210+
run: |
211+
./tools/push-to-arduino.sh
212+
if [ $? -ne 0 ]; then exit 1; fi

build.sh

+5
Original file line numberDiff line numberDiff line change
@@ -299,13 +299,15 @@ done
299299

300300
# update package_esp32_index.template.json
301301
if [ "$BUILD_TYPE" = "all" ]; then
302+
echo "* Generating package_esp32_index.template.json..."
302303
python3 ./tools/gen_tools_json.py -i "$IDF_PATH" -j "$AR_COMPS/arduino/package/package_esp32_index.template.json" -o "$AR_OUT/"
303304
python3 ./tools/gen_tools_json.py -i "$IDF_PATH" -o "$TOOLS_JSON_OUT/"
304305
if [ $? -ne 0 ]; then exit 1; fi
305306
fi
306307

307308
# Generate PlatformIO manifest file
308309
if [ "$BUILD_TYPE" = "all" ]; then
310+
echo "* Generating PlatformIO manifest file..."
309311
pushd $IDF_PATH
310312
ibr=$(git describe --all 2>/dev/null)
311313
ic=$(git -C "$IDF_PATH" rev-parse --short HEAD)
@@ -316,18 +318,21 @@ fi
316318

317319
# copy everything to arduino-esp32 installation
318320
if [ $COPY_OUT -eq 1 ] && [ -d "$ESP32_ARDUINO" ]; then
321+
echo "* Copying to Arduino..."
319322
./tools/copy-to-arduino.sh
320323
if [ $? -ne 0 ]; then exit 1; fi
321324
fi
322325

323326
# push changes to esp32-arduino-libs and create pull request into arduino-esp32
324327
if [ $DEPLOY_OUT -eq 1 ]; then
328+
echo "* Pushing to Arduino..."
325329
./tools/push-to-arduino.sh
326330
if [ $? -ne 0 ]; then exit 1; fi
327331
fi
328332

329333
# archive the build
330334
if [ $ARCHIVE_OUT -eq 1 ]; then
335+
echo "* Archiving build..."
331336
./tools/archive-build.sh "$TARGET"
332337
if [ $? -ne 0 ]; then exit 1; fi
333338
fi

tools/check-deploy-needed.sh

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

3+
if [ "$GITHUB_EVENT_NAME" != "schedule" ] && [ "$GITHUB_EVENT_NAME" != "workflow_dispatch" ] && [ "$GITHUB_EVENT_NAME" != "repository_dispatch" -o "$GITHUB_EVENT_ACTION" != "deploy" ]; then
4+
echo "Wrong event '$GITHUB_EVENT_NAME'!"
5+
exit 1
6+
fi
7+
38
source ./tools/config.sh
49

510
IDF_COMMIT=`github_last_commit "$IDF_REPO" "$IDF_BRANCH"`

tools/cron.sh

+5-1
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,8 @@ if [ ! "$GITHUB_EVENT_NAME" == "schedule" ]; then
55
exit 1
66
fi
77

8-
bash ./build.sh -d
8+
if [ -z "$TARGETS" ]; then
9+
TARGETS="all"
10+
fi
11+
12+
bash ./build.sh -e -t $TARGETS

tools/install-esp-idf.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ source $IDF_PATH/export.sh
5151
# SETUP ARDUINO DEPLOY
5252
#
5353

54-
if [ "$GITHUB_EVENT_NAME" == "schedule" ] || [ "$GITHUB_EVENT_NAME" == "repository_dispatch" -a "$GITHUB_EVENT_ACTION" == "deploy" ]; then
54+
if [ "$GITHUB_EVENT_NAME" == "schedule" ] || [ "$GITHUB_EVENT_NAME" == "workflow_dispatch" ] || [ "$GITHUB_EVENT_NAME" == "repository_dispatch" -a "$GITHUB_EVENT_ACTION" == "deploy" ]; then
5555
# format new branch name and pr title
5656
if [ -x $commit_predefined ]; then #commit was not specified at build time
5757
AR_NEW_BRANCH_NAME="idf-$IDF_BRANCH"

0 commit comments

Comments
 (0)