This repository has been archived by the owner on Dec 26, 2022. It is now read-only.
forked from flef/Incipio
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #84 from theofidry/enhancement/deploy-scripts
Enhance deploy scripts
- Loading branch information
Showing
5 changed files
with
139 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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: | ||
|
@@ -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 | ||
|
@@ -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 | ||
|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |