Skip to content

Commit e04b86b

Browse files
Qinghao ShiQinghao Shi
authored andcommitted
add ci files for check the repo structure
1 parent 73f5e9f commit e04b86b

File tree

3 files changed

+84
-6
lines changed

3 files changed

+84
-6
lines changed

.circleci/config.yml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,15 @@ jobs:
77
build:
88
docker:
99
- image: mbedos/mbed-os-env:stable
10-
working_directory: ~/repo
1110
steps:
1211
- checkout:
13-
path: work/sinppet/TESTS
14-
- run: mv work/sinppet/TESTS/mbed-os.lib work/
15-
- run: git clone https://github.com/ARMmbed/mbed-os.git work/mbed-os
12+
path: sinppet/TESTS
13+
- run: |
14+
cd sinppet/TESTS
15+
python3 .circleci/repo_checks.py
16+
- run: mv sinppet/TESTS/mbed-os.lib .
17+
- run: git clone https://github.com/ARMmbed/mbed-os.git mbed-os
1618
- run: |
17-
cd work
1819
mbed config root .
1920
mbed update
2021
mbed add https://github.com/c1728p9/AudioPlayer

.circleci/repo_checks.py

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
"""
2+
Copyright (c) 2016-2020 ARM Limited. All rights reserved.
3+
4+
SPDX-License-Identifier: Apache-2.0
5+
6+
Licensed under the Apache License, Version 2.0 (the "License");
7+
you may not use this file except in compliance with the License.
8+
You may obtain a copy of the License at
9+
10+
http://www.apache.org/licenses/LICENSE-2.0
11+
12+
Unless required by applicable law or agreed to in writing, software
13+
distributed under the License is distributed on an "AS IS" BASIS,
14+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
See the License for the specific language governing permissions and
16+
limitations
17+
"""
18+
19+
from pathlib import Path
20+
import glob
21+
import os.path
22+
import sys
23+
24+
level2_set= set()
25+
dup_set = set()
26+
27+
28+
def main():
29+
for filepath in Path('.').rglob('main.cpp'):
30+
level2dir=os.path.basename(os.path.dirname(filepath))
31+
level1dir=os.path.basename(os.path.dirname(os.path.dirname(filepath)))
32+
level0dir=os.path.dirname(os.path.dirname(os.path.dirname(filepath)))
33+
34+
# check if length of folder name less then 34
35+
if len(level2dir) > 34 :
36+
sys.stderr.write("ERROR: Snippet '{}' length of {} is {} exceed the requirement of 34".format(filepath,level2dir,len(level2dir)))
37+
sys.exit(1)
38+
39+
# check if folder level less than 2
40+
if level1dir == '':
41+
sys.stderr.write("ERROR: Snippet '{}' has only one level of folder, but 2 is required".format(filepath))
42+
sys.exit(1)
43+
44+
# check if folder level more than 2
45+
if level0dir != '':
46+
sys.stderr.write("ERROR: Snippet '{}' has more than two level of folders, but 2 is required".format(filepath))
47+
sys.exit(1)
48+
49+
if level2dir not in level2_set:
50+
level2_set.add(level2dir)
51+
else:
52+
dup_set.add(level2dir)
53+
54+
# check duplicated level2 folder names
55+
if len(dup_set) > 0 :
56+
for filepath in Path('.').rglob('main.cpp'):
57+
level2dir=os.path.basename(os.path.dirname(filepath))
58+
if level2dir in dup_set:
59+
sys.stderr.write("ERROR level2 name '{}' in path '{}' is has a duplicated with others".format(level2dir,filepath))
60+
sys.exit(1)
61+
62+
63+
print("All checks PASSED")
64+
65+
66+
if __name__ == "__main__":
67+
main()

README.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,12 @@
11
# Mbed OS Docs-Only Examples
2-
This repository contains example applications that currently only exist in the Mbed OS docs.
2+
This repository contains example applications snippets that currently only exist in the Mbed OS docs.
3+
4+
## Contributions
5+
6+
Contribute the the example folder need to following bellow requirements
7+
- Every individual example snippet need to contain a compile-able `main.cpp` and placed into one folder with all required files.
8+
- The path to the folder has to be in the 2 level folder structure `Repo_ROOT/<Level1>/<Level2>/main.cpp` we recommend to following our conventions: `Repo_ROOT/Category_Topic/Module_Example`
9+
- A `README.md` file in the snippet folder is optional, the main instruction and explanatory documents should be contributed to [mbed-os-docs](https://github.com/ARMmbed/mbed-os-5-docs).
10+
- the `Level2` folder name, e.g. `<Module_Example>`, need to be unique to any other `Level2` folder in this repository and contains no more than 34 characters.
11+
- The CI on this repository will check on the above criteria and also make sure the snippets able to be built
12+

0 commit comments

Comments
 (0)