Skip to content

Commit f1d3e87

Browse files
committed
Travis CI integration: automatic linting, rebuilding index.json, building pages archive, and little other improvements
1 parent f877d15 commit f1d3e87

7 files changed

+99
-5
lines changed

.editorconfig

+4
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,7 @@ insert_final_newline = true
1010

1111
[*.md]
1212
trim_trailing_whitespace = false
13+
14+
[Makefile]
15+
indent_style = tab
16+
indent_size = 8

.travis.yml

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
language: ruby
2+
rvm:
3+
- 2.2.2
4+
5+
gemfile:
6+
- Gemfile
7+
8+
script:
9+
- make check
10+
11+
after_success:
12+
- bash scripts/build.sh
13+
14+
env:
15+
global:
16+
secure: PC9nFPE034jPsF0nUn7phCt0RgVouIvd0HsQkOonNSiElh+pkFyaVvDIsQR8lF4x1AxFjz9Yo3qnNGM3txvOMiNqfReDRINfnpvLDkumCeXuKYNO8XyacTHyxMWp0sZM/YhHhJ8qhroSbNOcYYduSW+fTAoyILieRNg+Wwx7b/rdybVKW7d45GDhjmxvx0/cVhLgghXZr7SRMRh89xrGRkT8vRY7xwlmMs83YRSEcs9pkBrdAfSG/16yOCAQVUS1z10zXk/SsRZlNGKzSWsvb1H/OlkHZpxpnawJhmn2iNIy25acqRdyLwv5Oy5P2sQDBjNenTmiv0JL9v7ks5uNtXaIimvSieLKn/vLmGmW/8ArifqwPpEcL/ZmoCH5SzNrvtO06TfuYPCWGrfLKBxySh4jnza8y8YruKlQfjWDm/o5MmiJWvM1mVtIRozO9hDYZ1EMf4e8qlT7K6Y3alWbl3PqZ/DnLHYIUEvtYv5M0H2Ydtqh5JIWj/XRaNSwwmL4Lpcz3AKavP93N4tYAoGIWO9hkVpwCYz3qNH9dIxQJ7ancj01FWVFqqbLcBLPk8MaQsuFSBZpIz9PTLFdtso/YnviqSu5I7GMsFQdvGY8Mth207dMCVs7DRYe9QCjpboQoiCPY8ckmVYvlYdrDMjnfkhQC/OfZLitVLBe6zyEwTs=

Gemfile

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
source 'https://rubygems.org'
22

3-
gem 'mdl'
3+
group :development, :test do
4+
gem 'mdl'
5+
end

Gemfile.lock

+3
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,6 @@ PLATFORMS
1414

1515
DEPENDENCIES
1616
mdl
17+
18+
BUNDLED WITH
19+
1.10.6

Makefile

+8-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
default: check
2+
13
all: setup index
24

35
index:
@@ -14,10 +16,13 @@ hooks:
1416
deps:
1517
@bundle
1618
@echo "OK"
17-
19+
20+
check:
21+
@bundle exec mdl --style ./scripts/markdown-style.rb pages
22+
1823
lint:
19-
@GEM_PATH=.gem find pages -exec .gem/bin/mdl {} --style ./scripts/markdown-style.rb 1>&2 \;
20-
24+
@GEM_PATH=.gem find pages -exec mdl {} --style ./scripts/markdown-style.rb 1>&2 \;
25+
2126
lint-changed:
2227
@./scripts/lint-changed.sh
2328

scripts/build.sh

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
#!/usr/bin/env bash
2+
3+
set -ev
4+
5+
function initialize {
6+
if [ -z "$TLDRHOME" ]; then
7+
export TLDRHOME=${TRAVIS_BUILD_DIR:-`pwd`}
8+
fi
9+
export TLDR_ARCHIVE="tldr.zip"
10+
export SITE_HOME="$HOME/site"
11+
export SITE_URL="github.com/tldr-pages/tldr-pages.github.io"
12+
13+
git config --global user.email "travis@travis-ci.org"
14+
git config --global user.name "Travis CI"
15+
git config --global push.default simple
16+
git config --global diff.zip.textconv "unzip -c -a"
17+
}
18+
19+
function rebuild_index {
20+
$TLDRHOME/scripts/build_index.rb
21+
echo "Rebuilding index is done"
22+
}
23+
24+
function build_archive {
25+
echo "Removing $TLDR_ARCHIVE if it exists"
26+
rm -f $TLDR_ARCHIVE
27+
28+
echo "Creating an archive $TLDR_ARCHIVE"
29+
cd $TLDRHOME/
30+
zip -r $TLDR_ARCHIVE pages/ LICENSE.md
31+
}
32+
33+
function upload_assets {
34+
echo "Uploading assets to static site"
35+
36+
git clone --quiet --depth 1 https://${GH_TOKEN}@${SITE_URL} $SITE_HOME
37+
mv -f $TLDR_ARCHIVE $SITE_HOME/assets/
38+
cp -f $TLDRHOME/pages/index.json $SITE_HOME/assets/
39+
40+
cd $SITE_HOME
41+
git add -A .
42+
git commit -m "[TravisCI] uploaded assets after commits ${TRAVIS_COMMIT_RANGE}"
43+
if [[ ! `git push -q` ]]; then
44+
echo "Cannot push to a static site"
45+
else
46+
echo "Assets deployed"
47+
fi
48+
}
49+
50+
###################################
51+
# MAIN
52+
###################################
53+
54+
if [ ! "$TRAVIS_PULL_REQUEST" == "false" ]; then
55+
echo "This is a Pull Request, no index rebuild needed"
56+
elif [ ! "$TRAVIS_BRANCH" == "master" ]; then
57+
echo "This is not a master branch, no index rebuild needed"
58+
else
59+
initialize
60+
rebuild_index
61+
build_archive
62+
upload_assets
63+
fi

scripts/markdown-style.rb

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# This file contains the markdown rules markdownlint will check for
22
all
33

4-
exclude_rule 'MD013' # Lengthy lines (80+ chars)
4+
exclude_rule 'MD013' # Lengthy lines (80+ chars)
5+
exclude_rule 'MD034' # Allow bare URLs

0 commit comments

Comments
 (0)