Skip to content

Commit

Permalink
Add travis CI configuration
Browse files Browse the repository at this point in the history
From now on Travis CI will manage the build cycle driven by the
build script, hopefully the current configuration will work for
automatic "artifact" (pdf) releases from master branch as well.
  • Loading branch information
jossemarGT committed Dec 31, 2017
1 parent d4320ea commit ec73484
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 8 deletions.
15 changes: 15 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
language: generic
sudo: required
script: './build.sh'
services:
- docker
before_deploy: ./build.sh ci-git-setup
after_deploy: ./build.sh ci-git-push
deploy:
provider: releases
api_key: $GH_TOKEN
file: dist/jossemargt-resume.pdf
skip_cleanup: true
on:
repo: jossemarGT/resume
branch: master
69 changes: 64 additions & 5 deletions build.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
#!/bin/bash
set -eo pipefail
set -euo pipefail

GOAL=${1-default}
BUILD_DATE=$(date +%B\ %d,\ %Y)
TITLE=$(sed -n -e "s/^title:[[:space:]]*'\([^']\+\).*'/\1/p" docs/configuration.yaml)

##
# Generates HTML page inside docs/ directory using RESUME.md file and Pandoc Docker
# container
generate_page () {
Expand All @@ -15,23 +17,80 @@ generate_page () {
./RESUME.md docs/configuration.yaml
}

##
# Bumps last modified date in pandoc template configuration
bump_date () {
# TODO: Bump only if RESUME.md has changed
sed -i "s/date:.*/date: ${BUILD_DATE}/" docs/configuration.yaml
}

##
# Generates PDF file inside dist/ directory using docs/index.html file and
# wkhtmltopdf Docker container
generate_pdf () {
[ -d dist ] || mkdir dist
echo ":: Generating ${TITLE} PDF"
docker run -v "$(pwd)":/tmp/source -w /tmp/source --rm madnight/docker-alpine-wkhtmltopdf \
--title "${TITLE}" --page-size Letter --no-background \
--quiet --title "${TITLE}" --page-size Letter --no-background \
--print-media-type --viewport-size 520px \
docs/index.html dist/jossemargt-resume.pdf
}

######### CI Specific goals #########

##
# Setup git client in CI environment
git_setup () {
if [[ -z $(git config --local user.name) ]]; then
echo ':: Setup CI git user and email'
git config --local user.name 'Deployment Bot'
git config --local user.email '[email protected]'
fi
}

##
# Commit changes on `docs` directory and tags branch's head with current date
git_tag_bump () {
if [[ -z $(git --no-pager diff --numstat docs) ]]; then
echo ":: Git bump -> docs directory didn't change. SKIPPED"
return 0
fi

git add docs
git commit -m "Update GH Pages on ${BUILD_DATE}"
git tag "$(date +'%Y%m%d')"
}

##
# Push latest changes and tags (vendor specific implementation)
git_publish () {
set +x # Just in case
if [[ $TRAVIS_EVENT_TYPE != 'pull_request' ]]; then
echo ':: Git publish'
# Push latest commit to master branch and the tag associated with it
git push "https://${GH_TOKEN}:[email protected]/${TRAVIS_REPO_SLUG}" \
--quiet HEAD:master --tags
return 0
fi
echo ':: Git publish -> Nothing to do'
}

##
# Using the functions defined above
bump_date
generate_page
generate_pdf
case "$GOAL" in
ci-git-setup)
git_setup
git_tag_bump
;;
ci-git-push)
git_publish # A fenced git push
;;
default)
bump_date
generate_page
generate_pdf
;;
*)
echo ":: Unrecognized goal '${GOAL}'. Nothing to do."
;;
esac
2 changes: 1 addition & 1 deletion docs/configuration.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ github_reponame: resume
# ==============================================================================
title: 'jossemarGT résumé'
lang: en
date: December 23, 2017
date: December 30, 2017
author:
- Jossemar Cordero
description: 'jossemargt resume'
Expand Down
4 changes: 2 additions & 2 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<meta http-equiv="X-UA-Compatible" content="chrome=1">
<meta name="generator" content="pandoc">
<meta name="author" content="Jossemar Cordero">
<meta name="dcterms.date" content="2017-12-23">
<meta name="dcterms.date" content="2017-12-31">
<meta name="description" content="jossemargt resume">
<meta name="keywords" content="resume, cv, software engineer, devops, developer">
<title>jossemarGT résumé</title>
Expand Down Expand Up @@ -52,7 +52,7 @@ <h2 class="tag-line">Software engineer, maker and maddo scientisto</h2>
<small>
<a class="no-print" href="https://github.com/jossemarGT/resume/blob/master/RESUME.md">View On GitHub</a>
<span class="no-print">&bull;</span>
Last revision: 2017-12-23
Last revision: 2017-12-31
</small>
</p>
</footer>
Expand Down

0 comments on commit ec73484

Please sign in to comment.