Skip to content

Commit 6f6313f

Browse files
committed
Split cron jobs using matrix
1 parent 6683a0d commit 6f6313f

File tree

7 files changed

+230
-165
lines changed

7 files changed

+230
-165
lines changed

Diff for: .github/workflows/cron.yml

+111-100
Original file line numberDiff line numberDiff line change
@@ -1,144 +1,155 @@
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+
# This input can be a comma-separated list of strings (e.g. "release/v5.1,release/v5.3") or "all" to build all branches.
19+
# For IDF versions before v5.1, "all" is not supported. Use a specific branch instead.
20+
description: 'IDF branch to build (check workflow file for instructions on how to use this input)'
21+
required: true
22+
default: 'all'
23+
target:
24+
# This input can be a comma-separated list of strings (e.g. "esp32,esp32s2") or "all" to build all targets.
25+
# For IDF versions before v5.1, "all" is not supported. Use a specific target list instead.
26+
description: 'Target to build (check workflow file for instructions on how to use this input)'
27+
required: true
28+
default: 'all'
1529

1630
defaults:
1731
run:
1832
shell: bash
1933

2034
jobs:
21-
run:
22-
name: Build with IDF ${{ matrix.idf_branch }}
35+
gen-matrix:
36+
name: Generate matrix
37+
runs-on: ubuntu-latest
38+
outputs:
39+
matrix: ${{ steps.gen-matrix.outputs.matrix }}
40+
branches: ${{ steps.gen-matrix.outputs.branches }}
41+
steps:
42+
- uses: actions/checkout@v4
43+
- name: Generate matrix
44+
id: gen-matrix
45+
run: |
46+
bash ./tools/cron-gen-matrix.sh "${{ github.event.inputs.idf_branch }}" "${{ github.event.inputs.target }}"
47+
48+
build-libs:
49+
name: Build with IDF ${{ matrix.idf_branch }} for ${{ matrix.target }}
2350
runs-on: ubuntu-latest
24-
51+
needs: gen-matrix
2552
strategy:
2653
fail-fast: false
27-
matrix:
28-
idf_branch: [release/v5.1, release/v4.4] #, release/v3.3]
54+
matrix: ${{ fromJson(needs.gen-matrix.outputs.matrix) }}
2955
steps:
3056
- uses: actions/checkout@v4
3157
with:
3258
fetch-depth: 0
59+
60+
- name: Check if result should be deployed
61+
id: check
62+
env:
63+
GITHUB_TOKEN: ${{ secrets.PUSH_TOKEN || secrets.GITHUB_TOKEN }}
64+
IDF_BRANCH: ${{ matrix.idf_branch }}
65+
run: |
66+
git checkout ${{ env.IDF_BRANCH }} || echo "Using master branch"
67+
bash ./tools/check-deploy-needed.sh
68+
3369
- name: Install dependencies
70+
if: env.libs_has_commit == '0' || env.ar_has_commit == '0'
3471
run: bash ./tools/prepare-ci.sh
72+
3573
- name: Build
3674
env:
37-
GITHUB_TOKEN: ${{ secrets.PUSH_TOKEN }}
75+
GITHUB_TOKEN: ${{ secrets.PUSH_TOKEN || secrets.GITHUB_TOKEN }}
3876
GIT_AUTHOR_EMAIL: ${{ secrets.PUSH_EMAIL }}
3977
GIT_COMMITTER_EMAIL: ${{ secrets.PUSH_EMAIL }}
4078
IDF_BRANCH: ${{ matrix.idf_branch }}
79+
TARGETS: ${{ matrix.target }}
80+
if: env.libs_has_commit == '0' || env.ar_has_commit == '0'
4181
run: |
42-
git checkout ${{ matrix.idf_branch }} || echo "Using master branch"
4382
bash ./tools/cron.sh
83+
4484
- name: Upload build
45-
if: failure()
85+
if: failure() && (env.libs_has_commit == '0' || env.ar_has_commit == '0')
4686
uses: actions/upload-artifact@v4
4787
with:
48-
name: build
88+
name: build-${{ env.libs_version }}-${{ matrix.target }}
4989
path: build
50-
- name: Upload archive
90+
91+
- name: Upload library files
92+
if: env.libs_has_commit == '0' || env.ar_has_commit == '0'
5193
uses: actions/upload-artifact@v4
5294
with:
53-
name: artifacts
95+
name: libs-${{ env.libs_version }}-${{ matrix.target }}
5496
path: dist
5597

98+
combine-artifacts:
99+
name: Combine artifacts for IDF ${{ matrix.idf_branch }}
100+
runs-on: ubuntu-latest
101+
needs: [gen-matrix, build-libs]
102+
strategy:
103+
fail-fast: false
104+
matrix:
105+
idf_branch: ${{ fromJson(needs.gen-matrix.outputs.branches) }}
106+
steps:
107+
- uses: actions/checkout@v4
108+
with:
109+
fetch-depth: 0
110+
111+
- name: Check if result should be deployed
112+
id: check
113+
env:
114+
GITHUB_TOKEN: ${{ secrets.PUSH_TOKEN || secrets.GITHUB_TOKEN }}
115+
IDF_BRANCH: ${{ matrix.idf_branch }}
116+
run: |
117+
git checkout ${{ env.IDF_BRANCH }} || echo "Using master branch"
118+
bash ./tools/check-deploy-needed.sh
119+
120+
- name: Download artifacts
121+
if: env.libs_has_commit == '0' || env.ar_has_commit == '0'
122+
uses: actions/download-artifact@v4
123+
with:
124+
path: dist
125+
pattern: libs-${{ env.libs_version }}-*
126+
merge-multiple: true
127+
128+
- name: Combine artifacts
129+
if: env.libs_has_commit == '0' || env.ar_has_commit == '0'
130+
run: |
131+
bash ./tools/cron-combine.sh
132+
133+
- name: Upload full esp32-arduino-libs archive
134+
if: env.libs_has_commit == '0' || env.ar_has_commit == '0'
135+
uses: actions/upload-artifact@v4
136+
with:
137+
name: esp32-arduino-libs
138+
path: dist/esp32-arduino-libs.tar.gz
56139

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"
140+
- name: Upload package_esp32_index.template.json
141+
if: env.libs_has_commit == '0' || env.ar_has_commit == '0'
142+
uses: actions/upload-artifact@v4
143+
with:
144+
name: package-esp32-index-json
145+
path: dist/package_esp32_index.template.json
144146

147+
- name: Push changes
148+
if: github.repository == 'espressif/esp32-arduino-lib-builder' && (env.libs_has_commit == '0' || env.ar_has_commit == '0')
149+
env:
150+
GITHUB_TOKEN: ${{ secrets.PUSH_TOKEN }}
151+
GIT_AUTHOR_EMAIL: ${{ secrets.PUSH_EMAIL }}
152+
GIT_COMMITTER_EMAIL: ${{ secrets.PUSH_EMAIL }}
153+
IDF_BRANCH: ${{ matrix.idf_branch }}
154+
run: |
155+
bash ./tools/push-to-arduino.sh

Diff for: 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

Diff for: tools/check-deploy-needed.sh

+23-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,22 @@ 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+
else
95+
echo "Deploy not needed. Skipping..."
8596
fi

Diff for: tools/cron-combine.sh

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/bin/bash
2+
3+
set -e
4+
mkdir -p out
5+
6+
libs_folder="out/tools/esp32-arduino-libs"
7+
8+
files=$(find dist -name 'arduino-esp32-libs-esp*.tar.gz')
9+
for file in $files; do
10+
echo "Extracting $file"
11+
tar zxvf $file -C out
12+
cat $libs_folder/versions.txt >> $libs_folder/versions_full.txt
13+
done
14+
15+
# Merge versions.txt files
16+
awk -i inplace '!seen[$0]++' $libs_folder/versions_full.txt
17+
mv -f $libs_folder/versions_full.txt $libs_folder/versions.txt
18+
19+
cd $libs_folder && tar zcf ../../../dist/esp32-arduino-libs.tar.gz * && cd ../../..
20+
cp out/package_esp32_index.template.json dist/package_esp32_index.template.json

0 commit comments

Comments
 (0)