Skip to content

Commit d866530

Browse files
committed
added new travis structure
1 parent 6403ea8 commit d866530

File tree

4 files changed

+178
-25
lines changed

4 files changed

+178
-25
lines changed

.travis.yml

Lines changed: 52 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
language: php
2-
3-
## PHP versions to test against
42
php:
53
- "7.0"
64
- "5.6"
@@ -9,29 +7,58 @@ php:
97
- "5.3"
108
- "5.2"
119
sudo: false
10+
branches:
11+
except:
12+
- "/^*-v[0-9]/"
1213
env:
13-
- WP_VERSION=latest WP_MULTISITE=0
14+
matrix:
15+
- WP_VERSION=latest WP_MULTISITE=0
16+
global:
17+
- MASTER_BRANCH=production UPSTREAM_REPO=Codeinwp/visualizer STORE_URL=https://themeisle.com
1418
install:
15-
- . $HOME/.nvm/nvm.sh
16-
- nvm install stable
17-
- nvm use stable
18-
- npm install
19-
- npm install grunt-cli -g
20-
## install PHPCS and Wordpress standards
21-
- pear install pear/PHP_CodeSniffer
22-
- mkdir $TRAVIS_BUILD_DIR/wordpress-coding-standards && curl -L https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/archive/master.tar.gz | tar xz --strip-components=1 -C wordpress-coding-standards
23-
- phpenv rehash
24-
- phpcs --config-set installed_paths $TRAVIS_BUILD_DIR/wordpress-coding-standards
25-
- phpenv rehash
26-
before_script:
27-
- bash bin/install-wp-tests.sh wordpress_test root '' localhost $WP_VERSION
28-
- export PATH="$HOME/.composer/vendor/bin:$PATH"
29-
- |
30-
if [[ ${TRAVIS_PHP_VERSION:0:2} == "7." ]]; then
31-
composer global require "phpunit/phpunit=5.7.*"
32-
fi
33-
- phpenv rehash
19+
- chmod +x bin/install-dependencies.sh
20+
- ". ./bin/install-dependencies.sh"
3421
script:
35-
grunt travis
36-
after_failure:
37-
- cat logs/phpcs.log
22+
- if [ "$TRAVIS_PULL_REQUEST" != "false" ]; then grunt travis; fi;
23+
before_deploy:
24+
- chmod +x bin/prepare-deploy.sh
25+
- ". ./bin/prepare-deploy.sh"
26+
deploy:
27+
- provider: s3
28+
access_key_id: "$AWS_ACCESS_KEY"
29+
secret_access_key: "$AWS_SECRET_KEY"
30+
bucket: "$AWS_BUCKET"
31+
skip_cleanup: true
32+
acl: public_read
33+
overwrite: true
34+
local-dir: artifact/
35+
upload-dir: "$AWS_PRODUCTS_FOLDER/$THEMEISLE_REPO/latest"
36+
on:
37+
branch: "$MASTER_BRANCH"
38+
repo: "$UPSTREAM_REPO"
39+
condition: $TRAVIS_PHP_VERSION = "7.0"
40+
- provider: s3
41+
access_key_id: "$AWS_ACCESS_KEY"
42+
secret_access_key: "$AWS_SECRET_KEY"
43+
bucket: "$AWS_BUCKET"
44+
skip_cleanup: true
45+
acl: public_read
46+
overwrite: true
47+
local-dir: artifact/
48+
upload-dir: "$AWS_PRODUCTS_FOLDER/$THEMEISLE_REPO/$THEMEISLE_VERSION"
49+
on:
50+
repo: "$UPSTREAM_REPO"
51+
branch: "$MASTER_BRANCH"
52+
condition: $TRAVIS_PHP_VERSION = "7.0"
53+
- provider: releases
54+
api_key: "$GITHUB_TOKEN"
55+
file: artifact/$THEMEISLE_REPO.zip
56+
skip_cleanup: true
57+
on:
58+
tags: false
59+
repo: "$UPSTREAM_REPO"
60+
branch: "$MASTER_BRANCH"
61+
condition: $TRAVIS_PHP_VERSION = "7.0"
62+
after_deploy:
63+
- chmod +x bin/deploy.sh
64+
- ". ./bin/deploy.sh"

bin/deploy.sh

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#!/bin/bash
2+
3+
# We run this just one time, for a first job from the buid and just at once after_deploy hook.
4+
if ! [ $AFTER_DEPLOY_RUN ] && [ "$TRAVIS_PHP_VERSION" == "7.0" ]; then
5+
6+
# Flag the run in order to not be trigged again on the next after_deploy.
7+
export AFTER_DEPLOY_RUN=1;
8+
echo " Started deploy script. ";
9+
10+
# Setup git username and email.
11+
12+
git config user.name "selul"
13+
git config user.email ${GITHUB_EMAIL}
14+
15+
# Send changelog changes to git.
16+
git checkout $MASTER_BRANCH
17+
git add -v .
18+
19+
# We use [skip ci] in message to prevent this commit to trigger the build.
20+
git commit -a -m "[AUTO][skip ci] Updating changelog for v"$THEMEISLE_VERSION
21+
git push --quiet "https://${GITHUB_TOKEN}@github.com/$UPSTREAM_REPO.git" HEAD:$MASTER_BRANCH
22+
23+
# Tag the new release.
24+
git tag -a "v$THEMEISLE_VERSION" -m "[AUTO] Release of $THEMEISLE_VERSION ";
25+
git push --quiet "https://${GITHUB_TOKEN}@github.com/$UPSTREAM_REPO.git" --tags ;
26+
sleep 5;
27+
28+
# Sends the api call for creating the release.
29+
# We use this as the travis release provider does not offer any way
30+
# to set the body of the release.
31+
API_JSON='{"tag_name": "v'$THEMEISLE_VERSION'","target_commitish": "'$MASTER_BRANCH'","name": "v'$THEMEISLE_VERSION'","body": "'$CHANGES'","draft": false,"prerelease": false}';
32+
curl -s --data "$API_JSON" "https://api.github.com/repos/$UPSTREAM_REPO/releases?access_token="$GITHUB_TOKEN > /dev/null;
33+
34+
# Send update to the store
35+
STORE_JSON='{"version": "'$THEMEISLE_VERSION'","id": "'$THEMEISLE_ID'","body": "'$CHANGES'"}';
36+
curl -s -H "Content-Type: application/json" -H "x-themeisle-auth: $THEMEISLE_AUTH" --data "$STORE_JSON" "$STORE_URL/wp-json/ti-endpoint/v1/update_changelog_new/" > /dev/null
37+
38+
# Send data to demo server.
39+
grunt sftp
40+
fi;

bin/install-dependencies.sh

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#!/bin/bash
2+
3+
# We run this on PR or on push to MASTER_BRANCH.
4+
if [ "$TRAVIS_PULL_REQUEST" != "false" ] || ( [ "$TRAVIS_EVENT_TYPE" == "push" ] && [ "$TRAVIS_REPO_SLUG" == "$UPSTREAM_REPO" ] && [ "$TRAVIS_BRANCH" == "$MASTER_BRANCH" ] ) ; then
5+
6+
. $HOME/.nvm/nvm.sh
7+
nvm install stable
8+
nvm use stable
9+
10+
npm install
11+
npm install grunt-cli -g
12+
13+
phpenv local 5.6
14+
15+
composer selfupdate 1.0.0 --no-interaction
16+
composer install --no-interaction
17+
phpenv local --unset
18+
19+
fi;
20+
# We dont install PHPCS if is not a PR.
21+
if [ "$TRAVIS_PULL_REQUEST" != "false" ]; then
22+
23+
# Install PHPCS.
24+
pear install pear/PHP_CodeSniffer
25+
26+
# Install WPCS standards.
27+
git clone -b master --depth 1 https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards.git $HOME/wordpress-coding-standards
28+
phpenv rehash
29+
phpcs --config-set installed_paths $HOME/wordpress-coding-standards
30+
phpenv rehash
31+
32+
# Install wordpress for testing.
33+
bash bin/install-wp-tests.sh wordpress_test root '' localhost $WP_VERSION
34+
export PATH="$HOME/.composer/vendor/bin:$PATH"
35+
36+
# Use phpunit 5.7 as WP dont support 6.
37+
if [[ ${TRAVIS_PHP_VERSION:0:2} == "7." ]]; then
38+
composer global require "phpunit/phpunit=5.7.*" ;
39+
fi;
40+
fi;

bin/prepare-deploy.sh

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#!/bin/bash
2+
3+
#We make sure we run this just at one before_deploy hook.
4+
if ! [ $BEFORE_DEPLOY_RUN ] && [ "$TRAVIS_PHP_VERSION" == "7.0" ]; then
5+
6+
echo " Preparing deploy. ";
7+
8+
# Flag the run.
9+
export BEFORE_DEPLOY_RUN=1;
10+
11+
# Parse the name of the repo.
12+
export THEMEISLE_REPO=$(node -pe "require('./package.json').name")
13+
14+
# Parse the version of the product.
15+
16+
export THEMEISLE_VERSION=$(node -pe "require('./package.json').version")
17+
18+
# Parse product category.
19+
export THEMEISLE_CATEGORY=$(node -pe "require('./package.json').category")
20+
21+
export DEMO_THEMEISLE_PATH="/sites/demo.themeisle.com/wp-content/$THEMEISLE_CATEGORY/$THEMEISLE_REPO";
22+
23+
# Build changelog based on commit message description.
24+
CHANGELOG="\n ### v$THEMEISLE_VERSION - "$(date +'%Y-%m-%d')" \n **Changes:** \n";
25+
26+
# Remove first line from the commit as is it used as commit title.
27+
NORMALIZED_MESSAGE=$(sed "1d" <<< "$TRAVIS_COMMIT_MESSAGE");
28+
29+
# Save changes list in a sepparately variable as we use it in the release body.
30+
export CHANGES="";
31+
while read -r line; do
32+
if ! [ -z $line ]; then
33+
line=$(echo "${line//[$'\r\n']}");
34+
export CHANGES=$CHANGES'- '$line'\n';
35+
fi;
36+
done <<< "$NORMALIZED_MESSAGE"
37+
38+
# Concat changes and changelog title and prepend to the changelog file.
39+
40+
CHANGELOG="$CHANGELOG $CHANGES";
41+
echo -e "$CHANGELOG $(cat CHANGELOG.md)" > CHANGELOG.md
42+
43+
# Run the prepare deployment action
44+
45+
grunt deploy
46+
fi;

0 commit comments

Comments
 (0)