Cron Deploy #474
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Cron Build | |
on: | |
schedule: | |
# ┌───────────── minute (0 - 59) | |
# │ ┌───────────── hour (0 - 23) | |
# │ │ ┌───────────── day of the month (1 - 31) | |
# │ │ │ ┌───────────── month (1 - 12 or JAN-DEC) | |
# │ │ │ │ ┌───────────── day of the week (0 - 6 or SUN-SAT) | |
# │ │ │ │ │ | |
# │ │ │ │ │ | |
# │ │ │ │ │ | |
# * * * * * | |
- cron: '0 */6 * * *' | |
workflow_dispatch: | |
inputs: | |
idf_branch: | |
description: 'IDF branch to build (JSON list of strings e.g. ["release/v5.1"] or "all" to build all branches)' | |
required: true | |
default: 'all' | |
target: | |
description: 'Target to build (JSON list of strings e.g. ["esp32", "esp32s2"] or "all" to build all targets)' | |
required: true | |
default: 'all' | |
defaults: | |
run: | |
shell: bash | |
jobs: | |
gen-matrix: | |
name: Generate matrix | |
runs-on: ubuntu-latest | |
outputs: | |
matrix: ${{ steps.gen-matrix.outputs.matrix }} | |
branches: ${{ steps.gen-matrix.outputs.branches }} | |
steps: | |
- name: Generate matrix | |
id: gen-matrix | |
run: | | |
# Change this based on the IDF branches we want to build | |
all_branches="[\"release/v5.1\"]" | |
# Change this based on the COMMON targets for all branches we want to build. | |
common_targets="[\"esp32\", \"esp32s2\", \"esp32s3\", \"esp32c2\", \"esp32c3\", \"esp32c6\", \"esp32h2\"]" | |
# For additional targets per branch, add them here | |
additional_targets="[{\"idf_branch\": \"release/v5.3\", \"target\": \"esp32p4\"}]" | |
branches="${{ github.event.inputs.idf_branch }}" | |
targets="${{ github.event.inputs.target }}" | |
if [ -z "$branches" ] || [ "$branches" == "all" ]; then | |
branches=$all_branches | |
fi | |
if [ -z "$targets" ]; then | |
targets="all" | |
fi | |
echo "Inputs:" | |
echo "idf_branch: ${{ github.event.inputs.idf_branch }}" | |
echo "target: ${{ github.event.inputs.target }}" | |
matrix="{" | |
matrix+="\"idf_branch\": $branches," | |
if [ "$targets" == "all" ]; then | |
matrix+="\"target\": $common_targets," | |
matrix+="\"include\": " | |
# Add all additional targets that are in the selected branches | |
matrix+=$(echo $additional_targets | jq --argjson branches "$branches" '[.[] | select(.idf_branch as $branch | $branches | index($branch))]') | |
else | |
matrix+="\"target\": $targets" | |
fi | |
matrix+="}" | |
echo "Branches: $branches" | |
echo "Targets: $targets" | |
echo "Matrix:" | |
echo "$matrix" | jq . | |
echo "matrix=$matrix" >> $GITHUB_OUTPUT | |
echo "branches=$branches" >> $GITHUB_OUTPUT | |
build-libs: | |
name: Build with IDF ${{ matrix.idf_branch }} for ${{ matrix.target }} | |
runs-on: ubuntu-latest | |
needs: gen-matrix | |
strategy: | |
fail-fast: false | |
matrix: ${{ fromJson(needs.gen-matrix.outputs.matrix) }} | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Check if result should be deployed | |
id: check | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
IDF_BRANCH: ${{ matrix.idf_branch }} | |
run: | | |
git checkout ${{ env.IDF_BRANCH }} || echo "Using master branch" | |
bash ./tools/check-deploy-needed.sh | |
- name: Create artifact id | |
id: artifact_id | |
run: | | |
artifact_id=${{ matrix.idf_branch }}-${{ matrix.target }} | |
echo "artifact_id=${artifact_id////_}" >> $GITHUB_ENV | |
- name: Install dependencies | |
#if: env.libs_has_commit == '0' || env.ar_has_commit == '0' | |
run: bash ./tools/prepare-ci.sh | |
- name: Build | |
env: | |
GITHUB_TOKEN: ${{ secrets.PUSH_TOKEN }} | |
GIT_AUTHOR_EMAIL: ${{ secrets.PUSH_EMAIL }} | |
GIT_COMMITTER_EMAIL: ${{ secrets.PUSH_EMAIL }} | |
IDF_BRANCH: ${{ matrix.idf_branch }} | |
TARGETS: ${{ matrix.target }} | |
#if: env.libs_has_commit == '0' || env.ar_has_commit == '0' | |
run: | | |
bash ./tools/cron.sh | |
- name: Upload build | |
if: failure() && (env.libs_has_commit == '0' || env.ar_has_commit == '0') | |
uses: actions/upload-artifact@v4 | |
with: | |
name: build-${{ steps.artifact_id.outputs.artifact_id }} | |
path: build | |
- name: Upload library files | |
#if: env.libs_has_commit == '0' || env.ar_has_commit == '0' | |
uses: actions/upload-artifact@v4 | |
with: | |
name: libs-${{ steps.artifact_id.outputs.artifact_id }} | |
path: dist | |
combine-artifacts: | |
name: Combine artifacts for IDF ${{ matrix.idf_branch }} | |
runs-on: ubuntu-latest | |
needs: [gen-matrix, build-libs] | |
strategy: | |
fail-fast: false | |
matrix: | |
idf_branch: ${{ fromJson(needs.gen-matrix.outputs.branches) }} | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Check if result should be deployed | |
id: check | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
IDF_BRANCH: ${{ matrix.idf_branch }} | |
run: | | |
git checkout ${{ env.IDF_BRANCH }} || echo "Using master branch" | |
bash ./tools/check-deploy-needed.sh | |
- name: Create artifact id | |
id: artifact_id | |
run: | | |
artifact_id=${{ matrix.idf_branch }} | |
echo "artifact_id=${artifact_id////_}" >> $GITHUB_ENV | |
- name: Download artifacts | |
#if: env.libs_has_commit == '0' || env.ar_has_commit == '0' | |
uses: actions/download-artifact@v4 | |
with: | |
path: dist | |
pattern: libs-${{ steps.artifact_id.outputs.artifact_id }}-* | |
merge-multiple: true | |
- name: Combine artifacts | |
#if: env.libs_has_commit == '0' || env.ar_has_commit == '0' | |
shell: bash | |
run: | | |
set -e | |
mkdir -p out | |
find dist -name 'arduino-esp32-libs-esp*.tar.gz' | |
for file in $files; do | |
tar zxvf $file -C out | |
cat out/tools/esp32-arduino-libs/versions.txt >> out/tools/esp32-arduino-libs/versions_full.txt | |
done | |
# Merge versions.txt files | |
awk -i inplace '!seen[$0]++' out/tools/esp32-arduino-libs/versions_full.txt | |
mv -f out/tools/esp32-arduino-libs/versions_full.txt out/tools/esp32-arduino-libs/versions.txt | |
cd out/tools/esp32-arduino-libs && tar zcf ../../../dist/esp32-arduino-libs.tar.gz * && cd ../../.. | |
cp out/package_esp32_index.template.json dist/package_esp32_index.template.json | |
- name: Upload full esp32-arduino-libs archive | |
#if: env.libs_has_commit == '0' || env.ar_has_commit == '0' | |
uses: actions/upload-artifact@v4 | |
with: | |
name: esp32-arduino-libs | |
path: dist/esp32-arduino-libs.tar.gz | |
- name: Upload package_esp32_index.template.json | |
#if: env.libs_has_commit == '0' || env.ar_has_commit == '0' | |
uses: actions/upload-artifact@v4 | |
with: | |
name: package-esp32-index-json | |
path: dist/package_esp32_index.template.json | |
- name: Push changes | |
if: github.repository == 'espressif/esp32-arduino-lib-builder' && (env.libs_has_commit == '0' || env.ar_has_commit == '0') | |
env: | |
GITHUB_TOKEN: ${{ secrets.PUSH_TOKEN }} | |
GIT_AUTHOR_EMAIL: ${{ secrets.PUSH_EMAIL }} | |
GIT_COMMITTER_EMAIL: ${{ secrets.PUSH_EMAIL }} | |
IDF_BRANCH: ${{ matrix.idf_branch }} | |
run: | | |
bash ./tools/push-to-arduino.sh |