From 52c2e02d4ebc1f81b50dfaf8900fad789ac4ab78 Mon Sep 17 00:00:00 2001 From: Wu Jian Gang Date: Mon, 2 Apr 2018 19:22:25 +0800 Subject: [PATCH 1/2] feat(ci): Add init CI script --- .gitlab-ci.yml | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 .gitlab-ci.yml diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 000000000..6d542c35a --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,74 @@ +stages: + - build + - deploy + +variables: + GIT_STRATEGY: clone + +# before each job, we need to check if this job is filtered by bot stage/job filter +.apply_bot_filter: &apply_bot_filter + python $APPLY_BOT_FILTER_SCRIPT || exit 0 + +before_script: + - mkdir -p ~/.ssh + - chmod 700 ~/.ssh + - echo -n $GITLAB_KEY >> ~/.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 + +.do_nothing_before: + before_script: &do_nothing_before + # apply bot filter in before script + - *apply_bot_filter + - echo "Not setting up GitLab key, not fetching submodules" + - source tools/ci/configure_ci_environment.sh + +.build_template: &build_template + stage: build + image: ci_test + tags: + - build + +build_ssc: + <<: *build_template + artifacts: + paths: + - ./SSC/ssc_bin + expire_in: 6 mos + script: + - git clone $GITLAB_SSH_SERVER/yinling/SSC.git + - cd SSC + # try checkout same branch + - git checkout ${CI_BUILD_REF_NAME} || echo "Using default branch..." + - chmod +x gen_misc_rtos.sh + - ./gen_misc_rtos.sh + +push_master_to_github: + stage: deploy + image: $CI_DOCKER_REGISTRY/esp32-ci-env$BOT_DOCKER_IMAGE_TAG + tags: + - deploy + only: + - master + - /^release\/v/ + - /^v\d+\.\d+(\.\d+)?($|-)/ + when: on_success + dependencies: [] + variables: + GITHUB_PUSH_REFS: refs/remotes/origin/release refs/remotes/origin/master + before_script: *do_nothing_before + script: + - mkdir -p ~/.ssh + - chmod 700 ~/.ssh + - echo -n $GH_PUSH_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 git@github.com:espressif/ESP8266_RTOS_SDK.git + # What the next line of script does: goes through the list of refs for all branches we push to github, + # generates a snippet of shell which is evaluated. The snippet checks CI_COMMIT_SHA against the SHA + # (aka objectname) at tip of each branch, and if any SHAs match then it checks out the local branch + # and then pushes that ref to a corresponding github branch + - eval $(git for-each-ref --shell bash --format 'if [ $CI_COMMIT_SHA == %(objectname) ]; then git checkout -B %(refname:strip=3); git push --follow-tags github %(refname:strip=3); fi;' $GITHUB_PUSH_REFS) From 3f43e12afa3697219dda49b580786e830a5b59f4 Mon Sep 17 00:00:00 2001 From: Wu Jian Gang Date: Tue, 3 Apr 2018 11:06:26 +0800 Subject: [PATCH 2/2] feat(ci): Add shell of configure ci environment --- tools/ci/configure_ci_environment.sh | 32 ++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 tools/ci/configure_ci_environment.sh diff --git a/tools/ci/configure_ci_environment.sh b/tools/ci/configure_ci_environment.sh new file mode 100644 index 000000000..a92600e92 --- /dev/null +++ b/tools/ci/configure_ci_environment.sh @@ -0,0 +1,32 @@ +# This file is sourced in to the CI environment +# in .gitlab-ci.yml +# + +# Sets the error behaviour options for shell throughout the CI environment +# +set -o errexit # Exit if command failed. +set -o pipefail # Exit if pipe failed. + +# we can use the appropriate secret variable for debugging +[ ! -z $DEBUG_SHELL ] && set -x + +[ -z $CI_COMMIT_REF_NAME ] && echo "This internal script should only be run by a Gitlab CI runner." && exit 1 + +# Sets IS_PUBLIC and IS_PRIVATE based on branch type +# +# Public branches are: +# release branches - start with release/ +# release tags - look like vXX.YY or vXX.YY.ZZ with an optional dash followed by anything on the end +# master branch +# +# These POSIX REs are equivalent to the REs in some "only:" sections of the gitlab-ci.yml file +# +REF=$CI_COMMIT_REF_NAME +if [[ $REF = "master" || $REF =~ ^release/v || $REF =~ ^v[0-9]+\.[0-9]+(\.[0-9]+)?(-|$) ]]; then + export IS_PRIVATE= + export IS_PUBLIC=1 +else + export IS_PRIVATE=1 + export IS_PUBLIC= +fi +unset REF