Skip to content

Commit 439df1d

Browse files
committed
Merge branch 'ci/cron_optimization'
2 parents b662e2d + 4bef12c commit 439df1d

File tree

5 files changed

+192
-165
lines changed

5 files changed

+192
-165
lines changed

.github/workflows/cron.yml

+157-100
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
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
# * * * * *
@@ -17,128 +17,185 @@ defaults:
1717
run:
1818
shell: bash
1919

20+
env:
21+
LATEST_RELEASE_BRANCH: "release/v5.1" # Change this to the latest release branch so the checkouts are done correctly
22+
2023
jobs:
21-
run:
22-
name: Build with IDF ${{ matrix.idf_branch }}
24+
gen-matrix:
25+
name: Generate matrix
2326
runs-on: ubuntu-latest
24-
27+
outputs:
28+
matrix: ${{ steps.gen-matrix.outputs.matrix }}
29+
branches: ${{ steps.gen-matrix.outputs.branches }}
30+
steps:
31+
- uses: actions/checkout@v4
32+
with:
33+
fetch-depth: 0
34+
35+
- name: Generate matrix
36+
id: gen-matrix
37+
run: |
38+
set -e
39+
40+
# Change this based on the IDF branches we want to build. Don't forget to update env.LATEST_RELEASE_BRANCH
41+
all_branches=("release/v5.1")
42+
43+
# Change this based on the COMMON targets for all branches we want to build.
44+
common_targets="[\"esp32\", \"esp32s2\", \"esp32s3\", \"esp32c2\", \"esp32c3\", \"esp32c6\", \"esp32h2\"]"
45+
46+
# For additional targets per branch, add them here
47+
additional_targets="[{\"idf_branch\": \"release/v5.3\", \"target\": \"esp32p4\"}]"
48+
49+
branches="["
50+
matrix="{"
51+
52+
for branch in ${all_branches[@]}; do
53+
if [ "$branch" == "$LATEST_RELEASE_BRANCH" ]; then
54+
git checkout master
55+
else
56+
git checkout $branch
57+
fi
58+
export IDF_BRANCH=$branch
59+
./tools/check-deploy-needed.sh
60+
if [ "$DEPLOY_NEEDED" == "1" ]; then
61+
branches+="\"$branch\","
62+
fi
63+
done
64+
65+
branches="${branches%,}]"
66+
matrix+="\"idf_branch\": $branches,"
67+
matrix+="\"target\": $common_targets,"
68+
69+
matrix+="\"include\": "
70+
# Add all additional targets that are in the selected branches
71+
matrix+=$(echo $additional_targets | jq --argjson branches "$branches" '[.[] | select(.idf_branch as $branch | $branches | index($branch))]')
72+
73+
matrix+="}"
74+
75+
echo "Branches: $branches"
76+
77+
echo "Matrix:"
78+
echo "$matrix" | jq .
79+
80+
if [ ! -x $GITHUB_OUTPUT ]; then
81+
echo "matrix=$matrix" >> $GITHUB_OUTPUT
82+
echo "branches=$branches" >> $GITHUB_OUTPUT
83+
fi
84+
85+
build-libs:
86+
name: Build with IDF ${{ matrix.idf_branch }} for ${{ matrix.target }}
87+
runs-on: ubuntu-latest
88+
if: needs.gen-matrix.outputs.branches != '[]'
89+
needs: gen-matrix
2590
strategy:
2691
fail-fast: false
27-
matrix:
28-
idf_branch: [release/v5.1, release/v4.4] #, release/v3.3]
92+
matrix: ${{ fromJson(needs.gen-matrix.outputs.matrix) }}
2993
steps:
3094
- uses: actions/checkout@v4
3195
with:
32-
fetch-depth: 0
96+
# Useful workaround for the checkout action to work with the matrix
97+
# https://github.com/actions/runner/issues/409#issuecomment-1013325196
98+
ref: ${{ matrix.idf_branch == env.LATEST_RELEASE_BRANCH && 'master' || matrix.idf_branch }}
99+
33100
- name: Install dependencies
34101
run: bash ./tools/prepare-ci.sh
102+
35103
- name: Build
36104
env:
37-
GITHUB_TOKEN: ${{ secrets.PUSH_TOKEN }}
105+
GITHUB_TOKEN: ${{ secrets.PUSH_TOKEN || secrets.GITHUB_TOKEN }}
38106
GIT_AUTHOR_EMAIL: ${{ secrets.PUSH_EMAIL }}
39107
GIT_COMMITTER_EMAIL: ${{ secrets.PUSH_EMAIL }}
40108
IDF_BRANCH: ${{ matrix.idf_branch }}
109+
TARGETS: ${{ matrix.target }}
41110
run: |
42-
git checkout ${{ matrix.idf_branch }} || echo "Using master branch"
43111
bash ./tools/cron.sh
112+
113+
- name: Replace invalid characters in the artifact name
114+
run: |
115+
branch=${{ matrix.idf_branch }}
116+
echo "libs_branch=${branch//\//_}" >> $GITHUB_ENV
117+
44118
- name: Upload build
45119
if: failure()
46120
uses: actions/upload-artifact@v4
47121
with:
48-
name: build
122+
name: build-${{ env.libs_branch }}-${{ matrix.target }}
49123
path: build
50-
- name: Upload archive
124+
125+
- name: Upload library files
51126
uses: actions/upload-artifact@v4
52127
with:
53-
name: artifacts
128+
name: libs-${{ env.libs_branch }}-${{ matrix.target }}
54129
path: dist
55130

131+
combine-artifacts:
132+
name: Combine artifacts for IDF ${{ matrix.idf_branch }}
133+
runs-on: ubuntu-latest
134+
needs: [gen-matrix, build-libs]
135+
# Condition is evaluated before the job is run so it won't cause a failure
136+
if: needs.gen-matrix.outputs.branches != '[]'
137+
strategy:
138+
fail-fast: false
139+
matrix:
140+
idf_branch: ${{ fromJson(needs.gen-matrix.outputs.branches) }}
141+
steps:
142+
- uses: actions/checkout@v4
143+
with:
144+
# Useful workaround for the checkout action to work with the matrix
145+
# https://github.com/actions/runner/issues/409#issuecomment-1013325196
146+
ref: ${{ matrix.idf_branch == env.LATEST_RELEASE_BRANCH && 'master' || matrix.idf_branch }}
147+
148+
- name: Replace invalid characters in the artifact name
149+
run: |
150+
branch=${{ matrix.idf_branch }}
151+
echo "libs_branch=${branch//\//_}" >> $GITHUB_ENV
152+
153+
- name: Download artifacts
154+
uses: actions/download-artifact@v4
155+
with:
156+
path: dist
157+
pattern: libs-${{ env.libs_branch }}-*
158+
merge-multiple: true
159+
160+
- name: Combine artifacts
161+
run: |
162+
set -e
163+
mkdir -p out
164+
165+
libs_folder="out/tools/esp32-arduino-libs"
166+
167+
files=$(find dist -name 'arduino-esp32-libs-esp*.tar.gz')
168+
for file in $files; do
169+
echo "Extracting $file"
170+
tar zxvf $file -C out
171+
cat $libs_folder/versions.txt >> $libs_folder/versions_full.txt
172+
done
173+
174+
# Merge versions.txt files
175+
awk -i inplace '!seen[$0]++' $libs_folder/versions_full.txt
176+
mv -f $libs_folder/versions_full.txt $libs_folder/versions.txt
177+
178+
cd $libs_folder && tar zcf ../../../dist/esp32-arduino-libs.tar.gz * && cd ../../..
179+
cp out/package_esp32_index.template.json dist/package_esp32_index.template.json
180+
181+
- name: Upload full esp32-arduino-libs archive
182+
uses: actions/upload-artifact@v4
183+
with:
184+
name: esp32-arduino-libs
185+
path: dist/esp32-arduino-libs.tar.gz
56186

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"
187+
- name: Upload package_esp32_index.template.json
188+
uses: actions/upload-artifact@v4
189+
with:
190+
name: package-esp32-index-json
191+
path: dist/package_esp32_index.template.json
144192

193+
- name: Push changes
194+
if: github.repository == 'espressif/esp32-arduino-lib-builder'
195+
env:
196+
GITHUB_TOKEN: ${{ secrets.PUSH_TOKEN }}
197+
GIT_AUTHOR_EMAIL: ${{ secrets.PUSH_EMAIL }}
198+
GIT_COMMITTER_EMAIL: ${{ secrets.PUSH_EMAIL }}
199+
IDF_BRANCH: ${{ matrix.idf_branch }}
200+
run: |
201+
bash ./tools/push-to-arduino.sh

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

+25-12
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"`
@@ -70,16 +75,24 @@ echo "LIBS_VERSION: $LIBS_VERSION"
7075
echo "LIBS_HAS_COMMIT: $LIBS_HAS_COMMIT"
7176
echo "LIBS_HAS_BRANCH: $LIBS_HAS_BRANCH"
7277

73-
if [ ! -x $GITHUB_OUTPUT ]; then
74-
echo "idf_commit=$IDF_COMMIT" >> "$GITHUB_OUTPUT"
75-
echo "ar_branch=$AR_BRANCH" >> "$GITHUB_OUTPUT"
76-
echo "ar_new_commit_message=$AR_NEW_COMMIT_MESSAGE" >> "$GITHUB_OUTPUT"
77-
echo "ar_new_branch_name=$AR_NEW_BRANCH_NAME" >> "$GITHUB_OUTPUT"
78-
echo "ar_new_pr_title=$AR_NEW_PR_TITLE" >> "$GITHUB_OUTPUT"
79-
echo "ar_has_commit=$AR_HAS_COMMIT" >> "$GITHUB_OUTPUT"
80-
echo "ar_has_branch=$AR_HAS_BRANCH" >> "$GITHUB_OUTPUT"
81-
echo "ar_has_pr=$AR_HAS_PR" >> "$GITHUB_OUTPUT"
82-
echo "libs_version=$LIBS_VERSION" >> "$GITHUB_OUTPUT"
83-
echo "libs_has_commit=$LIBS_HAS_COMMIT" >> "$GITHUB_OUTPUT"
84-
echo "libs_has_branch=$LIBS_HAS_BRANCH" >> "$GITHUB_OUTPUT"
78+
if [ ! -x $GITHUB_ENV ]; then
79+
echo "idf_commit=$IDF_COMMIT" >> "$GITHUB_ENV"
80+
echo "ar_branch=$AR_BRANCH" >> "$GITHUB_ENV"
81+
echo "ar_new_commit_message=$AR_NEW_COMMIT_MESSAGE" >> "$GITHUB_ENV"
82+
echo "ar_new_branch_name=$AR_NEW_BRANCH_NAME" >> "$GITHUB_ENV"
83+
echo "ar_new_pr_title=$AR_NEW_PR_TITLE" >> "$GITHUB_ENV"
84+
echo "ar_has_commit=$AR_HAS_COMMIT" >> "$GITHUB_ENV"
85+
echo "ar_has_branch=$AR_HAS_BRANCH" >> "$GITHUB_ENV"
86+
echo "ar_has_pr=$AR_HAS_PR" >> "$GITHUB_ENV"
87+
echo "libs_version=$LIBS_VERSION" >> "$GITHUB_ENV"
88+
echo "libs_has_commit=$LIBS_HAS_COMMIT" >> "$GITHUB_ENV"
89+
echo "libs_has_branch=$LIBS_HAS_BRANCH" >> "$GITHUB_ENV"
90+
fi
91+
92+
if [ "$LIBS_HAS_COMMIT" == "0" ] || [ "$AR_HAS_COMMIT" == "0" ]; then
93+
echo "Deploy needed"
94+
export DEPLOY_NEEDED="1"
95+
else
96+
echo "Deploy not needed. Skipping..."
97+
export DEPLOY_NEEDED="0"
8598
fi

tools/cron.sh

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

3-
if [ ! "$GITHUB_EVENT_NAME" == "schedule" ]; then
4-
echo "Wrong event '$GITHUB_EVENT_NAME'!"
5-
exit 1
3+
if [ -z "$TARGETS" ]; then
4+
TARGETS="all"
65
fi
76

8-
bash ./build.sh -d
7+
export IDF_CCACHE_ENABLE=1
8+
9+
bash ./build.sh -e -t $TARGETS

0 commit comments

Comments
 (0)