前提要求
创建两个远程仓库
这里采用 github
平台

source-repo 作为项目的总源码仓库,而另外一个作为部署后的工作仓库
申请 token
在Settings/Developer Settings/Personal accses tokens/Tokens(classic)
设置下新建token


配置文件
在.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
| name: 自动部署
on: push: branches: - main release: types: - published
jobs: deploy: runs-on: ubuntu-latest steps: - name: 检查分支 uses: actions/checkout@v3 with: ref: main - name: 安装 Node uses: actions/setup-node@v3 with: node-version: '18.x' - name: 安装 Hexo run: | export TZ='Asia/Shanghai' npm install hexo-cli -g - name: 缓存 Hexo uses: actions/cache@v3 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 # npm install gulp-cli -g - name: 生成静态文件 run: | hexo clean hexo generate # gulp #hexo bangumi -u #hexo cinema -u - name: 部署 run: | cd ./public git init git config --global user.name '${{ secrets.GITHUBUSERNAME }}' git config --global user.email '${{ secrets.GITHUBEMAIL }}' git add . git commit -m "U updated via Github Actions." git push --force --quiet "https://${{ secrets.GITHUBUSERNAME }}:${{ secrets.GITHUBTOKEN }}@github.com/${{ secrets.GITHUBUSERNAME }}/hexo-blog.git" master:main # 后面的仓库地址改成自己的工作仓库地址 # git push --force --quiet "https://${{ secrets.GITHUBUSERNAME }}:${{ secrets.GITHUBTOKEN }}@github.com/${{ secrets.GITHUBUSERNAME }}/${{ secrets.GITHUBUSERNAME }}.github.io.git" master:main # git push --force --quiet "https://${{ secrets.GITEEUSERNAME }}:${{ secrets.GITEETOKEN }}@gitee.com/${{ secrets.GITEEUSERNAME }}/${{ secrets.GITEEUSERNAME }}.git" master:master
|
第一步、添加环境变量

在这里我只是部署到github
上,如有其他平台可以根据autodeploy.yml
文件里的部署步骤下的run
命令自行添加,里面各自的$环境变量$也得在上面图中填写
部分变量说明:
GITHUBUSERNAME:github 用户名
GITHUBEMAIL:github 邮箱
GITHUBTOKEN:上面创建的 token
第二步、将 hexo 代码上传到远程仓库
上传等一会儿就可以点开Actions
页面看项目的部署情况



等部署完成之后打开工作仓库hexo-blog
就可以看到有一个commit

第三步、利用 vercel 部署项目
这里选择用vercel
来对项目进行部署,如有其他选择可以自行选择。
注册vercel
账号 - Add New Project

直接导入刚才的hexo-blog
仓库
