Skip to content

Generate Blogs

Generate Blogs #1179

Workflow file for this run

name: Generate Blogs
on:
push:
branches: [main]
schedule:
- cron: "0 1-23/2 * * *" # every day
workflow_dispatch:
permissions: write-all
jobs:
Prepare-required-files:
name: Prepare the required files
runs-on: ubuntu-latest
steps:
- name: Get files from repository
uses: actions/checkout@v4
- name: Set up Python environment
uses: actions/setup-python@v4
with:
python-version: '3.9.x'
- name: Install dependencies
run: |
pip install -r ${{ github.workspace }}/Redefine/requirements.txt
echo "--------------------------------------------------"
pip list
echo "--------------------------------------------------"
shell: bash
- name: Generate configuration file & download pandoc.deb
env:
ENV_GITHUB_ACTOR: ${{ github.actor }}
GH_TOKEN: ${{ secrets.GH_TOKEN }}
PUSHKEY: ${{ secrets.PUSHKEY }}
run: |
cd ${{ github.workspace }}/Redefine
python ./generate-config.py
shell: bash
- name: Upload files as artifacts
uses: actions/upload-artifact@v4
with:
name: config-files
path: |
${{ github.workspace }}/Redefine/blog.bd3qif.com/_config.redefine.yml
${{ github.workspace }}/Redefine/blog.bd3qif.com/_config.yml
${{ github.workspace }}/Redefine/blog.zhangyirui.cn/_config.redefine.yml
${{ github.workspace }}/Redefine/blog.zhangyirui.cn/_config.yml
${{ github.workspace }}/Redefine/pandoc/pandoc.deb
Generate-And-Deploy-Blog:
name: Generate and deploy Hexo blogs
needs: Prepare-required-files
runs-on: ubuntu-latest
strategy:
matrix:
blog: [zhangyirui.cn, bd3qif.com]
steps:
- name: Get files from repository
uses: actions/checkout@v2
- name: Download files
uses: actions/download-artifact@v4
with:
name: config-files
- name: Install pandoc
run: sudo dpkg -i ${{ github.workspace }}/pandoc/pandoc.deb
shell: bash
- name: Insatll hexo
run: |
echo "--------------------------------------------------"
cd ${{ github.workspace }}
echo "pandoc version: $(pandoc -v)"
echo "nodejs version: $(node -v)"
echo "npm version: $(npm -v)"
echo "--------------------------------------------------"
npm install -g hexo-cli
echo "--------------------------------------------------"
shell: bash
- name: Init blog & Install redefine theme
run: |
cd ${{ github.workspace }}
hexo init blog
git clone https://github.com/Zhang-Yirui/hexo-theme-redefine.git blog/themes/redefine
shell: bash
- name: Insatll npm packages
run: |
cd ${{ github.workspace }}/blog
npm install hexo-filter-mermaid-diagrams
npm install hexo-all-minifier
npm install hexo-filter-mathjax
npm uninstall hexo-renderer-marked
npm install hexo-renderer-pandoc
npm uninstall hexo-blog-encrypt
shell: bash
- name: Copy source files
run: |
cd ${{ github.workspace }}
cp -r ./Redefine/source/ ./blog/
cp -r ./Redefine/scaffolds/ ./blog/
shell: bash
- name: Copy config files
run: |
cd ${{ github.workspace }}
cp ./blog.${{ matrix.blog }}/*.yml ./blog/
shell: bash
- name: Generat blog
run: |
cd ${{ github.workspace }}/blog
hexo g
shell: bash
- name: Add README file & Compress files
run: |
cd ${{ github.workspace }}/blog
cp ../Redefine/source/.README.md ./public/README.md
tar -zcf public-blog.${{ matrix.blog }}.tar.gz ./public
shell: bash
- name: Upload config files as artifacts
uses: actions/upload-artifact@v4
with:
name: blog.${{ matrix.blog }}
path: |
${{ github.workspace }}/blog/public-blog.${{ matrix.blog }}.tar.gz
- name: Deploy the blog to the server over SSH
if: ${{ matrix.blog == 'zhangyirui.cn' }}
uses: kostya-ten/ssh-server-deploy@v4
with:
host: ${{ secrets.SERVER1_HOST }}
port: ${{ secrets.SERVER1_PORT }}
username: ${{ secrets.SERVER1_USERNAME }}
private_key: ${{ secrets.SERVER1_PRIVATE_KEY }}
scp_source: ${{ github.workspace }}/blog/public-blog.${{ matrix.blog }}.tar.gz
scp_target: ${{ secrets.SERVER1_TARGET }}
before_script: |
cd ${{ secrets.SERVER1_TARGET }}
ls -al
after_script: |
nohup tar -xzvf ${{ secrets.SERVER1_TARGET }}/public-blog.${{ matrix.blog }}.tar.gz -C ${{ secrets.SERVER1_TARGET }}/ > ${{ secrets.SERVER1_TARGET }}/nohup.log 2>&1 &
- name: Deploy the blog to Github Pages
if: ${{ matrix.blog == 'bd3qif.com' }}
uses: JamesIves/github-pages-deploy-action@v4
with:
token: ${{ secrets.GH_TOKEN }}
branch: main
folder: blog/public
git-config-name: ${{ github.actor }}
repository-name: Zhang-Yirui/Zhang-Yirui.github.io
Generate-GitHub-Release:
name: Generate GitHub Release
needs: Generate-And-Deploy-Blog
runs-on: ubuntu-latest
steps:
- name: Download config files
uses: actions/download-artifact@v4
with:
path: ${{ github.workspace }}/blogs
merge-multiple: true
- name: View files
run: |
echo "--------------------------------------------------"
ls -al -R ${{ github.workspace }}/blogs
echo "--------------------------------------------------"
# - name: Package & Compress files
# run: |
# echo "--------------------------------------------------"
# mv ${{ github.workspace }}/blogs/public-bd3qif.tar.gz ${{ github.workspace }}/blogs/blog.bd3qif.com/public.tar.gz
# mv ${{ github.workspace }}/blogs/public-zhangyirui.tar.gz ${{ github.workspace }}/blogs/blog.zhangyirui.cn/public.tar.gz
# cd ${{ github.workspace }}/blogs
# tar -zcf blog.zhangyirui.cn.tar.gz ./blog.zhangyirui.cn
# tar -zcf blog.bd3qif.com.tar.gz ./blog.bd3qif.com
# ls -R ${{ github.workspace }}
# echo "--------------------------------------------------"
# echo "$GITHUB_OUTPUT"
# echo "--------------------------------------------------"
# cat $GITHUB_OUTPUT
# ls $GITHUB_OUTPUT
# shell: bash
# - name: Create GitHub release
# id: create_release
# uses: actions/create-release@v4
# with:
# tag_name: v1.0.0 # 您可以根据需要更改版本号
# release_name: "Release v1.0.0"
# body: "This is the first release of config files."
# draft: false
# prerelease: false
# env:
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Delete the artifact config-files
uses: geekyeggo/delete-artifact@v5
with:
name: config-files