静态博客搭建记录2

笔记主要包含实现自动部署的工作流。

参考

结合了第二、三个博文中的 workflow 文件,最终实现自动化部署。Obsidian 一键上传用到了 envelope

我的 workflow 文件

name: Generate Hexo Blog

on:
push:
branches:
- main # default branch

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
token: ${{ secrets.GITHUB_TOKEN }}
submodules: true
- name: Use Node.js 16.x #配置node环境
uses: actions/setup-node@v2
with:
node-version: '20.11.1'
- name: Setup Hexo environment
run: |
npm install -g hexo-cli
npm ci
- name: Generate pages
run: |
hexo generate
ls -R public/
# - name: Cache NPM dependencies
# uses: actions/cache@v2
# with:
# path: node_modules
# key: ${{ runner.OS }}-npm-cache
# restore-keys: |
# ${{ runner.OS }}-npm-cache
# - name: Install Dependencies
# run: npm install
# - name: Build
# run: npm run build
# - name: Upload Pages artifact
# uses: actions/upload-pages-artifact@v2
# with:
# path: ./public

# deploy:
# needs: build
# permissions:
# pages: write
# id-token: write
# environment:
# name: github-pages
# url: ${{ steps.deployment.outputs.page_url }}
# runs-on: ubuntu-latest
# steps:
# - name: Deploy to GitHub Pages
# id: deployment
# uses: actions/deploy-pages@v2
- name: Deploy
uses: JamesIves/github-pages-deploy-action@releases/v3
with:
REPOSITORY_NAME: yohakuo/yohakuo.github.io
BRANCH: html
FOLDER: public

基本操作

  • 切换分支
git checkout main
  • 从远程仓库拉取最新的更改并合并到本地仓库
git pull origin main
  • 保存更改并推送到 GitHub:
git add .  
git commit -m "main workflow configure"  
git commit -m "Vault backup"
git push -u origin main
  • 暂存更改(将它们暂存起来,然后在合并分支后再恢复)
git stash
git stash apply
  • 删除这些更改
git stash drop
  • 删除远程分支
git push origin --delete
  • 关联分支
git branch -u origin/main
  • 文件和文件夹的删除
git rm <name>
git rm -r <name>

主题

我当时配置这个主题出现了一点问题,最后是把它作为子模块工作流才能运行成<submodules: true>

问题解决

You have unmerged paths.

  • 查看下暂存区修改后的文件状态。
git status
  • 来到标红的文件进行修改,再次 push **MERGING** 就没有了

git push -u origin --> fatal: unable to access

  • 远程仓库和本地不一致,比如远程有的文件本地没有
  • 查询并取消代理
git config --global http.proxy

git config --global --unset http.proxy
  • 修改dns
git pull origin <name>