From 876a7088341e03ed2ac5f54cc530666606b935f6 Mon Sep 17 00:00:00 2001 From: felinae98 <731499577@qq.com> Date: Fri, 18 Feb 2022 20:01:20 +0800 Subject: [PATCH] run when pr --- .circleci/config.yml | 218 ++++--------------------------------------- .circleci/main.yml | 211 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 227 insertions(+), 202 deletions(-) create mode 100644 .circleci/main.yml diff --git a/.circleci/config.yml b/.circleci/config.yml index e9cc9c3..4df4806 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -1,206 +1,20 @@ +setup: true version: 2.1 - orbs: - # The python orb contains a set of prepackaged CircleCI configuration you can use repeatedly in your configuration files - # Orb commands and jobs help you with common scripting around a language/tool - # so you dont have to copy and paste it everywhere. - # See the orb documentation here: https://circleci.com/developer/orbs/orb/circleci/python - python: circleci/python@1.4 - node: circleci/node@4.7.0 - # poetry: frameio/poetry@0.21.0 - swissknife: roopakv/swissknife@0.59.0 - docker: circleci/docker@1.7.0 - docker-cache: cci-x/docker-registry-image-cache@0.2.0 - codecov: codecov/codecov@3.2.2 - + continuation: circleci/continuation@0.2.0 workflows: - build-test-publish: + setup: jobs: - - build-frontend: - filters: - tags: - only: /.*/ - - test: - requires: - - build-frontend - filters: - tags: - only: /.*/ - - build: - requires: - - test - filters: - branches: - ignore: /.*/ - tags: - only: /^v.*/ - - publish-pypi: - requires: - - build - filters: - branches: - ignore: /.*/ - tags: - only: /^v.*/ - - publish-github-release: - requires: - - build - filters: - branches: - ignore: /.*/ - tags: - only: /^v.*/ - - docker/publish: &docker-push - name: "docker/publish-release" - dockerfile: docker/Dockerfile_with_frontend - after_checkout: - - attach_workspace: - at: . - - restore_cache: - key: frontend_build_res-{{ checksum "frontend.hash" }} - requires: - - test - filters: - branches: - ignore: /.*/ - tags: - only: /^v.*/ - context: - - docker - image: $CIRCLE_PROJECT_USERNAME/$CIRCLE_PROJECT_REPONAME - cache_from: '$CIRCLE_PROJECT_USERNAME/$CIRCLE_PROJECT_REPONAME:${CIRCLE_TAG}' - tag: latest,${CIRCLE_TAG} - update-description: true - docker-username: DOCKERHUB_USERNAME - docker-password: DOCKERHUB_PASSWORD - - docker/publish: - <<: *docker-push - name: "docker/publish-debug" - filters: - tags: - ignore: /.*/ - tag: ${CIRCLE_BRANCH} - cache_from: '$CIRCLE_PROJECT_USERNAME/$CIRCLE_PROJECT_REPONAME:${CIRCLE_BRANCH}' - - docker/publish: - <<: *docker-push - dockerfile: docker/Dockerfile_with_frontend_sentry - name: "docker/publish-sentry" - tag: sentry,${CIRCLE_TAG}-sentry - cache_from: '$CIRCLE_PROJECT_USERNAME/$CIRCLE_PROJECT_REPONAME:sentry' - - docker/publish: - <<: *docker-push - name: "docker/publish-debug-sentry" - dockerfile: docker/Dockerfile_with_frontend_sentry - filters: - branches: - only: [main, dev] - tags: - ignore: /.*/ - tag: ${CIRCLE_BRANCH}-sentry - cache_from: '$CIRCLE_PROJECT_USERNAME/$CIRCLE_PROJECT_REPONAME:${CIRCLE_BRANCH}-sentry' - -jobs: - build-frontend: - docker: - - image: cimg/node:16.13.0 - steps: - - checkout - - run: - name: Get hash of frontend code - command: | - find ./admin-frontend/src -type f -exec md5sum {} + | LC_ALL=C sort > frontend.hash - md5sum ./admin-frontend/yarn.lock >> frontend.hash - cat frontend.hash - - persist_to_workspace: - root: . - paths: - - "frontend.hash" - - restore_cache: - key: frontend_build_res-{{ checksum "frontend.hash" }} - - run: - name: Check cache - command: | - if [ -f ./src/plugins/nonebot_bison/admin_page/dist/index.html ]; then - echo "frontend cache exists" - circleci-agent step halt - else - echo "no such cache, build will begin" - fi - - node/install-packages: - app-dir: ./admin-frontend - pkg-manager: yarn - - run: - name: yarn build - working_directory: ./admin-frontend - command: yarn build - - save_cache: - paths: - - ./src/plugins/nonebot_bison/admin_page/dist/ - key: frontend_build_res-{{ checksum "frontend.hash" }} - test: - docker: - - image: cimg/python:3.9 - - image: browserless/chrome - # environment: - # BISON_BROWSER: wsc://localhost:3000 - steps: - - checkout - # - run: sed -e '41,45d' -i pyproject.toml - - python/install-packages: - pkg-manager: poetry - - run: - name: Install browser - command: poetry run playwright install-deps && poetry run playwright install chromium - - run: - name: Coverage test - command: poetry run pytest --cov-report html --cov-report xml --cov=./src/plugins/nonebot_bison --junitxml=test-results/junit.xml -k 'not compare' - - store_test_results: - path: test-results - - run: - name: Collect coverage - command: poetry run coverage html --include='src/*' - - codecov/upload: - file: coverage.xml - - store_artifacts: - path: htmlcov - build: - docker: - - image: cimg/python:3.9 - steps: - - checkout - - attach_workspace: - at: . - - restore_cache: - key: frontend_build_res-{{ checksum "frontend.hash" }} - - run: poetry build - - store_artifacts: - path: "dist" - - persist_to_workspace: - root: . - paths: - - "dist" - publish-pypi: - docker: - - image: cimg/python:3.9 - steps: - - checkout - - attach_workspace: - at: . - - run: - command: poetry publish -u $PYPI_USERNAME -p $PYPI_PASSWORD - name: Publish to Pypi - - publish-github-release: - docker: - - image: circleci/golang:1.17 - steps: - - checkout - - attach_workspace: - at: . - - run: - name: Publish to Github Release - command: | - go install github.com/tcnksm/ghr@latest - VERSION=$(cat pyproject.toml | grep version | sed 's/version = "\([0-9\.]*\)"/\1/') - ghr -t ${GITHUB_TOKEN} -u ${CIRCLE_PROJECT_USERNAME} -r ${CIRCLE_PROJECT_REPONAME} -c ${CIRCLE_SHA1} -delete ${VERSION} ./dist - + - continuation/continue: + configuration_path: ".circleci/main.yml" + parameters: /home/circleci/params.json + pre-steps: + - run: + command: | + if [ -z "${CIRCLE_PULL_REQUEST##*/}" ] + then + IS_PR=false + else + IS_PR=true + fi + echo '{ "is_pr": '$IS_PR' }' >> /home/circleci/params.json diff --git a/.circleci/main.yml b/.circleci/main.yml new file mode 100644 index 0000000..2882fe9 --- /dev/null +++ b/.circleci/main.yml @@ -0,0 +1,211 @@ +version: 2.1 + +orbs: + # The python orb contains a set of prepackaged CircleCI configuration you can use repeatedly in your configuration files + # Orb commands and jobs help you with common scripting around a language/tool + # so you dont have to copy and paste it everywhere. + # See the orb documentation here: https://circleci.com/developer/orbs/orb/circleci/python + python: circleci/python@1.4 + node: circleci/node@4.7.0 + # poetry: frameio/poetry@0.21.0 + swissknife: roopakv/swissknife@0.59.0 + docker: circleci/docker@1.7.0 + docker-cache: cci-x/docker-registry-image-cache@0.2.0 + codecov: codecov/codecov@3.2.2 + +workflows: + pull-request: + when: << pipeline.parameters.is_pr >> + jobs: + - build-frontend + - test + build-test-publish: + jobs: + - build-frontend: + filters: + tags: + only: /.*/ + - test: + requires: + - build-frontend + filters: + tags: + only: /.*/ + - build: + requires: + - test + filters: + branches: + ignore: /.*/ + tags: + only: /^v.*/ + - publish-pypi: + requires: + - build + filters: + branches: + ignore: /.*/ + tags: + only: /^v.*/ + - publish-github-release: + requires: + - build + filters: + branches: + ignore: /.*/ + tags: + only: /^v.*/ + - docker/publish: &docker-push + name: "docker/publish-release" + dockerfile: docker/Dockerfile_with_frontend + after_checkout: + - attach_workspace: + at: . + - restore_cache: + key: frontend_build_res-{{ checksum "frontend.hash" }} + requires: + - test + filters: + branches: + ignore: /.*/ + tags: + only: /^v.*/ + context: + - docker + image: $CIRCLE_PROJECT_USERNAME/$CIRCLE_PROJECT_REPONAME + cache_from: '$CIRCLE_PROJECT_USERNAME/$CIRCLE_PROJECT_REPONAME:${CIRCLE_TAG}' + tag: latest,${CIRCLE_TAG} + update-description: true + docker-username: DOCKERHUB_USERNAME + docker-password: DOCKERHUB_PASSWORD + - docker/publish: + <<: *docker-push + name: "docker/publish-debug" + filters: + tags: + ignore: /.*/ + tag: ${CIRCLE_BRANCH} + cache_from: '$CIRCLE_PROJECT_USERNAME/$CIRCLE_PROJECT_REPONAME:${CIRCLE_BRANCH}' + - docker/publish: + <<: *docker-push + dockerfile: docker/Dockerfile_with_frontend_sentry + name: "docker/publish-sentry" + tag: sentry,${CIRCLE_TAG}-sentry + cache_from: '$CIRCLE_PROJECT_USERNAME/$CIRCLE_PROJECT_REPONAME:sentry' + - docker/publish: + <<: *docker-push + name: "docker/publish-debug-sentry" + dockerfile: docker/Dockerfile_with_frontend_sentry + filters: + branches: + only: [main, dev] + tags: + ignore: /.*/ + tag: ${CIRCLE_BRANCH}-sentry + cache_from: '$CIRCLE_PROJECT_USERNAME/$CIRCLE_PROJECT_REPONAME:${CIRCLE_BRANCH}-sentry' + +jobs: + build-frontend: + docker: + - image: cimg/node:16.13.0 + steps: + - checkout + - run: + name: Get hash of frontend code + command: | + find ./admin-frontend/src -type f -exec md5sum {} + | LC_ALL=C sort > frontend.hash + md5sum ./admin-frontend/yarn.lock >> frontend.hash + cat frontend.hash + - persist_to_workspace: + root: . + paths: + - "frontend.hash" + - restore_cache: + key: frontend_build_res-{{ checksum "frontend.hash" }} + - run: + name: Check cache + command: | + if [ -f ./src/plugins/nonebot_bison/admin_page/dist/index.html ]; then + echo "frontend cache exists" + circleci-agent step halt + else + echo "no such cache, build will begin" + fi + - node/install-packages: + app-dir: ./admin-frontend + pkg-manager: yarn + - run: + name: yarn build + working_directory: ./admin-frontend + command: yarn build + - save_cache: + paths: + - ./src/plugins/nonebot_bison/admin_page/dist/ + key: frontend_build_res-{{ checksum "frontend.hash" }} + test: + docker: + - image: cimg/python:3.9 + - image: browserless/chrome + # environment: + # BISON_BROWSER: wsc://localhost:3000 + steps: + - checkout + # - run: sed -e '41,45d' -i pyproject.toml + - python/install-packages: + pkg-manager: poetry + - run: + name: Install browser + command: poetry run playwright install-deps && poetry run playwright install chromium + - run: + name: Coverage test + command: poetry run pytest --cov-report html --cov-report xml --cov=./src/plugins/nonebot_bison --junitxml=test-results/junit.xml -k 'not compare' + - store_test_results: + path: test-results + - run: + name: Collect coverage + command: poetry run coverage html --include='src/*' + - codecov/upload: + file: coverage.xml + - store_artifacts: + path: htmlcov + build: + docker: + - image: cimg/python:3.9 + steps: + - checkout + - attach_workspace: + at: . + - restore_cache: + key: frontend_build_res-{{ checksum "frontend.hash" }} + - run: poetry build + - store_artifacts: + path: "dist" + - persist_to_workspace: + root: . + paths: + - "dist" + publish-pypi: + docker: + - image: cimg/python:3.9 + steps: + - checkout + - attach_workspace: + at: . + - run: + command: poetry publish -u $PYPI_USERNAME -p $PYPI_PASSWORD + name: Publish to Pypi + + publish-github-release: + docker: + - image: circleci/golang:1.17 + steps: + - checkout + - attach_workspace: + at: . + - run: + name: Publish to Github Release + command: | + go install github.com/tcnksm/ghr@latest + VERSION=$(cat pyproject.toml | grep version | sed 's/version = "\([0-9\.]*\)"/\1/') + ghr -t ${GITHUB_TOKEN} -u ${CIRCLE_PROJECT_USERNAME} -r ${CIRCLE_PROJECT_REPONAME} -c ${CIRCLE_SHA1} -delete ${VERSION} ./dist +