项目作者: wp-content-framework

项目描述 :
Scripts for Travis CI Test
高级语言: Shell
项目地址: git://github.com/wp-content-framework/ci-helper.git
创建时间: 2019-06-26T07:07:11Z
项目社区:https://github.com/wp-content-framework/ci-helper

开源协议:MIT License

下载


Scripts for Travis CI

Update dependencies
CodeFactor
License: MIT

Table of Contents

Details


Overview

  • Code check
    • PHP
      • PHP_CodeSniffer
      • PHPMD
    • JavaScript
      • ESLint
  • Test
    • PHP
      • PHPUnit
    • JavaScript
      • Jest
  • Coverage
    • Codecov
  • Deploy
    • GitHub releases
    • GitHub pages
    • WP Directory

Usage

0. Prepare composer.json, package.json

composer.json

  • require-dev
    1. {
    2. "require-dev": {
    3. "squizlabs/php_codesniffer": "*",
    4. "wp-coding-standards/wpcs": "*",
    5. "phpmd/phpmd": "^2.6",
    6. "phpcompatibility/phpcompatibility-wp": "*",
    7. "dealerdirect/phpcodesniffer-composer-installer": "^0.5.0",
    8. "roave/security-advisories": "dev-master",
    9. "phake/phake": "^2.3 || ^3.1",
    10. "phpunit/phpunit": "^4.8 || ^5.7 || ^7.5"
    11. }
    12. }
  • scripts
    1. {
    2. "scripts": {
    3. "phpunit": [
    4. "phpunit"
    5. ],
    6. "phpcs": [
    7. "phpcs --standard=./phpcs.xml"
    8. ],
    9. "fix": [
    10. "phpcbf --standard=./phpcs.xml"
    11. ],
    12. "phpmd": [
    13. "phpmd ./src/,./configs/,./tests/ ansi phpmd.xml"
    14. ]
    15. }
    16. }

    package.json

  • scripts
    1. {
    2. "scripts": {
    3. "lint": "eslint src/**/**/*.js && eslint __tests__/**/**/*.js",
    4. "cover": "jest --coverage"
    5. }
    6. }

    1. Prepare scripts

    Download and run prepare.sh to create test configs.

.travis.yml

  1. before_script:
  2. - git clone --depth=1 https://github.com/wp-content-framework/ci-helper.git ci-helper
  3. - bash ci-helper/bin/prepare.sh

2. Use

Check coding style

.travis.yml

  1. jobs:
  2. fast_finish: true
  3. include:
  4. - stage: check
  5. language: php
  6. php: '7.2'
  7. script: bash tests/bin/php/phpcs.sh
  8. - stage: check
  9. language: php
  10. php: '7.2'
  11. script: bash tests/bin/php/phpmd.sh
  12. - stage: check
  13. language: node_js
  14. node_js: '11'
  15. dist: trusty
  16. script: bash tests/bin/js/js-lint.sh

Test

.travis.yml

  1. - stage: test
  2. language: php
  3. php: '7.2'
  4. env: WP_VERSION=latest
  5. script: bash tests/bin/php/wp-test.sh
  6. - stage: test
  7. language: php
  8. php: '7.2'
  9. env:
  10. - WP_VERSION=5.2
  11. - WP_MULTISITE=1
  12. script: bash tests/bin/php/wp-test.sh
  13. - stage: test
  14. language: node_js
  15. node_js: '11'
  16. dist: trusty
  17. script: bash tests/bin/js/js-test.sh

SVN diff

.travis.yml

  1. - stage: prepare
  2. language: node_js
  3. node_js: '11'
  4. dist: trusty
  5. script:
  6. - source tests/bin/deploy/env.sh
  7. - bash tests/bin/deploy/wp-check-diff.sh

Deploy

  • GitHub releases
  1. Go to Personal access tokens.
  2. Generate token which has repo scope.
  3. Run travis encrypt command to encrypt the token (Details).
    like travis encrypt "<GitHub Token>" --com -r <owner>/<repo>

or use travis setup releases command.

.travis.yml

  1. - stage: deploy
  2. language: node_js
  3. node_js: '11'
  4. dist: trusty
  5. script: skip
  6. before_deploy:
  7. - source tests/bin/deploy/env.sh
  8. - bash tests/bin/deploy/create.sh
  9. deploy:
  10. provider: releases
  11. skip_cleanup: true
  12. name: ${RELEASE_TITLE}
  13. tag_name: ${RELEASE_TAG}
  14. file: ${RELEASE_FILE}
  15. api_key:
  16. secure: <encrypted token>
  17. overwrite: true
  18. on:
  19. tags: true
  • GitHub pages
  1. Go to Personal access tokens.
  2. Generate token which has repo scope and set as Environment Variables GITHUB_TOKEN in the settings page.
  3. Create script bin/gh-pages/setup.sh, bin/gh-pages/pre_install.sh or bin/gh-pages/pre_setup.sh to setup assets.

.travis.yml

  1. - stage: deploy
  2. language: node_js
  3. node_js: '11'
  4. dist: trusty
  5. env:
  6. - GH_PAGES_PLUGIN_SCRIPT="./index.min.js"
  7. - GH_PAGES_PLUGIN_STYLE="./index.css"
  8. - GH_PAGES_TITLE="Test"
  9. - GH_PAGES_TEMPLATE=gutenberg
  10. - GH_PAGES_TRACKING_ID=UA-XXXXXXXX-X
  11. script: skip
  12. before_deploy:
  13. - source tests/bin/deploy/env.sh
  14. - bash tests/bin/deploy/gh-pages.sh
  15. deploy:
  16. provider: pages
  17. skip_cleanup: true
  18. github_token: ${GITHUB_TOKEN}
  19. keep_history: true
  20. local_dir: ${GH_PAGES_DIR}
  21. on:
  22. branch: master
  • WP Directory
  1. Set Environment Variables SVN_USER and SVN_PASS in the settings page

.travis.yml

  1. - stage: deploy
  2. language: node_js
  3. node_js: '11'
  4. dist: trusty
  5. script: skip
  6. before_deploy:
  7. - source tests/bin/deploy/env.sh
  8. deploy:
  9. provider: script
  10. skip_cleanup: true
  11. script: bash tests/bin/deploy/wp-release.sh
  12. on:
  13. tags: true

3. Slack

  1. Install Travis CI slack app and get Token.
  2. Run travis encrypt command to encrypt the token.
    like travis encrypt "<account>:<token>" --com -r <owner>/<repo>

.travis.yml

  1. notifications:
  2. email: false
  3. slack:
  4. secure: <encrypted token>

Check List

  • composer.json
    • require
    • scripts
  • package.json
    • scripts
  • .travis.yml
    • before_script
    • jobs
      • Check coding style
      • Test
      • SVN diff
      • Deploy
        • GitHub release
          • GITHUB_TOKEN
        • GitHub pages
          • GITHUB_TOKEN
          • bin/gh-pages/plugin.sh
        • WP Directory
          • SVN_USER
          • SVN_PASS
    • Slack
      • SLACK_TOKEN

Sample Plugins

Test Travis