Skip to content

Build Demo Site

Build Demo Site #327

Workflow file for this run

# Build the demo site when new changes are commited.
name: Build Demo Site
# This will run when push events occur on master branch.
on:
push:
branches: [ master ]
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job called "build"
build:
# The type of container that the job will run in
runs-on: ubuntu-latest
# Environment virables
env:
SITE_URL: kr-demo.candinya.com
# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Setup Node.js env
- uses: actions/[email protected]
with:
node-version: '16.x'
# Get Hexo test utils
- uses: actions/checkout@v2
with:
repository: 'hexojs/hexo-theme-unit-test'
# Make dirs for themes
- name: Make dirs for themes
run: mkdir themes
# Clone Kratos-Rebirth into themes dir
- name: Clone Kratos-Rebirth into themes dir
run: git clone --single-branch --branch master https://github.com/${GITHUB_REPOSITORY} ./themes/kratos-rebirth
# Edit hexo site settings
- name: Edit Hexo site settings
run: |
sed -i "s/title: Hexo/title: Kratos-Rebirth/" "_config.yml"
sed -i "s/subtitle: ''/subtitle: A demo site of theme Kratos Rebirth/" "_config.yml"
sed -i "s/description: ''/description: A demo site of theme Kratos Rebirth/" "_config.yml"
sed -i "s/author: John Doe/author: Candinya/" "_config.yml"
sed -i "s/language:/language: zh-CN/" "_config.yml"
sed -i "s|url: http://yoursite.com|url: https://${SITE_URL}|" "_config.yml"
sed -i "s|permalink: :year/:month/:day/:title/|permalink: posts/:title/|" "_config.yml"
sed -i "s/theme: landscape/theme: kratos-rebirth/" "_config.yml"
# Copy document
- name: Copy document
run: cp "themes/kratos-rebirth/Kratos-Rebirth-Manual.md" "source/_posts/Kratos-Rebirth-Manual.md"
# Pin document
- name: Pin document
run: |
sed '2 isticky: 1' -i source/_posts/Kratos-Rebirth-Manual.md
# Copy extended theme settings
- name: Copy extended theme settings
run: cp "themes/kratos-rebirth/.demo/_config.kratos-rebirth.yml" "_config.kratos-rebirth.yml"
# Edit theme settings
- name: Edit theme settings
run: |
sed -i "s|clientID: 'GitHub Application Client ID'|clientID: ${{ secrets.GH_OAUTH_ID }}|" "_config.kratos-rebirth.yml"
sed -i "s|clientSecret: 'GitHub Application Client Secret'|clientSecret: ${{ secrets.GH_OAUTH_SECRET }}|" "_config.kratos-rebirth.yml"
# Set Pages CNAME file
- name: Set github pages CNAME file
run: |
touch "source/CNAME"
echo "${SITE_URL}" > source/CNAME
# Install Hexo env
- name: Install Hexo environment
run: npm install
# Install post-time-fix plugin
- name: Install post-time-fix plugin
run: npm install hexo-filter-date-from-git --save
# Setup git configs
- name: Setup git configs
run: |
git config --global user.name "Github Actions"
git config --global user.email "[email protected]"
# Set private key for deployment
mkdir -p ~/.ssh/
echo "${{ secrets.DEPLOY_KEY }}" | tr -d '\r' > ~/.ssh/id_rsa
chmod 600 ~/.ssh/id_rsa
ssh-keyscan github.com >> ~/.ssh/known_hosts
# Hexo build demo site
- name: Hexo build demo site
run: npx hexo generate --force
# Deploy demo site
- name: Deploy demo site
run: |
cd ./public
git init -b gh-pages
git remote add origin [email protected]:Candinya/Kratos-Rebirth-Demo.git
git add -A
git commit -m "Update Demo Site at `date +'%Y-%m-%d %H:%M:%S'`"
git push --set-upstream origin gh-pages -f