-
Notifications
You must be signed in to change notification settings - Fork 94
/
Copy path.gitlab-ci.yml
160 lines (146 loc) · 5.69 KB
/
.gitlab-ci.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
stages:
- pre-check
- build
- sync
- deploy
# Avoid running duplicate pipeline
workflow:
rules:
- if: '$CI_PIPELINE_SOURCE == "merge_request_event"'
- if: '$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH'
variables:
GIT_STRATEGY: fetch
GIT_SUBMODULE_STRATEGY: recursive
SYNC_BRANCH_NAME: "ci/sync_gh_tflite-micro"
SYNC_COMMIT_MSG: "tflite-micro-sync: Update esp-tflite-micro (synced from github)"
REPO_URL: "https://${PUSH_TO_GITLAB_TOKEN_NAME}:${PUSH_TO_GITLAB_TOKEN}@gitlab.espressif.cn:6688/app-frameworks/tflite-micro-esp-examples.git"
pre-commit-mr:
stage: pre-check
image: "$CI_DOCKER_REGISTRY/pre-commit-codecheck:1"
allow_failure: true
before_script:
- echo "Skip common before script"
script:
- echo "Merge request is from ${CI_COMMIT_REF_NAME} into ${CI_MERGE_REQUEST_TARGET_BRANCH_NAME}"
- git fetch origin ${CI_MERGE_REQUEST_TARGET_BRANCH_NAME} ${CI_COMMIT_REF_NAME}
- export from_sha=$(git merge-base HEAD origin/${CI_MERGE_REQUEST_TARGET_BRANCH_NAME})
- echo "Checking changes from ${from_sha} to ${CI_COMMIT_SHA}:"
- git log --oneline ${from_sha}..${CI_COMMIT_SHA}
- echo "Modified files:"
- git diff-tree --no-commit-id --name-only -r ${from_sha} ${CI_COMMIT_SHA}
- echo "Running pre-commit:"
- pre-commit run --from ${from_sha} --to ${CI_COMMIT_SHA}
rules:
- if: '$CI_PIPELINE_SOURCE == "merge_request_event"'
tags: [build, internet]
# include:
# - project: espressif/shared-ci-dangerjs
# ref: master
# file: danger.yaml
# run-danger-mr-linter:
# before_script:
# - echo "Skip common before script"
# stage: pre-check
# tags: [build, internet]
before_script:
- mkdir -p ~/.ssh
- chmod 700 ~/.ssh
- echo -n $GITLAB_KEY_TMP > ~/.ssh/id_rsa_base64
- base64 --decode --ignore-garbage ~/.ssh/id_rsa_base64 > ~/.ssh/id_rsa
- chmod 600 ~/.ssh/id_rsa
- echo -e "Host gitlab.espressif.cn\n\tStrictHostKeyChecking no\n" >> ~/.ssh/config
.test_build: &test_build
# Build examples
- for TARGET in $EXAMPLE_TARGETS; do
- ./scripts/build_examples.sh $TARGET
- done
.build_template:
stage: build
image: espressif/idf:latest
tags:
- build
variables:
PEDANTIC_FLAGS: "-Werror -Wno-error=cpp -Werror=unused-variable -Werror=unused-but-set-variable -Werror=unused-function"
EXTRA_CFLAGS: "${PEDANTIC_FLAGS}"
EXTRA_CXXFLAGS: "${PEDANTIC_FLAGS}"
rules:
- if: '$CI_PIPELINE_SOURCE == "schedule"'
when: never
- when: always
script:
- cd ${CI_PROJECT_DIR}
# build examples
- *test_build
- cd ${CI_PROJECT_DIR}
build_idf_v5.3:
extends: .build_template
image: espressif/idf:release-v5.3
variables:
EXAMPLE_TARGETS: esp32 esp32s2 esp32s3 esp32c3 esp32c2
build_idf_v5.1:
extends: .build_template
image: espressif/idf:release-v5.1
variables:
EXAMPLE_TARGETS: esp32 esp32s2 esp32s3 esp32c3 esp32c2
build_idf_v5.0:
extends: .build_template
image: espressif/idf:release-v5.0
variables:
EXAMPLE_TARGETS: esp32 esp32s3 esp32c3 esp32c2
build_idf_v4.4:
extends: .build_template
image: espressif/idf:release-v4.4
variables:
EXAMPLE_TARGETS: esp32 esp32s3 esp32c3
.push_to_gitlab: &push_to_gitlab
# Push updated repo (synced from github) to gitlab
- git config --global user.email "[email protected]"
- git config --global user.name "Gitlab-Scheduled-GH-Sync-Job"
- git remote set-url origin ${REPO_URL}
# check - remote branch should not exist (i.e. the open MR (if any) should be merged and branch should have been deleted)
- git ls-remote --exit-code --heads ${REPO_URL} ${SYNC_BRANCH_NAME} && echo "ERROR - ${SYNC_BRANCH_NAME} branch already exists. Is there any open MR ?" && exit 1
- git branch ${SYNC_BRANCH_NAME} 2>&1 || echo "Branch exists" && git branch -D ${SYNC_BRANCH_NAME} 2>&1 || echo "Branch deleted" && git branch ${SYNC_BRANCH_NAME} 2>&1 && echo "Branch created"
- git checkout ${SYNC_BRANCH_NAME}
- git add .
- git commit -m "${SYNC_COMMIT_MSG}"
- git push --set-upstream origin ${SYNC_BRANCH_NAME}
- git status
- git log -2
# The variable ${SYNC_BRANCH_NAME} is not getting set here (currently), so branch name is directly added for `source_branch` key
- curl --request POST --url "https://gitlab.espressif.cn:6688/api/v4/projects/2457/merge_requests" --header
"PRIVATE-TOKEN:${PUSH_TO_GITLAB_TOKEN}" --header "content-type:application/json" --data '{"title":"Sync esp-tflite-micro from github - '${CI_PIPELINE_ID}'", "source_branch":"ci/sync_gh_tflite-micro", "target_branch":"master" }'
- git checkout -
sync_from_github:on-schedule:
stage: sync
image: espressif/idf:release-v5.2
tags:
- github_sync
rules:
- if: '$CI_PIPELINE_SOURCE == "schedule" && $CI_COMMIT_BRANCH == "master"'
script:
# sync tflite-lib from github
- cd ${CI_PROJECT_DIR}
- echo "====================== Sync esp-tflite-micro from Github and push to Gitlab ======================"
- python3 -m pip install -r scripts/gh_sync_req.txt
- ./scripts/sync_from_tflite_micro.sh
# push to gitlab
- *push_to_gitlab
- echo "====================== Done ======================"
push_to_github:
stage: deploy
image: espressif/idf:release-v5.0
tags:
- deploy
when: manual
only:
- master
script:
- mkdir -p ~/.ssh
- chmod 700 ~/.ssh
- echo -n $GH_KEY > ~/.ssh/id_rsa_base64
- base64 --decode --ignore-garbage ~/.ssh/id_rsa_base64 > ~/.ssh/id_rsa
- chmod 600 ~/.ssh/id_rsa
- echo -e "Host github.com\n\tStrictHostKeyChecking no\n" >> ~/.ssh/config
- git remote remove github &>/dev/null || true
- git remote add github [email protected]:espressif/esp-tflite-micro.git
- git push github "${CI_COMMIT_SHA}:refs/heads/${CI_COMMIT_REF_NAME}"