Skip to content

Commit d075b31

Browse files
committed
fix(libs): Allow for manual rebuilding and fix commit checking
1 parent b6f03b6 commit d075b31

File tree

4 files changed

+73
-9
lines changed

4 files changed

+73
-9
lines changed

Diff for: .github/workflows/cron.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ on:
1212
# │ │ │ │ │
1313
# * * * * *
1414
- cron: '0 */6 * * *'
15-
workflow_dispatch: # For testing
15+
workflow_dispatch: # For manually rebuilding the libraries
1616

1717
defaults:
1818
run:
@@ -21,6 +21,7 @@ defaults:
2121
jobs:
2222
build-libs:
2323
name: Build with IDF ${{ matrix.idf_branch }}
24+
if: github.repository_owner == 'espressif'
2425
uses: ./.github/workflows/cron_build.yml
2526
with:
2627
idf_branch: ${{ matrix.idf_branch }}

Diff for: .github/workflows/cron_build.yml

-1
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,6 @@ jobs:
132132
compression-level: 0
133133

134134
- name: Push changes
135-
if: github.repository == 'espressif/esp32-arduino-lib-builder'
136135
env:
137136
GITHUB_TOKEN: ${{ secrets.PUSH_TOKEN }}
138137
GIT_AUTHOR_EMAIL: ${{ secrets.PUSH_EMAIL }}

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

+25-4
Original file line numberDiff line numberDiff line change
@@ -37,19 +37,40 @@ AR_NEW_COMMIT_MESSAGE="IDF $IDF_BRANCH $IDF_COMMIT"
3737
AR_NEW_PR_TITLE="IDF $IDF_BRANCH"
3838

3939
LIBS_RELEASE_TAG="idf-"${IDF_BRANCH//\//_}""
40-
LIBS_VERSION="$LIBS_RELEASE_TAG-$IDF_COMMIT"
40+
LIBS_VERSION_PREFIX="$LIBS_RELEASE_TAG-$IDF_COMMIT-v"
41+
VERSION_COUNTER=1
4142

4243
AR_HAS_BRANCH=`github_branch_exists "$AR_REPO" "$AR_NEW_BRANCH_NAME"`
4344
if [ "$AR_HAS_BRANCH" == "1" ]; then
44-
AR_HAS_COMMIT=`github_commit_exists "$AR_REPO" "$AR_NEW_BRANCH_NAME" "$IDF_COMMIT"`
45+
LATEST_LIBS_IDF=`github_get_libs_idf "$AR_REPO" "$AR_NEW_BRANCH_NAME" "$AR_NEW_PR_TITLE"`
4546
else
46-
AR_HAS_COMMIT=`github_commit_exists "$AR_REPO" "$AR_BRANCH" "$IDF_COMMIT"`
47+
LATEST_LIBS_IDF=`github_get_libs_idf "$AR_REPO" "$AR_BRANCH" "$AR_NEW_PR_TITLE"`
4748
fi
49+
50+
echo "Current IDF commit: $IDF_COMMIT"
51+
echo "Latest IDF commit in $AR_BRANCH of $AR_REPO: $LATEST_LIBS_IDF"
52+
53+
AR_HAS_COMMIT=`if [ "$LATEST_LIBS_IDF" == "$IDF_COMMIT" ]; then echo "1"; else echo "0"; fi`
4854
AR_HAS_PR=`github_pr_exists "$AR_REPO" "$AR_NEW_BRANCH_NAME"`
4955

5056
LIBS_RELEASE_ID=`github_release_id "$AR_LIBS_REPO" "$LIBS_RELEASE_TAG"`
5157
LIBS_HAS_RELEASE=`if [ -n "$LIBS_RELEASE_ID" ]; then echo "1"; else echo "0"; fi`
52-
LIBS_ASSET_ID=`github_release_asset_id "$AR_LIBS_REPO" "$LIBS_RELEASE_ID" "esp32-arduino-libs-$LIBS_VERSION.zip"`
58+
59+
if [ "$GITHUB_EVENT_NAME" == "workflow_dispatch" ]; then
60+
echo "Workflow dispatch event. Generating new libs."
61+
while true; do
62+
LIBS_ASSET_ID=`github_release_asset_id "$AR_LIBS_REPO" "$LIBS_RELEASE_ID" "esp32-arduino-libs-$LIBS_VERSION_PREFIX$VERSION_COUNTER.zip"`
63+
if [ -n "$LIBS_ASSET_ID" ]; then
64+
VERSION_COUNTER=$((VERSION_COUNTER+1))
65+
else
66+
break
67+
fi
68+
done
69+
else
70+
LIBS_ASSET_ID=`github_release_asset_id "$AR_LIBS_REPO" "$LIBS_RELEASE_ID" "esp32-arduino-libs-$LIBS_VERSION_PREFIX$VERSION_COUNTER.zip"`
71+
fi
72+
73+
LIBS_VERSION="$LIBS_VERSION_PREFIX$VERSION_COUNTER"
5374
LIBS_HAS_ASSET=`if [ -n "$LIBS_ASSET_ID" ]; then echo "1"; else echo "0"; fi`
5475

5576
export IDF_COMMIT

Diff for: tools/config.sh

+46-3
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ if [ -z $IDF_TARGET ]; then
2525
fi
2626

2727
# Owner of the target ESP32 Arduino repository
28-
AR_USER="espressif"
28+
AR_USER="$GITHUB_REPOSITORY_OWNER"
2929

3030
# The full name of the repository
3131
AR_REPO="$AR_USER/arduino-esp32"
@@ -99,12 +99,55 @@ if [[ "$AR_OS" == "macos" ]]; then
9999
export SSTAT="stat -f %z"
100100
fi
101101

102+
function github_get_libs_idf(){ # github_get_libs_idf <repo-path> <branch-name> <message-prefix>
103+
local repo_path="$1"
104+
local branch_name="$2"
105+
local message_prefix="$3"
106+
message_prefix=$(echo $message_prefix | sed 's/[]\/$*.^|[]/\\&/g') # Escape special characters
107+
local page=1
108+
local version_found=""
109+
local libs_version=""
110+
111+
while [[ "$libs_version" == "" && "$page" -le 3 ]]; do
112+
# Get the latest commit message that matches the prefix and extract the hash from the last commit message
113+
version_found=`curl -s -k -H "Authorization: token $GITHUB_TOKEN" -H "Accept: application/vnd.github.v3.raw+json" "https://api.github.com/repos/$repo_path/commits?sha=$branch_name&per_page=100&page=$page" | \
114+
jq -r --arg prefix "$message_prefix" '[ .[] | select(.commit.message | test($prefix + " [a-f0-9]{8}")) ][0] | .commit.message' | \
115+
grep -Eo "$message_prefix [a-f0-9]{8}" | \
116+
awk 'END {print $NF}'`
117+
if [[ "$version_found" != "" && "$version_found" != "null" ]]; then
118+
libs_version=$version_found
119+
else
120+
page=$((page+1))
121+
fi
122+
done
123+
124+
if [ ! "$libs_version" == "" ] && [ ! "$libs_version" == "null" ]; then echo $libs_version; else echo ""; fi
125+
}
126+
102127
function github_commit_exists(){ #github_commit_exists <repo-path> <branch-name> <commit-message>
103128
local repo_path="$1"
104129
local branch_name="$2"
105130
local commit_message="$3"
106-
local commits_found=`curl -s -k -H "Authorization: token $GITHUB_TOKEN" -H "Accept: application/vnd.github.v3.raw+json" "https://api.github.com/repos/$repo_path/commits?sha=$branch_name" | jq -r '.[].commit.message' | grep "$commit_message" | wc -l`
107-
if [ ! "$commits_found" == "" ] && [ ! "$commits_found" == "null" ] && [ ! "$commits_found" == "0" ]; then echo $commits_found; else echo 0; fi
131+
local page=1
132+
local commits_found=0
133+
134+
while [ "$page" -le 3 ]; do
135+
local response=`curl -s -k -H "Authorization: token $GITHUB_TOKEN" -H "Accept: application/vnd.github.v3.raw+json" "https://api.github.com/repos/$repo_path/commits?sha=$branch_name&per_page=100&page=$page"`
136+
137+
if [[ -z "$response" || "$response" == "[]" ]]; then
138+
break
139+
fi
140+
141+
local commits=`echo "$response" | jq -r '.[].commit.message' | grep "$commit_message" | wc -l`
142+
if [ "$commits" -gt 0 ]; then
143+
commits_found=1
144+
break
145+
fi
146+
147+
page=$((page+1))
148+
done
149+
150+
echo $commits_found
108151
}
109152

110153
function github_last_commit(){ # github_last_commit <repo-path> <branch-name>

0 commit comments

Comments
 (0)