对于Angular项目,之前处理一个ticket的流程我们的做法:
npm start
npm run lint
npm run test
npm run build
tar -zcvf oneportal.gz -C dist .
每处理完一个任务都得搞一遍是不是很麻烦?重复而且效率低
这种事情完全可以交给CircleCI来处理。 CircleCI的好处(截止当前的政策2019.2):
Angular项目根目录新建.circleci
目录(注意以点开头),然后在这个目录里面再新建config.yml
文件
下面是我正在使用的配置,具体语法可以见官方介绍
# Check https://circleci.com/docs/2.0/language-javascript/ for more details
#
# See: https://github.com/ci-samples/angular-cli-circleci/blob/master/.circleci/config.yml
version: 2
jobs:
build:
docker:
# Specify service dependencies here if necessary
# CircleCI maintains a library of pre-built images
# documented at https://circleci.com/docs/2.0/circleci-images/
# specify the version you desire here
# - image: circleci/node:10.14-browsers
- image: finleyma/circleci-nodejs-browser-awscli
working_directory: ~/repo
# https://circleci.com/docs/2.0/env-vars/
environment:
ANGULAR_BUILD_DIR: ~/repo/dist
steps:
- checkout
# Download and cache dependencies
- restore_cache:
keys:
- v1-dependencies-{{ checksum "package.json" }}
# fallback to using the latest cache if no exact match is found
- v1-dependencies-
- run:
name: install-dependencies
command: npm install
- run: node -v
- run: npm -v
- run: npm run lint
- run: npm run ci-test
- run: npm run ci-build
- run: tar -zcvf oneportal.gz -C dist .
- save_cache:
paths:
- node_modules
key: v1-dependencies-{{ checksum "package.json" }}
- run: aws --version
- run:
name: upload-to-aws-s3
command: 'aws s3 cp oneportal.gz s3://your-aws-bucket/path/ --region us-east-1'
workflows:
version: 2
build-deploy:
jobs:
- build:
filters:
branches:
only: daily-build
我需要解释几点:
npm run ci-test
和npm run ci-build
需要在项目的package.json定义好,加入了一些参数,比如不输出过程,和加入环境参数配置 "start": "npm run proxy",
...
"build": "ng build --prod",
"test": "ng test --configuration=testing",
"ci-build": "node --max_old_space_size=4096 node_modules/@angular/cli/bin/ng build --configuration=dev --watch=false --progress=false",
"ci-test": "ng test --configuration=testing --watch=false --browsers=ChromeHeadless --progress=false",
"lint": "ng lint",
当然,你可以直接通过SSH将项目传到站点服务器部署。也需要在后台配置下访问服务器的Key。