diff --git a/.travis.yml b/.travis.yml index 796722803..7b74136fd 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,6 +4,7 @@ language: php branches: only: - master + - trunk - develop - /^release\/*/ - /^hotfix\/\d+\.\d+(\.\d+)?(-\S*)?$/ @@ -37,6 +38,38 @@ jobs: env: LINT=1 PHPUNIT=1 - php: "nightly" env: LINT=1 PHPUNIT=1 + - stage: 🚀 deployment + name: "Deploy to Yoast-dist" + php: 7.2 + install: + - yarn global add grunt-cli + - yarn install + before_script: skip + script: + - | + if [[ ! -z "$TRAVIS_TAG" ]]; then + grunt set-version -new-version=$TRAVIS_TAG + grunt update-version + fi + - grunt artifact + if: ( tag IS present OR branch =~ /^feature\// OR branch =~ /^release\// OR branch =~ /^hotfix\// OR branch = trunk OR branch = develop ) AND type != pull_request + before_install: + - nvm install lts/* + - curl -o- -L https://yarnpkg.com/install.sh | bash + - export PATH=$HOME/.yarn/bin:$PATH + - openssl aes-256-cbc -K $encrypted_d1beccaa5494_key -iv $encrypted_d1beccaa5494_iv -in config/travis/deploy_keys/id_rsa_yoast_dist.enc -out config/travis/deploy_keys/id_rsa_yoast_dist -d + - chmod 600 config/travis/deploy_keys/id_rsa_yoast_dist + - eval $(ssh-agent -s) + - ssh-add config/travis/deploy_keys/id_rsa_yoast_dist + + # If the commit was tagged, create an artifact and push it to the distribution github + deploy: + skip_cleanup: true + provider: script + script: bash config/travis/deploy_to_dist.sh ${TRAVIS_TAG:-$TRAVIS_BRANCH} duplicate-post + on: + repo: $TRAVIS_REPO_SLUG + all_branches: true allow_failures: - php: "nightly" diff --git a/config/travis/deploy_keys/id_rsa_yoast_dist.enc b/config/travis/deploy_keys/id_rsa_yoast_dist.enc new file mode 100644 index 000000000..f423139d7 Binary files /dev/null and b/config/travis/deploy_keys/id_rsa_yoast_dist.enc differ diff --git a/config/travis/deploy_to_dist.sh b/config/travis/deploy_to_dist.sh new file mode 100755 index 000000000..924419478 --- /dev/null +++ b/config/travis/deploy_to_dist.sh @@ -0,0 +1,66 @@ +#!/usr/bin/env bash + +###################### +## Deployment script # +###################### +## arg 1: git tag ## +## arg 2: repo-name ## +###################### + +set -ex + +if [ -z "$1" ]; then + echo 'The first argument should be the version you want to deploy to dist.' + exit 1 +fi + +if [ -z "$2" ]; then + echo 'The second argument should be the repo name.' + exit 1 +fi + +# Repo to deploy to: +USER="Yoast-dist" +REPO=$2 +REPO_URL="git@github.com:$USER/$REPO.git" + +# Get the latest tag. +lastTag=$1 +branch="master" +mainDir=$(pwd) + +if [[ $lastTag =~ ^feature/* || $lastTag =~ ^release/* || $lastTag =~ ^hotfix/* || $lastTag == "develop" || $lastTag == "trunk" ]]; then + branch=$lastTag +fi + +# Clone the dist repo. +rm -rf ./dist-repo +git clone ${REPO_URL} dist-repo +cd dist-repo +git checkout $branch 2>/dev/null || git checkout -b $branch +cd .. + +# Copy the git folder with the entire history. +cp -r ./dist-repo/.git ./artifact +cp composer.json ./artifact + +# Remove the vendor directory from the artifact, composer will generate it's own autoload. +rm -rf ./artifact/vendor + +# Navigate to the to be committed folder. +cd ./artifact + +# Commit the files. +git add -A + +# If it's a feature, release or trunk branch. +if [[ $lastTag =~ ^feature/* || $lastTag =~ ^release/* || $lastTag =~ ^hotfix/* || $lastTag == "develop" || $lastTag == "trunk" ]]; then + git commit --allow-empty -m "${TRAVIS_COMMIT_MESSAGE}" +else + git commit -m "Release ${lastTag}" + # Tag the commit. + git tag ${lastTag} +fi + +# Push to remote. +git push -u origin $branch --tags