Skip to content

Commit 0af3e2b

Browse files
committed
ci: replace ci_fetch_submodules.py with submodule cache
1 parent 598f19e commit 0af3e2b

File tree

12 files changed

+49
-152
lines changed

12 files changed

+49
-152
lines changed

.gitlab/ci/common.yml

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -30,26 +30,15 @@ variables:
3030
# - set GIT_STRATEGY: "clone" to shiny runners
3131
# - set GIT_STRATEGY: "fetch" to brew runners
3232
GIT_STRATEGY: clone
33-
# we will download archive for each submodule instead of clone.
34-
# we don't do "recursive" when fetch submodule as they're not used in CI now.
35-
GIT_SUBMODULE_STRATEGY: none
36-
# since we're using merged-result pipelines, the last commit should work for most cases
3733
GIT_DEPTH: 1
38-
# --no-recurse-submodules: we use cache for submodules
34+
GIT_SUBMODULE_STRATEGY: none # here we use cache for submodules, so we don't need to fetch them every time
35+
# since we're using merged-result pipelines, the last commit should work for most cases
3936
# --prune --prune-tags: in case remote branch or tag is force pushed
4037
GIT_FETCH_EXTRA_FLAGS: "--no-recurse-submodules --prune --prune-tags"
4138
# we're using .cache folder for caches
4239
GIT_CLEAN_FLAGS: -ffdx -e .cache/
4340
LATEST_GIT_TAG: v6.0-dev
4441

45-
SUBMODULE_FETCH_TOOL: "tools/ci/ci_fetch_submodule.py"
46-
# by default we will fetch all submodules
47-
# jobs can overwrite this variable to only fetch submodules they required
48-
# set to "none" if don't need to fetch submodules
49-
SUBMODULES_TO_FETCH: "all"
50-
# tell build system do not check submodule update as we download archive instead of clone
51-
IDF_SKIP_CHECK_SUBMODULES: 1
52-
5342
IDF_PATH: "$CI_PROJECT_DIR"
5443
V: "0"
5544
CHECKOUT_REF_SCRIPT: "$CI_PROJECT_DIR/tools/ci/checkout_project_ref.py"
@@ -392,11 +381,9 @@ default:
392381
paths:
393382
- .cache/pip
394383
policy: pull
395-
- key: submodule-cache-${LATEST_GIT_TAG}
396-
fallback_keys:
397-
- submodule-cache
384+
- key: git-submodule-cache-${LATEST_GIT_TAG}
398385
paths:
399-
- .cache/submodule_archives
386+
- .git/modules
400387
policy: pull
401388
before_script:
402389
- *common-before_scripts

.gitlab/ci/deploy.yml

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,7 @@ check_submodule_sync:
1111
tags: [ brew, github_sync ]
1212
retry: 2
1313
variables:
14-
# for brew runners, we always set GIT_STRATEGY to fetch
15-
GIT_STRATEGY: fetch
16-
SUBMODULES_TO_FETCH: "none"
14+
GIT_STRATEGY: fetch # use brew local mirror first
1715
PUBLIC_IDF_URL: "https://github.com/espressif/esp-idf.git"
1816
dependencies: []
1917
script:
@@ -36,10 +34,8 @@ push_to_github:
3634
- check_submodule_sync
3735
tags: [ brew, github_sync ]
3836
variables:
39-
# for brew runners, we always set GIT_STRATEGY to fetch
40-
GIT_STRATEGY: fetch
41-
# github also need full record of commits
42-
GIT_DEPTH: 0
37+
GIT_STRATEGY: fetch # use brew local mirror first
38+
GIT_DEPTH: 0 # github needs full record of commits
4339
script:
4440
- add_github_ssh_keys
4541
- git remote remove github &>/dev/null || true

.gitlab/ci/host-test.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -382,8 +382,6 @@ test_idf_pytest_plugin:
382382
extends:
383383
- .host_test_template
384384
- .rules:patterns:idf-pytest-plugin
385-
variables:
386-
SUBMODULES_TO_FETCH: "none"
387385
artifacts:
388386
reports:
389387
junit: XUNIT_RESULT.xml

.gitlab/ci/integration_test.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ gen_integration_pipeline:
3636
cache: []
3737
tags: [fast_run, shiny]
3838
variables:
39-
SUBMODULES_TO_FETCH: "none"
4039
GIT_LFS_SKIP_SMUDGE: 1
4140
needs:
4241
- job: fast_template_app

.gitlab/ci/pre_check.yml

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ check_version:
1515
# need a full clone to get the latest tag
1616
# the --shallow-since=$(git log -1 --format=%as $LATEST_GIT_TAG) option is not accurate
1717
GIT_STRATEGY: fetch
18-
SUBMODULES_TO_FETCH: "none"
1918
GIT_DEPTH: 0
2019
script:
2120
- export IDF_PATH=$PWD
@@ -33,8 +32,6 @@ check_blobs:
3332
extends:
3433
- .pre_check_template
3534
- .rules:build:check
36-
variables:
37-
SUBMODULES_TO_FETCH: "components/esp_wifi/lib;components/esp_phy/lib;components/esp_coex/lib"
3835
script:
3936
# Check if Wi-Fi library header files match between IDF and the version used when compiling the libraries
4037
- IDF_TARGET=esp32 $IDF_PATH/components/esp_wifi/test_md5/test_md5.sh
@@ -107,7 +104,6 @@ check_version_tag:
107104
# need a full clone to get the latest tag
108105
# the --shallow-since=$(git log -1 --format=%as $LATEST_GIT_TAG) option is not accurate
109106
GIT_STRATEGY: fetch
110-
SUBMODULES_TO_FETCH: "none"
111107
GIT_DEPTH: 0
112108
script:
113109
- (git cat-file -t $CI_COMMIT_REF_NAME | grep tag) || (echo "ESP-IDF versions must be annotated tags." && exit 1)
@@ -210,13 +206,12 @@ baseline_manifest_sha:
210206
when: always
211207

212208
redundant_pass_job:
213-
stage: pre_check
209+
extends:
210+
- .pre_check_template
214211
tags: [shiny, fast_run]
215-
image: $ESP_ENV_IMAGE
216-
dependencies: null
217-
before_script: []
218212
cache: []
219-
extends: []
213+
variables:
214+
GIT_STRATEGY: none
215+
before_script: []
220216
script:
221217
- echo "This job is redundant to ensure the 'retry_failed_jobs' job can exist and not be skipped"
222-
when: always

.gitlab/ci/pre_commit.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ check_pre_commit_upload_cache:
2424
paths:
2525
- .cache/pre-commit
2626
policy: pull-push
27-
- key: submodule-cache-${LATEST_GIT_TAG}
27+
- key: git-submodule-cache-${LATEST_GIT_TAG}
2828
paths:
29-
- .cache/submodule_archives
29+
- .git/modules
3030
policy: pull
3131

3232
check_pre_commit:
@@ -41,9 +41,9 @@ check_pre_commit:
4141
paths:
4242
- .cache/pre-commit
4343
policy: pull
44-
- key: submodule-cache-${LATEST_GIT_TAG}
44+
- key: git-submodule-cache-${LATEST_GIT_TAG}
4545
paths:
46-
- .cache/submodule_archives
46+
- .git/modules
4747
policy: pull
4848

4949
check_powershell:
@@ -74,7 +74,7 @@ check_powershell:
7474
paths:
7575
- .cache/pre-commit
7676
policy: pull
77-
- key: submodule-cache-${LATEST_GIT_TAG}
77+
- key: git-submodule-cache-${LATEST_GIT_TAG}
7878
paths:
79-
- .cache/submodule_archives
79+
- .git/modules
8080
policy: pull

.gitlab/ci/rules.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,9 @@
249249
changes: *patterns-submodule
250250
- <<: *if-label-upload_cache
251251
when: manual
252+
- <<: *if-dev-push
253+
changes:
254+
- .gitlab/ci/upload_cache.yml
252255

253256
### Patterns ###
254257
.rules:patterns:clang_tidy:

.gitlab/ci/test-win.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
extends: .rules:test:host_test
44
stage: host_test
55
image: $ESP_ENV_IMAGE
6-
tags:
7-
- windows-build
6+
tags: [windows-build, brew]
87
dependencies: # set dependencies to null to avoid missing artifacts issue
98
# run host_test jobs immediately, only after upload cache
109
needs:
@@ -14,6 +13,8 @@
1413
- job: upload-submodules-cache
1514
optional: true
1615
artifacts: false
16+
variables:
17+
GIT_STRATEGY: fetch # use brew local mirror first
1718
before_script: []
1819
after_script: []
1920

@@ -60,7 +61,7 @@ test_tools_win:
6061
- python -m pip install jsonschema
6162
- .\install.ps1 --enable-ci --enable-pytest
6263
- .\export.ps1
63-
- python "${SUBMODULE_FETCH_TOOL}" -s "all"
64+
- git submodule update --init
6465
- cd ${IDF_PATH}/tools/test_idf_py
6566
- pytest --noconftest test_idf_py.py --junitxml=${IDF_PATH}/XUNIT_IDF_PY.xml
6667
- pytest --noconftest test_hints.py --junitxml=${IDF_PATH}/XUNIT_HINTS.xml
@@ -78,7 +79,7 @@ test_tools_win:
7879
script:
7980
- .\install.ps1 --enable-ci --enable-pytest
8081
- . .\export.ps1
81-
- python "${SUBMODULE_FETCH_TOOL}" -s "all"
82+
- git submodule update --init
8283
- cd ${IDF_PATH}\tools\test_build_system
8384
- pytest --parallel-count ${CI_NODE_TOTAL} --parallel-index ${CI_NODE_INDEX} --junitxml=${CI_PROJECT_DIR}\XUNIT_RESULT.xml
8485

@@ -88,8 +89,7 @@ pytest_build_system_win:
8889
- .rules:labels:windows_pytest_build_system
8990
parallel: 2
9091
needs: []
91-
tags:
92-
- windows-build
92+
tags: [windows-build, brew]
9393
artifacts:
9494
paths:
9595
- XUNIT_RESULT.xml

.gitlab/ci/upload_cache.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,14 @@ upload-submodules-cache:
3535
- $GEO
3636
- cache
3737
cache:
38-
key: submodule-cache-${LATEST_GIT_TAG}
38+
key: git-submodule-cache-${LATEST_GIT_TAG}
3939
paths:
40-
- .cache/submodule_archives
40+
- .git/modules
4141
policy: push
4242
script:
4343
# use the default gitlab server
4444
- unset LOCAL_GITLAB_HTTPS_HOST
45-
- rm -rf .cache/submodule_archives # clear old submodule archives
45+
- rm -rf .git/modules # clear old submodules
4646
- add_gitlab_ssh_keys
4747
- fetch_submodules
4848
parallel:

tools/ci/ci_fetch_submodule.py

Lines changed: 18 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -1,113 +1,33 @@
11
#!/usr/bin/env python
2-
# SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD
2+
# SPDX-FileCopyrightText: 2022-2025 Espressif Systems (Shanghai) CO LTD
33
# SPDX-License-Identifier: Apache-2.0
44

55
# internal use only for CI
66
# download archive of one commit instead of cloning entire submodule repo
77

88
import argparse
9-
import os
10-
import re
11-
import shutil
129
import subprocess
10+
import sys
1311
import time
14-
from typing import Any, List
15-
16-
import gitlab_api
17-
18-
SUBMODULE_PATTERN = re.compile(r"\[submodule \"([^\"]+)\"]")
19-
PATH_PATTERN = re.compile(r'path\s+=\s+(\S+)')
20-
URL_PATTERN = re.compile(r'url\s+=\s+(\S+)')
21-
22-
SUBMODULE_ARCHIVE_TEMP_FOLDER = 'submodule_archive'
23-
# need to match the one defined in CI yaml files for caching purpose
24-
SUBMODULE_ARCHIVE_CACHE_DIR = '.cache/submodule_archives'
25-
26-
27-
class SubModule(object):
28-
# We don't need to support recursive submodule clone now
29-
30-
GIT_LS_TREE_OUTPUT_PATTERN = re.compile(r'\d+\s+commit\s+([0-9a-f]+)\s+')
31-
32-
def __init__(self, gitlab_inst: gitlab_api.Gitlab, path: str, url: str) -> None:
33-
self.path = path
34-
self.url = url
35-
self.gitlab_inst = gitlab_inst
36-
self.project_id = self._get_project_id(url)
37-
self.commit_id = self._get_commit_id(path)
38-
39-
def _get_commit_id(self, path: str) -> str:
40-
output = subprocess.check_output(['git', 'ls-tree', 'HEAD', path]).decode()
41-
# example output: 160000 commit d88a262fbdf35e5abb372280eb08008749c3faa0 components/esp_wifi/lib
42-
match = self.GIT_LS_TREE_OUTPUT_PATTERN.search(output)
43-
return match.group(1) if match is not None else ''
44-
45-
def _get_project_id(self, url: str) -> Any:
46-
base_name = os.path.basename(url)
47-
project_id = self.gitlab_inst.get_project_id(os.path.splitext(base_name)[0], # remove .git
48-
namespace='espressif')
49-
return project_id
50-
51-
def download_archive(self) -> None:
52-
print('Update submodule: {}: {}'.format(self.path, self.commit_id))
53-
path_name = self.gitlab_inst.download_archive(self.commit_id, SUBMODULE_ARCHIVE_TEMP_FOLDER,
54-
self.project_id, SUBMODULE_ARCHIVE_CACHE_DIR)
55-
renamed_path = os.path.join(os.path.dirname(path_name), os.path.basename(self.path))
56-
os.rename(path_name, renamed_path)
57-
shutil.rmtree(self.path, ignore_errors=True)
58-
shutil.move(renamed_path, os.path.dirname(self.path))
59-
60-
61-
def update_submodule(git_module_file: str, submodules_to_update: List) -> None:
62-
gitlab_inst = gitlab_api.Gitlab()
63-
submodules = []
64-
with open(git_module_file, 'r') as f:
65-
data = f.read()
66-
match = SUBMODULE_PATTERN.search(data)
67-
if match is not None:
68-
while True:
69-
next_match = SUBMODULE_PATTERN.search(data, pos=match.end())
70-
if next_match:
71-
end_pos = next_match.start()
72-
else:
73-
end_pos = len(data)
74-
path_match = PATH_PATTERN.search(data, pos=match.end(), endpos=end_pos)
75-
url_match = URL_PATTERN.search(data, pos=match.end(), endpos=end_pos)
76-
path = path_match.group(1) if path_match is not None else ''
77-
url = url_match.group(1) if url_match is not None else ''
78-
79-
filter_result = True
80-
if submodules_to_update:
81-
if path not in submodules_to_update:
82-
filter_result = False
83-
if filter_result:
84-
submodules.append(SubModule(gitlab_inst, path, url))
85-
86-
match = next_match
87-
if not match:
88-
break
89-
90-
shutil.rmtree(SUBMODULE_ARCHIVE_TEMP_FOLDER, ignore_errors=True)
91-
92-
for submodule in submodules:
93-
submodule.download_archive()
94-
9512

9613
if __name__ == '__main__':
97-
start_time = time.time()
9814
parser = argparse.ArgumentParser()
9915
parser.add_argument('--repo_path', '-p', default='.', help='repo path')
100-
parser.add_argument('--submodule', '-s', default='all',
101-
help='Submodules to update. By default update all submodules. '
102-
'For multiple submodules, separate them with `;`. '
103-
'`all` and `none` are special values that indicates we fetch all / none submodules')
16+
parser.add_argument(
17+
'--submodule',
18+
'-s',
19+
default='all',
20+
help='Submodules to update. By default update all submodules. '
21+
'For multiple submodules, separate them with `;`. '
22+
'`all` and `none` are special values that indicates we fetch all / none submodules',
23+
)
10424
args = parser.parse_args()
105-
if args.submodule == 'none':
106-
print("don't need to update submodules")
107-
exit(0)
108-
if args.submodule == 'all':
109-
_submodules = []
110-
else:
111-
_submodules = args.submodule.split(';')
112-
update_submodule(os.path.join(args.repo_path, '.gitmodules'), _submodules)
25+
26+
print('This script is deprecated, please use the following git command with gitlab cache `.git/modules` instead.')
27+
print('Calling `git submodule update --init --depth=1` ...')
28+
29+
start_time = time.time()
30+
subprocess.check_call(
31+
['git', 'submodule', 'update', '--init', '--depth=1'], stdout=sys.stdout, stderr=sys.stderr, cwd=args.repo_path
32+
)
11333
print('total time spent on update submodule: {:.02f}s'.format(time.time() - start_time))

0 commit comments

Comments
 (0)