Test project to publish documentation website using GitHub Pages via Travis CI with Android environment.
master
branch as usual.master
and gh-pages
branches.Usually we use gh-pages
branch or Wiki to manage project documentation website on GitHub.
However, I wanted to manage them in master branch because:
Also, I didn't want to manage them manually (building files, committing them to gh-pages
branch, ...), so I automate the entire process.
I was going to introduce them to Android projects, but maybe this can be applied to other types of projects.
This project uses these awesome tools and services to manage contents.
projectRoot
├── app // Android app
├── docs // Documents to be published
├── gradle // Gradle wrapper files
├── gradlew // Gradle wrapper files
├── gradlew.bat // Gradle wrapper files
└── website // Scripts to publish website
├── .bowerrc // bower settings
├── bower.json // bower settings
├── bower_components // bower modules
├── gulpfile.js // gulp settings
├── harp.json // harp settings
├── node_modules // npm modules
├── package.json // npm settings
├── public // Files for website (.ejs, .jade, etc.)
│ └── lib // Copied bower files to be published
├── repo // Another git repo to commit to gh-pages
└── www // Files compiled by harp
This project is just a showcase project for managing static contents in GitHub repo (especially using master branch), so you should configure some parts of the project to manage your own project.
Go to Personal access tokens page,
click Generate new token
and generate it.
Then encrypt it using travis command.
$ gem install travis
$ travis encrypt -r ksoichiro/gh-pages-android-playground GH_TOKEN="****************************************" --add
The result will be added to .travis.yml
.
At first, create gh-pages
and push it to your repo.
git checkout --orphan gh-pages
gh-pages
branch must be pushed to GitHub before building on Travis CI.
Go to account settings on Travis CI site, and enable builds for the project.
npm
is required to execute build commands.
If you don't have npm
in your environment, nvm (or nvm-windows) will be good.
You must configure these files.
env:
global:
- GIT_COMMITTER_NAME=ksoichiro
- GIT_COMMITTER_EMAIL=soichiro.kashima@gmail.com
- GIT_AUTHOR_NAME=ksoichiro
- GIT_AUTHOR_EMAIL=soichiro.kashima@gmail.com
- secure: Tszvcrpj37Y2/iLG2ke42Zl/lOzwi21IfRafmnyoAqSWycwuEwFzp4wjHNUZEEVVdiAU5my2CfVhcPakF3bdcFt9Dg1lUP8SSuMgrUurGD95wfJ2ORNU1B+3GElKItO8yKjG1eruDNzgOCwX1VocSnCXZbHeg3p1mhE5UEIht+w=
env.global.secure
is the result of travis encrypt
.
var project = {
githubRepoOwner: 'ksoichiro',
name: 'gh-pages-android-playground',
};
These values define the Git repository URLs.
{
"name": "gh-pages-android-test",
"description": "Web site for Android projects on GitHub",
"repository": {
"type": "git",
"url": "https://github.com/ksoichiro/gh-pages-android-playground.git"
},
{
"name": "gh-pages-android-test",
"description": "bower components for gh-pages-android-test",
Just replace text to match your project.
{
"globals": {
"baseUrl": "$BASE_URL",
"title": "gh-pages-android-playground"
}
}
Just replace globals.title
to match your project.globals.baseUrl
is used to construct proper URLs in HTML for local or production.
Every operations to manage website in local environment are executed in website
directory.
At first, you should move to the directory and install the dependencies.
cd website
npm install
Then start a web server.
npm start
http://localhost:9000/
will be used.
After launching a server, you can edit files such as<projectRoot>/docs/*.md
,<projectRoot>/website/public/*.ejs
, and so on.
You can confirm the result by reloading the browser.
If they're OK, commit the edited files.
You can deploy the contents manually or Travis CI builds.
Run the following command in website
directory.
npm run clean && npm run deploy
This command will build static files and automatically commit and push the changes to the gh-pages
branch of GitHub repository.
Just push the master branch to GitHub.
Static contents are built on Travis CI, and the changes will be committed and pushed to the gh-pages
branch of GitHub repository.
Copyright 2015 Soichiro Kashima
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.