OSDN Git Service

Regular updates
[twpd/master.git] / travis-gh-pages.md
1 ---
2 title: Deploy gh-pages via Travis
3 category: Git
4 ---
5
6 Taken from https://medium.com/@nthgergo/publishing-gh-pages-with-travis-ci-53a8270e87db
7
8 ### Create an OAuth token and encrypt it
9
10 Use https://github.com/settings/tokens/new
11
12 ```sh
13 # via ruby
14 gem install travis
15 travis encrypt -r user/repo GITHUB_TOKEN=[the token here]
16 ```
17
18 ### Make it run the deploy script on deploy
19
20 ```yaml
21  # .travis.yml
22 script:
23   - bash ./scripts/deploy-to-gh-pages.sh
24 env:
25   global:
26     - GITHUB_REPO: "user/repo"
27     - secure: "nlnXJW/imf/w..."  # <-- from travis-encrypt
28 ```
29
30 ### Write deployer
31
32 Create the file `scripts/deploy-to-gh-pages.sh`
33
34 ```sh
35 #!/bin/bash
36 # See https://medium.com/@nthgergo/publishing-gh-pages-with-travis-ci-53a8270e87db
37 set -o errexit
38
39 rm -rf public
40 mkdir public
41
42 # config
43 git config --global user.email "nobody@nobody.org"
44 git config --global user.name "Travis CI"
45
46 # build (CHANGE THIS)
47 make
48
49 # deploy
50 cd public
51 git init
52 git add .
53 git commit -m "Deploy to Github Pages"
54 git push --force --quiet "https://${GITHUB_TOKEN}@$github.com/${GITHUB_REPO}.git" master:gh-pages > /dev/null 2>&1
55 ```
56
57 From Ractive, this might be useful in certain cases:
58
59 ```
60 if [ "$TRAVIS_PULL_REQUEST" != "false" -o "$TRAVIS_BRANCH" != "master" ]; then exit 0; fi
61 ```