Skip to content

Commit 6d86a0b

Browse files
committed
Use github releases for libs
1 parent 86a6f66 commit 6d86a0b

File tree

7 files changed

+203
-102
lines changed

7 files changed

+203
-102
lines changed

.github/workflows/cron.yml

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

1617
defaults:
1718
run:
@@ -25,6 +26,7 @@ jobs:
2526
idf_branch: ${{ matrix.idf_branch }}
2627
lib_builder_branch: ${{ matrix.lib_builder_branch }}
2728
targets: ${{ matrix.targets }}
29+
secrets: inherit
2830
strategy:
2931
fail-fast: false
3032
matrix:

.github/workflows/cron_build.yml

+46-11
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,20 @@ jobs:
2424
name: Check if deploy is needed for ${{ inputs.idf_branch }}
2525
runs-on: ubuntu-latest
2626
outputs:
27+
idf_commit: ${{ steps.check.outputs.idf_commit }}
28+
ar_branch: ${{ steps.check.outputs.ar_branch }}
29+
ar_new_commit_message: ${{ steps.check.outputs.ar_new_commit_message }}
30+
ar_new_branch_name: ${{ steps.check.outputs.ar_new_branch_name }}
31+
ar_new_pr_title: ${{ steps.check.outputs.ar_new_pr_title }}
32+
ar_has_commit: ${{ steps.check.outputs.ar_has_commit }}
33+
ar_has_branch: ${{ steps.check.outputs.ar_has_branch }}
34+
ar_has_pr: ${{ steps.check.outputs.ar_has_pr }}
35+
libs_release_tag: ${{ steps.check.outputs.libs_release_tag }}
36+
libs_version: ${{ steps.check.outputs.libs_version }}
37+
libs_release_id: ${{ steps.check.outputs.libs_release_id }}
38+
libs_has_release: ${{ steps.check.outputs.libs_has_release }}
39+
libs_asset_id: ${{ steps.check.outputs.libs_asset_id }}
40+
libs_has_asset: ${{ steps.check.outputs.libs_has_asset }}
2741
deploy_needed: ${{ steps.check.outputs.deploy_needed }}
2842
targets_list: ${{ steps.check.outputs.targets_list }}
2943
steps:
@@ -39,13 +53,12 @@ jobs:
3953
source ./tools/check-deploy-needed.sh
4054
targets_list=$(echo "${{ inputs.targets }}" | sed 's/ *, */,/g' | sed 's/^/["/' | sed 's/$/"]/' | sed 's/,/","/g')
4155
echo "Targets list: $targets_list"
42-
echo "deploy_needed=$DEPLOY_NEEDED" >> $GITHUB_OUTPUT
4356
echo "targets_list=$targets_list" >> $GITHUB_OUTPUT
4457
4558
build-libs:
4659
name: Build for ${{ matrix.target }} (${{ inputs.idf_branch }})
4760
runs-on: ubuntu-latest
48-
if: needs.check-if-needed.outputs.deploy_needed == '1'
61+
if: needs.check-if-needed.outputs.libs_has_asset == '0'
4962
needs: check-if-needed
5063
strategy:
5164
fail-fast: false
@@ -87,47 +100,69 @@ jobs:
87100
path: dist
88101

89102
combine-artifacts:
90-
name: Combine artifacts for IDF ${{ inputs.idf_branch }}
103+
name: Combine artifacts and push changes for IDF ${{ inputs.idf_branch }}
91104
runs-on: ubuntu-latest
92105
needs: [check-if-needed, build-libs]
93-
if: needs.check-if-needed.outputs.deploy_needed == '1'
106+
if: |
107+
always() &&
108+
needs.check-if-needed.result == 'success' &&
109+
needs.check-if-needed.outputs.deploy_needed == '1'
94110
steps:
95111
- uses: actions/checkout@v4
96112
with:
97113
ref: ${{ inputs.lib_builder_branch }}
98114

99115
- name: Replace invalid characters in the artifact name
116+
if: needs.check-if-needed.outputs.libs_has_asset == '0'
100117
run: |
101118
branch=${{ inputs.idf_branch }}
102119
echo "libs_branch=${branch//\//_}" >> $GITHUB_ENV
103120
104121
- name: Download artifacts
122+
if: needs.check-if-needed.outputs.libs_has_asset == '0'
105123
uses: actions/download-artifact@v4
106124
with:
107125
path: dist
108126
pattern: libs-${{ env.libs_branch }}-*
109127
merge-multiple: true
110128

111129
- name: Combine artifacts
130+
if: needs.check-if-needed.outputs.libs_has_asset == '0'
112131
run: bash ./tools/combine-artifacts.sh
113132

114133
- name: Upload full esp32-arduino-libs archive
134+
if: needs.check-if-needed.outputs.libs_has_asset == '0'
115135
uses: actions/upload-artifact@v4
116136
with:
117137
name: esp32-arduino-libs-${{ env.libs_branch }}
118-
path: dist/esp32-arduino-libs.tar.gz
119-
120-
- name: Upload package_esp32_index.template.json
121-
uses: actions/upload-artifact@v4
122-
with:
123-
name: package-esp32-index-json-${{ env.libs_branch }}
124-
path: dist/package_esp32_index.template.json
138+
path: dist/esp32-arduino-libs.zip
139+
compression-level: 0
125140

126141
- name: Push changes
127142
if: github.repository == 'espressif/esp32-arduino-lib-builder'
128143
env:
129144
GITHUB_TOKEN: ${{ secrets.PUSH_TOKEN }}
130145
GIT_AUTHOR_EMAIL: ${{ secrets.PUSH_EMAIL }}
131146
GIT_COMMITTER_EMAIL: ${{ secrets.PUSH_EMAIL }}
147+
IDF_COMMIT: ${{ needs.check-if-needed.outputs.idf_commit }}
148+
AR_BRANCH: ${{ needs.check-if-needed.outputs.ar_branch }}
149+
AR_NEW_COMMIT_MESSAGE: ${{ needs.check-if-needed.outputs.ar_new_commit_message }}
150+
AR_NEW_BRANCH_NAME: ${{ needs.check-if-needed.outputs.ar_new_branch_name }}
151+
AR_NEW_PR_TITLE: ${{ needs.check-if-needed.outputs.ar_new_pr_title }}
152+
AR_HAS_COMMIT: ${{ needs.check-if-needed.outputs.ar_has_commit }}
153+
AR_HAS_BRANCH: ${{ needs.check-if-needed.outputs.ar_has_branch }}
154+
AR_HAS_PR: ${{ needs.check-if-needed.outputs.ar_has_pr }}
155+
LIBS_RELEASE_TAG: ${{ needs.check-if-needed.outputs.libs_release_tag }}
156+
LIBS_VERSION: ${{ needs.check-if-needed.outputs.libs_version }}
157+
LIBS_RELEASE_ID: ${{ needs.check-if-needed.outputs.libs_release_id }}
158+
LIBS_HAS_RELEASE: ${{ needs.check-if-needed.outputs.libs_has_release }}
159+
LIBS_ASSET_ID: ${{ needs.check-if-needed.outputs.libs_asset_id }}
160+
LIBS_HAS_ASSET: ${{ needs.check-if-needed.outputs.libs_has_asset }}
132161
run: |
133162
bash ./tools/push-to-arduino.sh
163+
164+
- name: Upload package_esp32_index.template.json
165+
uses: actions/upload-artifact@v4
166+
with:
167+
name: package-esp32-index-json-${{ env.libs_branch }}
168+
path: out/package_esp32_index.template.json

tools/check-deploy-needed.sh

+36-16
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ AR_NEW_BRANCH_NAME="idf-$IDF_BRANCH"
3636
AR_NEW_COMMIT_MESSAGE="IDF $IDF_BRANCH $IDF_COMMIT"
3737
AR_NEW_PR_TITLE="IDF $IDF_BRANCH"
3838

39-
LIBS_VERSION="idf-"${IDF_BRANCH//\//_}"-$IDF_COMMIT"
39+
LIBS_RELEASE_TAG="idf-"${IDF_BRANCH//\//_}""
40+
LIBS_VERSION="$LIBS_RELEASE_TAG-$IDF_COMMIT"
4041

4142
AR_HAS_BRANCH=`github_branch_exists "$AR_REPO" "$AR_NEW_BRANCH_NAME"`
4243
if [ "$AR_HAS_BRANCH" == "1" ]; then
@@ -46,8 +47,10 @@ else
4647
fi
4748
AR_HAS_PR=`github_pr_exists "$AR_REPO" "$AR_NEW_BRANCH_NAME"`
4849

49-
LIBS_HAS_BRANCH=`github_branch_exists "$AR_LIBS_REPO" "$AR_NEW_BRANCH_NAME"`
50-
LIBS_HAS_COMMIT=`github_commit_exists "$AR_LIBS_REPO" "$AR_NEW_BRANCH_NAME" "$IDF_COMMIT"`
50+
LIBS_RELEASE_ID=`github_release_id "$AR_LIBS_REPO" "$LIBS_RELEASE_TAG"`
51+
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"`
53+
LIBS_HAS_ASSET=`if [ -n "$LIBS_ASSET_ID" ]; then echo "1"; else echo "0"; fi`
5154

5255
export IDF_COMMIT
5356

@@ -59,9 +62,25 @@ export AR_HAS_COMMIT
5962
export AR_HAS_BRANCH
6063
export AR_HAS_PR
6164

65+
export LIBS_RELEASE_TAG
6266
export LIBS_VERSION
63-
export LIBS_HAS_COMMIT
64-
export LIBS_HAS_BRANCH
67+
export LIBS_RELEASE_ID
68+
export LIBS_HAS_RELEASE
69+
export LIBS_ASSET_ID
70+
export LIBS_HAS_ASSET
71+
72+
if [ "$LIBS_HAS_RELEASE" == "1" ]; then
73+
if [ "$LIBS_HAS_ASSET" == "0" ] || [ "$AR_HAS_COMMIT" == "0" ]; then
74+
echo "Deploy needed"
75+
export DEPLOY_NEEDED="1"
76+
else
77+
echo "Deploy not needed. Skipping..."
78+
export DEPLOY_NEEDED="0"
79+
fi
80+
else
81+
echo "Release for tag \"$LIBS_RELEASE_TAG\" not found. Please create the release first."
82+
exit 1
83+
fi
6584

6685
echo "IDF_COMMIT: $IDF_COMMIT"
6786
echo "AR_BRANCH: $AR_BRANCH"
@@ -71,9 +90,13 @@ echo "AR_NEW_PR_TITLE: $AR_NEW_PR_TITLE"
7190
echo "AR_HAS_COMMIT: $AR_HAS_COMMIT"
7291
echo "AR_HAS_BRANCH: $AR_HAS_BRANCH"
7392
echo "AR_HAS_PR: $AR_HAS_PR"
93+
echo "LIBS_RELEASE_TAG: $LIBS_RELEASE_TAG"
7494
echo "LIBS_VERSION: $LIBS_VERSION"
75-
echo "LIBS_HAS_COMMIT: $LIBS_HAS_COMMIT"
76-
echo "LIBS_HAS_BRANCH: $LIBS_HAS_BRANCH"
95+
echo "LIBS_RELEASE_ID: $LIBS_RELEASE_ID"
96+
echo "LIBS_HAS_RELEASE: $LIBS_HAS_RELEASE"
97+
echo "LIBS_ASSET_ID: $LIBS_ASSET_ID"
98+
echo "LIBS_HAS_ASSET: $LIBS_HAS_ASSET"
99+
echo "DEPLOY_NEEDED: $DEPLOY_NEEDED"
77100

78101
if [ ! -x $GITHUB_OUTPUT ]; then
79102
echo "idf_commit=$IDF_COMMIT" >> "$GITHUB_OUTPUT"
@@ -84,15 +107,12 @@ if [ ! -x $GITHUB_OUTPUT ]; then
84107
echo "ar_has_commit=$AR_HAS_COMMIT" >> "$GITHUB_OUTPUT"
85108
echo "ar_has_branch=$AR_HAS_BRANCH" >> "$GITHUB_OUTPUT"
86109
echo "ar_has_pr=$AR_HAS_PR" >> "$GITHUB_OUTPUT"
110+
echo "libs_release_tag=$LIBS_RELEASE_TAG" >> "$GITHUB_OUTPUT"
87111
echo "libs_version=$LIBS_VERSION" >> "$GITHUB_OUTPUT"
88-
echo "libs_has_commit=$LIBS_HAS_COMMIT" >> "$GITHUB_OUTPUT"
89-
echo "libs_has_branch=$LIBS_HAS_BRANCH" >> "$GITHUB_OUTPUT"
112+
echo "libs_release_id=$LIBS_RELEASE_ID" >> "$GITHUB_OUTPUT"
113+
echo "libs_has_release=$LIBS_HAS_RELEASE" >> "$GITHUB_OUTPUT"
114+
echo "libs_asset_id=$LIBS_ASSET_ID" >> "$GITHUB_OUTPUT"
115+
echo "libs_has_asset=$LIBS_HAS_ASSET" >> "$GITHUB_OUTPUT"
116+
echo "deploy_needed=$DEPLOY_NEEDED" >> "$GITHUB_OUTPUT"
90117
fi
91118

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"
98-
fi

tools/combine-artifacts.sh

+1-2
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,4 @@ done
1616
awk -i inplace '!seen[$0]++' $libs_folder/versions_full.txt
1717
mv -f $libs_folder/versions_full.txt $libs_folder/versions.txt
1818

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
19+
cd out/tools && zip -r ../../dist/esp32-arduino-libs.zip * && cd ../..

tools/config.sh

+31-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ AR_GEN_PART_PY="$AR_TOOLS/gen_esp32part.py"
5050
AR_SDK="$AR_TOOLS/esp32-arduino-libs/$IDF_TARGET"
5151
PIO_SDK="FRAMEWORK_SDK_DIR, \"$IDF_TARGET\""
5252
TOOLS_JSON_OUT="$AR_TOOLS/esp32-arduino-libs"
53-
IDF_LIBS_DIR="$AR_ROOT/../esp32-arduino-libs"
5453

5554
if [ -d "$IDF_PATH" ]; then
5655
export IDF_COMMIT=$(git -C "$IDF_PATH" rev-parse --short HEAD)
@@ -132,6 +131,37 @@ function github_pr_exists(){ # github_pr_exists <repo-path> <branch-name>
132131
if [ ! "$pr_num" == "" ] && [ ! "$pr_num" == "null" ]; then echo 1; else echo 0; fi
133132
}
134133

134+
function github_release_id(){ # github_release_id <repo-path> <release-tag>
135+
local repo_path="$1"
136+
local release_tag="$2"
137+
local release=`curl -s -k -H "Authorization: token $GITHUB_TOKEN" -H "Accept: application/vnd.github.v3.raw+json" "https://api.github.com/repos/$repo_path/releases" | jq --arg release_tag "$release_tag" -r '.[] | select(.tag_name == $release_tag) | .id'`
138+
if [ ! "$release" == "" ] && [ ! "$release" == "null" ]; then echo "$release"; else echo ""; fi
139+
}
140+
141+
function github_release_asset_id(){ # github_release_asset_id <repo-path> <release-id> <release-file>
142+
local repo_path="$1"
143+
local release_id="$2"
144+
local release_file="$3"
145+
local release_asset=`curl -s -k -H "Authorization: token $GITHUB_TOKEN" -H "Accept: application/vnd.github.v3.raw+json" "https://api.github.com/repos/$repo_path/releases/$release_id/assets" | jq --arg release_file "$release_file" -r '.[] | select(.name == $release_file) | .id'`
146+
if [ ! "$release_asset" == "" ] && [ ! "$release_asset" == "null" ]; then echo "$release_asset"; else echo ""; fi
147+
}
148+
149+
function github_release_asset_upload(){ # github_release_asset_upload <repo-path> <release-id> <release-file-name> <release-file-path>
150+
local repo_path="$1"
151+
local release_id="$2"
152+
local release_file_name="$3"
153+
local release_file_path="$4"
154+
local file_extension="${release_file_name##*.}"
155+
local release_asset=`curl -s -k -X POST -H "Authorization: token $GITHUB_TOKEN" -H "Accept: application/vnd.github.v3.raw+json" -H "Content-Type: application/$file_extension" --data-binary "@$release_file_path" "https://uploads.github.com/repos/$repo_path/releases/$release_id/assets?name=$release_file_name" | jq -r '.id'`
156+
if [ ! "$release_asset" == "" ] && [ ! "$release_asset" == "null" ]; then echo "$release_asset"; else echo ""; fi
157+
}
158+
159+
function github_release_asset_delete(){ # github_release_asset_delete <repo-path> <release-asset-id>
160+
local repo_path="$1"
161+
local release_asset_id="$2"
162+
local res=$(curl -s -k -o /dev/null -w "%{http_code}" -X DELETE -H "Authorization: token $GITHUB_TOKEN" -H "Accept: application/vnd.github.v3.raw+json" "https://api.github.com/repos/$repo_path/releases/assets/$release_asset_id")
163+
if [ "$res" -eq 204 ]; then echo 1; else echo 0; fi
164+
}
135165

136166

137167
function git_branch_exists(){ # git_branch_exists <repo-path> <branch-name>

tools/install-arduino.sh

-14
Original file line numberDiff line numberDiff line change
@@ -46,17 +46,3 @@ if [ "$AR_BRANCH" ]; then
4646
git -C "$AR_COMPS/arduino" pull --ff-only
4747
fi
4848
if [ $? -ne 0 ]; then exit 1; fi
49-
50-
#
51-
# CLONE/UPDATE ESP32-ARDUINO-LIBS
52-
#
53-
if [ ! -d "$IDF_LIBS_DIR" ]; then
54-
echo "Cloning esp32-arduino-libs..."
55-
git clone "$AR_LIBS_REPO_URL" "$IDF_LIBS_DIR"
56-
else
57-
echo "Updating esp32-arduino-libs..."
58-
git -C "$IDF_LIBS_DIR" fetch && \
59-
git -C "$IDF_LIBS_DIR" pull --ff-only
60-
fi
61-
if [ $? -ne 0 ]; then exit 1; fi
62-

0 commit comments

Comments
 (0)