参考:
🔗利用Github Action实现Github到Gitee的持续同步 - SSgeek - 博客园 (cnblogs.com)
🔗使用GitHub Actions自动编译部署hexo博客 - Fungit - 博客园 (cnblogs.com)
配置SSH,使action可以推送代码
首先在本地生成一个ssh
密钥对
1
| ssh-keygen -t rsa -f ~/Documents/ssh-key/id_rsa(对应路径即可)
|
找到id_rsa.pub
文件,在GithubSSH
公钥中添加上面生成的密钥对的公钥,或settings
—>Deploy key
(仅对当前仓库有效)
找到id_rsa
文件,在github
打开对应action的仓库settings
—>secrets
,新建一个仓库secret
,名为HEXO_DEPLOY_KEY
,值为上面生成的密钥对的私钥
配置action
在仓库新建/.github/workflows/pages.yml
配置ssh位置 /home/runner/.ssh/
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 68 69 70 71 72
| name: Deploy hexo site to Pages
on: push: branches: [main] paths: - '*.json' - '**.yml' - '**/source/**' - '**/scripts/**'
permissions: contents: read pages: write id-token: write
defaults: run: shell: bash
jobs: build: timeout-minutes: 30 runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 with: token: ${{ secrets.GITHUB_TOKEN }} submodules: recursive - name: Use Node.js 20 uses: actions/setup-node@v4 with: node-version: "20" - name: Cache NPM dependencies uses: actions/cache@v4 with: path: node_modules key: ${{ runner.OS }}-npm-cache restore-keys: | ${{ runner.OS }}-npm-cache - name: Install Dependencies run: npm install - name: Install Hexo-cli run: | npm install -g hexo-cli --save echo "install hexo successful" - name: Build Blog run: | hexo clean hexo generate echo "build blog successful" - name: Set ssh Permission env: ACTION_DEPLOY_KEY: ${{ secrets.HEXO_DEPLOY_KEY }} run: | rm -rf /home/runner/.ssh mkdir -p /home/runner/.ssh/ echo "$ACTION_DEPLOY_KEY" > /home/runner/.ssh/id_rsa chmod 700 /home/runner/.ssh chmod 600 /home/runner/.ssh/id_rsa ssh-keyscan github.com >> /home/runner/.ssh/known_hosts - name: Deploy to Github run: | git config --global user.email "deploy@qq.com" git config --global user.name "deploy" hexo deploy - run: echo "Deploy Successful!"
|
经测试重新生成了一个初始博客文章hello-world.md
,待解决