获取Token
勾选repo
和workflow
添加源码仓库的变量
Settings
→Secrets and variables
→Actions
添加变量:
- GITHUBTOKEN
- GIT_EMAIL (Git邮箱)
Actions设置
新建文件:.github/workflows/autodeploy.yml
在里面输入:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
| name: 自动部署
on: push: branches: - main
release: types: - published
jobs: deploy: runs-on: ubuntu-latest steps: - name: 检查分支 uses: actions/checkout@v2 with: ref: main
- name: 安装 Node uses: actions/setup-node@v1 with: node-version: "14.x"
- name: 安装 Hexo run: | export TZ='Asia/Shanghai' npm install hexo-cli -g
- name: 缓存 Hexo uses: actions/cache@v1 id: cache with: path: node_modules key: ${{runner.OS}}-${{hashFiles('**/package-lock.json')}}
- name: 安装依赖 if: steps.cache.outputs.cache-hit != 'true' run: | npm install --save
- name: 生成静态文件 run: | hexo clean hexo generate - name: 部署 env: GITHUBREPO: github.com/Kabuto0229/blog.git GIT_USER: Kabuto0229 GIT_EMAIL: ${{ secrets.GIT_EMAIL }} GITHUBTOKEN: ${{ secrets.GITHUBTOKEN }}
run: | cd ./public git init git config --global user.name '$GIT_USER' git config --global user.email '$GIT_EMAIL' git add . git commit -m "${{ github.event.head_commit.message }} $(date +"%Z %Y-%m-%d %A %H:%M:%S") Updated By Github Actions" git push --force --quiet "https://$GIT_USER:$GITHUBTOKEN@$GITHUBREPO" master:master
|
提交到Github
- 初始化本地仓库
1 2 3
| $ git init $ git remote add origin git@github.com:Kabuto0229/Hexo.git $ git checkout -b main
|
- 添加屏蔽项
打开./.gitignore
,输入:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
| _multiconfig.yml .DS_Store Thumbs.db db.json *.log node_modules/ public/ scripts/ pnpm-lock.yaml .deploy*/ .deploy_git*/ .idea source/_posts/*.js themes/shoka themes/butterfly/.git
|
- 提交更改
1 2 3
| $ git add . $ git commit -m "update" $ git push origin main
|
参考链接
-
-