Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gitlab-ci 配置 #116

Open
huixisheng opened this issue Jan 26, 2021 · 1 comment
Open

gitlab-ci 配置 #116

huixisheng opened this issue Jan 26, 2021 · 1 comment

Comments

@huixisheng
Copy link
Owner

huixisheng commented Jan 26, 2021

最佳实践

stages:
  - install-packages
  - lint
  - unit-test

cache:
  # 缓存没有被 git 跟踪的文件
  untracked: true
  policy: pull-push
  # https://docs.gitlab.com/ee/ci/caching/
  # https://docs.gitlab.com/ce/ci/yaml/README.html#cache
  # GitLab CI/CD pipeline configuration reference | GitLab [https://docs.gitlab.com/ee/ci/yaml/README.html#cachekeyfiles](https://docs.gitlab.com/ee/ci/yaml/README.html#cachekeyfiles)
  key:
    files:
      - yarn.lock
    prefix: ${CI_JOB_NAME}
  paths:
    - node_modules

install-packages:
  stage: install-packages
  cache:
    policy: pull-push
    paths:
      - node_modules
  tags:
    - unit-test
  script:
    - yarn --silent

unit-test:
  stage: unit-test
  cache:
    policy: pull
    paths:
      - node_modules
  script:
    - yarn test
  tags:
    - unit-test
  only:
    - master
    - /^release.*$/
    - /^feature.*$/
    - merge_requests
  coverage: /All files\s*\|\s*([\d\.]+)/

lint:
  stage: lint
  only:
    - master
    - /^release.*$/
    - /^feature.*$/
    - merge_requests
  cache:
    policy: pull
    paths:
      - node_modules
  script:
    - yarn lint
  tags:
    - unit-test


历史方案

每次要修改 NODE_MODULES_VERSION 还是比较麻烦的

# 定义 stages
stages:
  - install-packages
  - lint
  - unit-test

# https://docs.gitlab.com/ee/ci/variables/#using-predefined-environment-variables
variables:
  NODE_MODULES_VERSION: "project-1.0.0"

cache:
  untracked: true
  policy: pull-push
  # https://docs.gitlab.com/ee/ci/caching/
  # https://docs.gitlab.com/ce/ci/yaml/README.html#cache
  key: "$NODE_MODULES_VERSION"
  paths:
    - node_modules

install-packages:
  stage: install-packages
  cache:
    policy: pull-push
    paths:
      - node_modules
  # 根据自己实际情况配置
  tags:
    - unit-test
  script:
    - yarn --silent

unit-test:
  stage: unit-test
  # https://segmentfault.com/a/1190000016483568
  cache:
    policy: pull
    paths:
      - node_modules
  script:
    - yarn test
  # 根据自己实际情况配置
  tags:
    - unit-test
  only:
    - master
    - /^release.*$/
    - /^feature.*$/
    - merge_requests
  coverage: /All files\s*\|\s*([\d\.]+)/

lint:
  stage: lint
  # https://segmentfault.com/a/1190000010442764#item-1-1
  only:
    - master
    - /^release.*$/
    - /^feature.*$/
    - merge_requests
  cache:
    policy: pull
    paths:
      - node_modules
  script:
    - yarn lint
  # 根据自己实际情况配置
  tags:
    - unit-test
@huixisheng
Copy link
Owner Author

huixisheng commented Jan 26, 2021

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant