Skip to content

notebook - 🚀 Deploy website on push #2835

notebook - 🚀 Deploy website on push

notebook - 🚀 Deploy website on push #2835

name: notebook - 🚀 Deploy website on push
on:
workflow_dispatch: # Run workflow manually (without waiting for the cron to be called), through the Github Actions Workflow page directly
# schedule: # Run workflow automatically
# - cron: "0 * * * *" # 每 1 h 运行一次
jobs:
web-deploy:
name: 🎉 Deploy
runs-on: ubuntu-latest
steps:
- name: 🚚 Get latest code
uses: actions/checkout@v3
with:
# Repository name with owner. For example, actions/checkout
# Default: ${{ github.repository }}
repository: 'yiyungent/notebook'
# The branch, tag or SHA to checkout. When checking out the repository that
# triggered a workflow, this defaults to the reference or SHA for that event.
# Otherwise, uses the default branch.
ref: 'main'
# Personal access token (PAT) used to fetch the repository. The PAT is configured
# with the local git config, which enables your scripts to run authenticated git
# commands. The post-job step removes the PAT.
#
# We recommend using a service account with the least permissions necessary. Also
# when generating a new PAT, select the least scopes necessary.
#
# [Learn more about creating and using encrypted secrets](https://help.github.com/en/actions/automating-your-workflow-with-github-actions/creating-and-using-encrypted-secrets)
#
# Default: ${{ github.token }}
token: ${{ secrets.MY_GITHUB_TOKEN_ACTIONS }}
# 为了让 git 有日志 (git log) 可寻,还得在检出的时候顺带把所有提交历史一并拉下来,指定 fetch-depth 就能做到
fetch-depth: 0 # Fetch all history for .GitInfo and .Lastmod
- name: TimeZone
run: |
echo "Before:"
date --iso-8601=seconds
ls -l /etc/localtime
# Setting TimeZone
sudo rm -f /etc/localtime
sudo ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
echo "After:"
ls -l /etc/localtime
date --iso-8601=seconds
shell: bash
- name: Fix File Modify Date
# run: |
# 实测: 无效
# git ls-files | while read filepath; do touch -d "$(git log -1 --format='@%ct' $filepath)" "$filepath" && echo "Fixed: $filepath"; done
# shell: bash
run: |
./fix-date.ps1
./updated.ps1
shell: pwsh
- name: Use Node.js 18
uses: actions/setup-node@v3
with:
node-version: '18'
- name: Install Pandoc
run: |
sudo apt-get install pandoc
- name: 替换 Markdown 中 换行符
run: |
./替换换行符.ps1
shell: pwsh
- name: 🔨 Build Project
run: |
# 解决 Hexo 文章时间为 UTC+0, 而不是 UTC+08:00
export TZ='Asia/Shanghai'
npm config set registry https://registry.npmmirror.com
npm install -g hexo-cli
npm install
# 使用 npm ci 锁定版本, 确保 CI/CD 环境与开发环境一致, 同时确保不会出现 prompt
npm ci
hexo clean
hexo generate
shell: bash
# - name: 📂 Sync files
# uses: SamKirkland/[email protected]
# with:
# server: ${{ secrets.NOTEBOOK_FTP_SERVER }}
# username: ${{ secrets.NOTEBOOK_FTP_USERNAME }}
# password: ${{ secrets.NOTEBOOK_FTP_PASSWORD }}
# local-dir: ./public/
- name: Deploy to Server
uses: easingthemes/ssh-deploy@main
env:
SSH_PRIVATE_KEY: ${{ secrets.NOTEBOOK_SSH_PRIVATE_KEY }}
ARGS: "-rlgoDzvc -i --delete"
SOURCE: "public/"
REMOTE_HOST: ${{ secrets.NOTEBOOK_REMOTE_HOST }}
REMOTE_USER: ${{ secrets.NOTEBOOK_REMOTE_USER }}
TARGET: ${{ secrets.NOTEBOOK_REMOTE_TARGET }}
# EXCLUDE: "/dist/, /node_modules/"