Skip to content
This repository has been archived by the owner on Dec 26, 2022. It is now read-only.

Commit

Permalink
Merge pull request #84 from theofidry/enhancement/deploy-scripts
Browse files Browse the repository at this point in the history
Enhance deploy scripts
  • Loading branch information
theofidry committed Oct 9, 2015
2 parents 69e6f2d + d776e1d commit 8b1b180
Show file tree
Hide file tree
Showing 5 changed files with 139 additions and 44 deletions.
56 changes: 13 additions & 43 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ php:
env:
global:
- PATH="$HOME/.composer/vendor/bin:$PATH"
# GH_TOKEN
- secure: cBXo6EWL5cGnTlDeroIE0C7nQQkXyB+kXE0vz4f8gP6XIH2KFWSDqt0VIo0mrNMAklr6vWBOYukCzDlt3svscM7/7c7nJpnlnfn01oMOt5gzK7iugEg66d1IjU1Hh1MIkAx+DHE/DF7nnM0PW5N5ATXJmk4G4QclMKCpfAb5AEU=
- GH_COMMIT_MESSAGE="Rebuild pages at $(git rev-parse --short HEAD)"
- GH_REMOTE="https://user:${GH_TOKEN}@github.com/in6pio/Incipio.git"
- GH_USER_NAME="TravisBot"
- GH_USER_EMAIL="[email protected]"
- GITHUB_PAGES_COMMIT_MESSAGE="Rebuild pages at $(git rev-parse --short HEAD)"
- if [[ -z "$GITHUB_PAGES_TOKEN" ]]; then
then GITHUB_PAGES_REMOTE="https://user:${GITHUB_PAGES_TOKEN}@github.com/in6pio/Incipio.git";
fi;
- GITHUB_USER_NAME="TravisBot"
- GITHUB_USER_EMAIL="[email protected]"

cache:
directories:
Expand All @@ -22,7 +22,7 @@ cache:
matrix:
include:
- php: 5.6
env: GH_PAGES="true"
env: DEPLOY_BUILD=true
allow_failures:
- php: 7.0
- php: nightly
Expand All @@ -34,19 +34,11 @@ before_install:
- composer self-update
- composer config -g github-oauth.github.com $GITHUB_OAUTH_TOKEN
- composer global require phpunit/phpunit --no-update
- if [ "true" = "$GH_PAGES" ] && ([ "false" != "$TRAVIS_PULL_REQUEST" ] || [ "master" != "$TRAVIS_BRANCH" ]); then
export GH_PAGES="false";
fi;
- if [ "true" = "$GH_PAGES" ]; then
git config --global user.name "${GH_USER_NAME}";
git config --global user.email "${GH_USER_EMAIL}";

pip install ghp-import --user;
pip install mkdocs --user;

composer global require halleck45/phpmetrics --no-update;
composer global require apigen/apigen --no-update;
fi;
- for file in scripts/*.sh; do
echo -en "\e[34mimports ${file}\e[0m\n";
source "$file";
done;
- configTravis

install:
- composer global update --prefer-dist
Expand All @@ -62,26 +54,4 @@ script:
- composer test:behat:front

after_success:
- if [ "true" = "$GH_PAGES" ]; then
echo -en "\n\e[34mGenerates PhpMetrics reports (x3)\e[0m\n";
phpmetrics --report-html=dist/reports/phpmetrics/app.html src;
phpmetrics --report-html=dist/reports/phpmetrics/api-bundle.html src/ApiBundle;
phpmetrics --report-html=dist/reports/phpmetrics/front-bundle.html src/FrontBundle;

echo -en "\n\e[34mGenerates PHPDoc\e[0m\n";
apigen generate --source src --destination dist/api-doc;

echo -en "\n\e[34mRetrieve GitHub Pages website\e[0m\n";
git clone ${GH_REMOTE}" gh-pages --branch=gh-pages --single-branch;

echo -en "\n\e[34mBuild GitHub Pages website\e[0m\n";
mkdocs build --clean;

echo -en "\n\e[34mPublish artefacts to GitHub Pages\e[0m\n";
mv -f dist/api-doc gh-pages;
mv -f dist/reports gh-pages;

ghp-import -m "${GH_COMMIT_MESSAGE}" -r "${GH_REMOTE}" -p gh-pages;

echo -en "\e[1;32mArtefacts published.\e[0m";
fi;
- publishToGithubPages
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
"style:fix": "php bin/php-cs-fixer fix -vvv src && php bin/php-cs-fixer fix -vvv features",
"test": "composer test:db && composer test:phpunit && composer test:behat && composer test:security",
"test:db": "php app/console d:s:v --ansi",
"test:security": "php bin/security-checker security:check",
"test:security": "php bin/security-checker security:check --ansi",
"test:phpunit": "php bin/phpunit -c phpunit_travis.xml --colors=always",
"test:behat": "composer behat:api && composer behat:front",
"test:behat:api": "php bin/behat --suite=api_features --strict --colors --tags ~@ignore",
Expand Down
48 changes: 48 additions & 0 deletions scripts/common.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#!/usr/bin/env bash
#
# Set the configuration necessary to the deployment.

export INFO_COLOR="\e[34m"
export SUCCESS_COLOR="\e[1;32m"
export ERROR_COLOR="\e[1;31m"
export NO_COLOR="\e[0m"

isDeployBuild() {
if [[ -z "$DEPLOY_BUILD" ]] || [[ -z "$TRAVIS_PULL_REQUEST" ]] || [[ -z "$TRAVIS_BRANCH" ]]; then
return 0;
fi;

if [[ true = "$DEPLOY_BUILD" ]] && [[ false != "$TRAVIS_PULL_REQUEST" ]] && [[ "master" = "$TRAVIS_BRANCH" ]]; then
return 0
fi

return 1
}

# Argument $1 = message
# Argument $2 = log level, accept `"info"`, `"success"` or `"error"`. Default at `"info"
log() {
local color="$INFO_COLOR"
local message="$1"
local level="$2"

case "$level" in
--success)
color="$SUCCESS_COLOR"
;;
--error)
color="$ERROR_COLOR"
;;
esac

if [ -z "$message" ]; then
echo "No argument supplied"

return 1
fi

echo -en "${color}${message}${NO_COLOR}\n"
}

export -f isDeployBuild
export -f log
34 changes: 34 additions & 0 deletions scripts/deploy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/usr/bin/env bash
#
# Functions for publishing and deploying artefacts

configTravis() {
isDeployBuild
if [[ 0 = "$?" ]]; then
log "No deployment scheduled for this build"

return 0;
fi

log "Prepare deployment for this build";

log "Configure Git user";
if [[ -z "$GITHUB_USER_NAME" ]] || [[ -z "$GITHUB_USER_EMAIL" ]]; then
log "Could not configure Git user" --error
else
GITHUB_USER_NAME="TravisBot"
GH_USER_EMAIL="[email protected]"
fi

log "Install necessary packages";
pip install ghp-import --user
pip install mkdocs --user
composer global require halleck45/phpmetrics --no-update
composer global require apigen/apigen --no-update

log "Deployment configuration read" --success

return 0
}

export -f configTravis
43 changes: 43 additions & 0 deletions scripts/publish.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/usr/bin/env bash
#
# Functions for publishing reports and docs to GitHub Pages

publishToGithubPages() {
isDeployBuild
if [[ 0 = "$?" ]]; then
log "Skipped"

return 0
fi

log "Retrieve GitHub Pages website"
if [[ -z "$GITHUB_PAGES_REMOTE" ]]; then
log "Could not retrieve GitHub Pages website. Abort GitHub Pages deployment" --error

return 1;
fi
git clone "$GITHUB_PAGES_REMOTE" gh-pages --branch=gh-pages --single-branch

log "Generates PhpMetrics reports (x3)"
phpmetrics --report-html=dist/reports/phpmetrics/app.html src
phpmetrics --report-html=dist/reports/phpmetrics/api-bundle.html src/ApiBundle
phpmetrics --report-html=dist/reports/phpmetrics/front-bundle.html src/FrontBundle

log "Generates PHPDoc"
apigen generate --source src --destination dist/api-doc

log "Build GitHub Pages website"
mkdocs build --clean

log "Publish artefacts to GitHub Pages"
mv -f dist/api-doc gh-pages
mv -f dist/reports gh-pages

ghp-import -m "$GITHUB_PAGES_COMMIT_MESSAGE" -r "$GITHUB_PAGES_REMOTE" -p gh-pages

log "Artefacts published" --success

return 0
}

export -f publishToGithubPages

0 comments on commit 8b1b180

Please sign in to comment.