[Python] Automate Pelican builds with Travis CI

As the title says. Pelican + There is a site operated by GitHub Pages. I tried setting Travis CI to automatically generate HTML with the pelican command when I pushed an article to master and push it to the gh-pages branch to update the site. Site: http://zaki-yama.github.io/salesforce-developers.info

Prerequisites

I tried the type of GitHub Pages called ** Project Pages **. There are two types of GitHub Pages: ** User / Organization Pages ** and ** Project Pages **.

User/Organization Pages

--Repository name: [** GitHub account name **] .github.io --Site URL: http: [** GitHub account name **] .github.io --Branch name to push pre-build source code: optional --Branch name to push HTML after build: master

Project Pages

--Repository name: Optional --Site URL: http: [** GitHub account name **] .github.io / [** repository name **] --Branch name to push pre-build source code: optional --Branch name to push HTML after build: gh-pages

TL;DR

If you can read English, you can follow this article. http://blog.thomasemmerling.de/automatic-pelican-publishing-on-github-pages-via-travisci.html

procedure

Enable the travis command

$ gem install travis

Get a Personal Access Token on GitHub

Reference: Creating an access token for command-line use --User Documentation

You need a token to push from Travis CI to the GitHub repository. Open Settings> Personal access tokens on GitHub and issue a new token with [Generate new token].

Copy the displayed character string.

SS_2016-01-08_0_18_37.png

Encrypt token

Use the first installed travis command.

$ travis encrypt GH_TOKEN=[Copied token]
Shell completion not installed. Would you like to install it now? |y| y
Detected repository as zaki-yama/salesforce-developers.info, is this correct? |yes| yes
Please add the following to your .travis.yml file:

  secure: "FLEqynRypa3B4S9qzcj0OTCwXrHUjEvsiXTI0r7qhZMzt11JUJUSzpVce/q5ZSENuBe9LR+c7MHl0pq9+1fka7bnYpbqWSybbIT5hLUVpIxB2ZvapogHmf9L/1n0vcODGhFwMUOfI1MuDN47wGCHS+qabNkIlzGGQPZYpri1ns1sp5rM7VFmVW6p3grAnhkaVWJIvW7GZORIPH11uBWtWsO2vhymrzM1J/PAgbJcSCjhtEZ79ntiG9DkAGqG27mVKPMNN8NDeIFGlbz2YyPgAqursSjZEPgmnzcQhzqyGz9D9Z5vAONki5vZ9CamEPfFa9llbQlwceM/7DJS+8FsBmiHH59i5rxW40iNK2otl6rSapXp1CLoWptXKVcyl9EjKcBUrRpWZ0Xzj94Ili80RbXiFJBW3B4qtrx7KCweUPURlY94a7n+P+pjbnx/jsdXFyvW4yR9R4+we82TxMPn49kq9Qf0cKnuEkVBOK1QyntdIDcW/L6heWqJAjWJMMGch4lSi0cN/8UGZxqq0b+OoHBp3FHWrnvOnLFB4mEgzp1/sa5jAFr6uq9mIS/TZ37XWrUX39YzAp6IL9Xq5Gmwof8nhKfnX7xm/yb3bglOt9HgrxArEKWoc/w/Gt4uxjGMQ2B9YjJsOdnxBHPpUgUXXxHj0FaD6K0pHLpJRQ+v78A="

Pro Tip: You can add it automatically by running with --add.

The string after secure: is the encrypted token, so copy it.

Make .travis.yml

Create a .travis.yml file in the root of the repository and write as follows.

yaml:.travis.yml


language: python
branches:
  only:
  - master
install:
- pip install pelican
- pip install ghp-import
- pip install markdown
script:
- make publish
- make github
env:
  global:
  - secure: [token encrypted with travis encrypt command]

Edit Makefile

Edit the make github part of Pelican's Makefile. In my case it was originally like this.

Makefile


PY?=python
PELICAN?=pelican
PELICANOPTS=

BASEDIR=$(CURDIR)
INPUTDIR=$(BASEDIR)/content
OUTPUTDIR=$(BASEDIR)/output

...(Omission)...

GITHUB_PAGES_BRANCH=master

...(Omission)...

github: publish
    ghp-import -m "Generate Pelican site" -b $(GITHUB_PAGES_BRANCH) $(OUTPUTDIR)
    git push origin $(GITHUB_PAGES_BRANCH)

.PHONY: html help clean regenerate serve serve-global devserver publish ssh_upload rsync_upload dropbox_upload ftp_upload s3_upload cf_upload github

Modify the last part of github: publish like this.

Makefile(Revised)


github: publish
    ghp-import $(OUTPUTDIR)
    @git push -fq https://${GH_TOKEN}@github.com/$(TRAVIS_REPO_SLUG).git gh-pages > /dev/null

Push .travis.yml to master

Commit the modified Makefile with .travis.yml and push it to the master branch. If the settings are correct, the Travis CI build will run, and the Pelican build and push to the gh-pages branch will be performed automatically.

(Bonus) Prevent the build from running when creating a Pull Request

I wanted to make the article before publication a separate branch, create a Pull Request to master, merge it, build it, and publish the article. As soon as I made the PR, the build ran and I was impatient, but it was in the Travis CI Settings.

SS_2016-01-09_14_15_01.png

(Bonus 2) Display the badge in the README

Reference: I tried using Travis CI: I wanted to put a badge on the repository on GitHub

Click on the build unknown badge in Travis CI's admin console, select Markdown and copy the text that appears.

SS_2016-01-08_1_39_01.png

Paste it into the README.md and push it to see the badge.

SS 2016-01-08 1.42.00.png

Recommended Posts

[Python] Automate Pelican builds with Travis CI
Automate python testing with CircleCI
Automate sushi making with Python
[Blender] Automate Blender add-on testing with GitHub and Travis CI
Automate simple tasks with Python Part0
Test Python non-functional programs with GitLab CI
Automate simple tasks with Python Part1 Scraping
FizzBuzz with Python3
Scraping with Python
Statistics with python
Scraping with Python
Python with Go
Twilio with Python
Integrate with Python
Play with 2016-Python
AES256 with python
Tested with Python
python starts with ()
with syntax (Python)
I tried to automate sushi making with python
Bingo with python
Zundokokiyoshi with python
Static analysis of Python code with GitLab CI
Excel with Python
Microcomputer with Python
Cast with python
Automate UI testing with Selenium API | Crawling websites with python
Automate Chrome with Python and Selenium on your Chromebook
Try to automate pdf format report creation with Python
Settings for testing C ++ 11 Python modules on Travis CI
Serial communication with Python
Zip, unzip with python
Django 1.11 started with Python3.6
Primality test with Python
Python with eclipse + PyDev.
Socket communication with Python
Data analysis with python 2
Scraping with Python (preparation)
Try scraping with Python.
Learning Python with ChemTHEATER 03
Sequential search with Python
"Object-oriented" learning with python
Run Python with VBA
Handling yaml with python
Solve AtCoder 167 with python
Serial communication with python
[Python] Use JSON with Python
Learning Python with ChemTHEATER 05-1
Learn Python with ChemTHEATER
Run prepDE.py with python3
1.1 Getting Started with Python
Collecting tweets with Python
Binarization with OpenCV / Python
3. 3. AI programming with Python
Kernel Method with Python
Non-blocking with Python + uWSGI
Scraping with Python + PhantomJS
Posting tweets with python
Drive WebDriver with python
Use mecab with Python3
[Python] Redirect with CGIHTTPServer