Skip to content

Instantly share code, notes, and snippets.

@cyberwani
Forked from swashata/.gitlab-ci.yml
Created March 30, 2023 17:09
Show Gist options
  • Save cyberwani/5b1f90239d3820ca310a40bde1ab8a11 to your computer and use it in GitHub Desktop.
Save cyberwani/5b1f90239d3820ca310a40bde1ab8a11 to your computer and use it in GitHub Desktop.

Revisions

  1. @swashata swashata created this gist Jul 4, 2020.
    136 changes: 136 additions & 0 deletions .gitlab-ci.yml
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,136 @@
    # Our base image
    image: registry.gitlab.com/wpquark/docker-containers/php-node:2.0.0-php-7.3-node-12.13.0

    # Select what we should cache
    cache:
    key: "$CI_COMMIT_REF_SLUG-$CI_JOB_NAME"
    paths:
    - .yarn-cache
    - .composer-cache

    # Our stages
    stages:
    - test
    - build
    - deploy

    variables:
    YARN_CACHE_FOLDER: "$CI_PROJECT_DIR/.yarn-cache"
    COMPOSER_CACHE_DIR: "$CI_PROJECT_DIR/.composer-cache"
    MYSQL_DATABASE: "wp_wpeform_test"
    MYSQL_ROOT_PASSWORD: "12345678"

    test:javascript:
    stage: test
    tags:
    - wordpress
    image: registry.gitlab.com/wpquark/docker-containers/php-node:2.0.0-php-7.3-node-12.13.0
    before_script:
    - yarn install --frozen-lockfile
    script:
    - yarn lint
    - yarn test
    - php scripts/coverage-shouter.php -sjs
    - bash <(curl -s https://codecov.io/bash) -F client

    # We test on php7.1, php7.2 and php7.3, stripped down here
    # We generate code-cverage here only
    test:php73:
    stage: test
    tags:
    - wordpress
    image: registry.gitlab.com/wpquark/docker-containers/php-node:2.0.0-php-7.3-node-12.13.0
    services:
    - mariadb:10.3
    before_script:
    - yarn install --frozen-lockfile
    - composer install
    - vendor/bin/pcov clobber
    script:
    - yarn phpcs
    - yarn phpunit:install "$MYSQL_DATABASE" root "$MYSQL_ROOT_PASSWORD" mariadb latest true
    # - yarn phpunit
    - yarn phpunit:ci
    - php scripts/coverage-shouter.php -sphp
    - bash <(curl -s https://codecov.io/bash) -F server
    artifacts:
    paths:
    - coverage/phpunit
    expire_in: 2 days

    # Build WordPress plugin file
    build:
    stage: build
    tags:
    - wordpress
    image: registry.gitlab.com/wpquark/docker-containers/php-node:1.1.0-php-7.3-node-10.15.3
    before_script:
    - yarn install --frozen-lockfile
    # install production dependency and optimize autoload
    # https://getcomposer.org/doc/articles/autoloader-optimization.md
    - composer install --no-dev --optimize-autoloader
    script:
    - yarn build
    - yarn archive
    artifacts:
    paths:
    - package/wp-eform.zip
    expire_in: 1 week
    only:
    - master@wpquark/wp-eform.io/wp-eform

    # And we do continuous deployment
    deploy-staging:
    stage: deploy
    image: registry.gitlab.com/wpquark/docker-containers/php-node:1.1.0-php-7.3-node-10.15.3
    tags:
    - wordpress
    before_script:
    - eval $(ssh-agent -s)
    - '[[ -f /.dockerenv ]] && echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config'
    script:
    # Make sure we add the Staging Key so that we can SSH
    - ssh-add <(cat "$STAGING_KEY")
    # Delete and recreate the temporary directory for copying
    - ssh -p<PORT> [email protected] "rm -rf ~/tmp_wpeform && mkdir -p ~/tmp_wpeform"
    # Copy the distribution ZIP
    - scp -P<PORT> package/wp-eform.zip [email protected]:~/tmp_wpeform
    # SSH and Delete the current plugin and unzip the new build
    - ssh -p<PORT> [email protected] "rm -rf ~/public_html/wp-content/plugins/wp-eform && unzip ~/tmp_wpeform/wp-eform.zip -d ~/public_html/wp-content/plugins"
    environment:
    name: staging
    url: https://staging.wpeform.io/wp-admin/admin.php?page=wpeform#/dashboard
    dependencies:
    - build
    only:
    - master@wpquark/wp-eform.io/wp-eform

    # Deploy to production but manually
    deploy-production:
    stage: deploy
    image: registry.gitlab.com/wpquark/docker-containers/php-node:1.1.0-php-7.3-node-10.15.3
    tags:
    - wordpress
    before_script:
    - eval $(ssh-agent -s)
    - '[[ -f /.dockerenv ]] && echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config'
    script:
    # Make sure we add the Staging Key so that we can SSH
    - ssh-add <(cat "$PRODUCTION_KEY")
    # Delete and recreate the temporary directory for copying
    - ssh -p<PORT> [email protected] "rm -rf ~/tmp_wpeform && mkdir -p ~/tmp_wpeform"
    # Copy the distribution ZIP
    - scp -P<PORT> package/wp-eform.zip [email protected]:~/tmp_wpeform
    # SSH and Delete the current plugin and unzip the new build
    - ssh -p<PORT> [email protected] "rm -rf ~/public_html/wp-content/plugins/wp-eform && unzip ~/tmp_wpeform/wp-eform.zip -d ~/public_html/wp-content/plugins"
    environment:
    name: production
    url: https://wpeform.io/wp-admin/admin.php?page=wpeform#/dashboard
    dependencies:
    - build
    when: manual
    only:
    - master@wpquark/wp-eform.io/wp-eform


    # Just like above we can deploy to any server.
    4 changes: 4 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,4 @@
    In GitLab Repository, go to Settings > CI/CD and add the following variable

    - `STAGING_KEY`: Private key to ssh into your server. Configure your server with the public key to accept it.
    - `PRODUCTION_KEY`: Same as before, but for your production server.