Today I received some security update on my SpyFall project from dependabot. I merged the pull request. Then I want to deploy this update to gh-pages branch, where my github page of SpyFall is deployed. However, this app is written in react js, I need to build it before I can deploy it to github Pages. Before I will just git pull and build and push the build to gh-pages branch manually, but now I can use github action to automate this, and in the future I can just push to master and Github will build and deploy to gh-pages automatically.
(This method also applicable for other javascript framework like Vue.js)
-
Press "Actions" here
-
Click "set up a workflow myself"
-
Paste this if you are using yarn for your non
<username>.github.io
repo
Note: I am using yarn as dependency manager, if you use npm, you can replace yarn install --frozen-lockfile
with npm ci
.
The reason why use these commands to install dependencies instead of using yarn
or npm install
is, npm ci
install depedencies according to package-lock.json
instead of package.json
, to ensure the versions of the app dependencies and their dependencies is same as the one you installed during development.
Moreover, react build the page to ./build directory, so I change the publish_dir to ./build, if your build will be in other directory you can change it accordingly.
If you are deploying to your <username>.github.io
repo, refer to this yaml instead
My source code is in dev
branch, so the action should be triggered by event related to dev
branch instead of master
branch, the action/checkout
should checkout dev
branch instead of master
branch, which is the default. The gh-page
action I specified the publish_branch
is master
, which is required by github. I am using ./dist
instead of ./build
just because my personal homepage is written in Vue which builds to ./dist
by default
-
Press start commit and commit new file
-
Check if your gh-pages is enabled at settings
- (optional) Add a badge to readme, just copy the markdown from actions->your pipeline->create status badge, then paste it to the readme file