$0, Free CICD and Web hosting integration. Travis-ci + Github.page by@peterchang_82818

$0, Free CICD and Web hosting integration. Travis-ci + Github.page

June 23rd 2022 5,127 reads
Read on Terminal Reader
react to story with heart
react to story with light
react to story with boat
react to story with money
No budget doesn’t mean no CI/CD, setup CI-CD just within few click and cost $0.
Outside of work, I like doing side projects to try out new tech and build something fun. The quality of side projects is more relax, not even require a secure check up before it merge to master, no need 2 reviewers to give 👍 to approve. As long as it look cool, can be merged.
Hold on, we all don’t want the new code to break the project when we showing off to people. So there are 2 points in development flow I care about:
  1. Run unit test when creating pull request, and leave comment
  2. Deploy a newest version when new commit is created on Master
I have tried out other services, like Heroku, circleCI, firebase, and AWS. They all have free product, but the brainless me end up on Travis.ci and Github.page, because they are simple.
This example is restricted to static web page, only contained static html, js and css file, not capable for server side render web application.

1.Github preparation

1.1 Create a Github repository

This is a sample Repository (web)under Organization vue-graphic, and the destinate url is https://vue-graphic.github.io/web.
The URL rule of Github.page is:

1.2 Setup publish branch

You can configure GitHub Branch to publish your site’s source files from master, gh-pages. In this example, the built static file will be pushed to branch gh-pages.
Master branch is the development branch.

2. Setup build script

The build script, is going to generate static HTML, css and js into ./dist directory.

3. Travis-CI configuration

3.1 Setup travis.yml

Travis-CI provides very good documentation specially for deployment to Github.page, then do your best skill, copy and paste.
local-dir: Directory to push to GitHub Pages
target-branch: Branch to push local-dir contents to, defaults to gh-pages

3.2 Setup Github personal access token

Travis CI can deploy your static files to GitHub Pages , and you will need to provide a personal access token and set the deployment provider details in .travis.yml.

3.3 Set Github Access token as Build Environment variable

Paste the Github personal access token into Travis-ci, section of environment variables. It is used in 3.3 for Github deployment.


Local deploy

push-dir is a tool Pushing the contents of a directory to a remote branch.
// package.json

"script:" {"local:deploy": "npm run build ; npx push-dir --dir=dist --branch=gh-pages --cleanup"
Then run:
$ npm run local:deploy

Setup assetsPublicPath for webpack config

For Vue-cli generated project, we need to setup assetsPublicPath as /repo.

Setup basename in React-Router

Setup basename into your **_<Router basename/>_**, it helps <Link /> and history.push() to navigate to right url.

Setup homepage in create-react-app

Setup Homepage in package.json, it helps to setup the configuration in npm run build.


react to story with heart
react to story with light
react to story with boat
react to story with money
. . . comments & more!