Cyan Blog Cyan Blog
首页
  • Java (opens new window)
  • JUC (opens new window)
  • JVM (opens new window)
  • Redis

    • Redis安装 (opens new window)
    • Redis基础 (opens new window)
    • Redis实战 (opens new window)
    • Redis集群安装 (opens new window)
    • Redis分布式缓存 (opens new window)
    • Redis多级缓存 (opens new window)
    • Redis原理 (opens new window)
  • 管理工具

    • Maven (opens new window)
    • Git (opens new window)
  • SSM

    • Spring (opens new window)
    • SpringBoot (opens new window)
    • Mybatis (opens new window)
    • MybatisPlus (opens new window)
  • 微服务

    • Docker (opens new window)
    • RabbitMQ (opens new window)
    • SpringCloud (opens new window)
    • Dubbo (opens new window)
    • MongoDB (opens new window)
    • Zookeeper (opens new window)
  • Java面试题 (opens new window)
  • JUC面试题 (opens new window)
  • JVM面试题 (opens new window)
  • Linux面试题 (opens new window)
  • SQL面试题 (opens new window)
  • Maven面试题 (opens new window)
  • Redis面试题 (opens new window)
  • SSM面试题 (opens new window)
  • SpringCloud面试题 (opens new window)
  • Linux (opens new window)
  • C++ (opens new window)
  • 数据库

    • MySQL (opens new window)
    • NoSQL (opens new window)
  • 软件测试

    • 软件测试 (opens new window)
  • 加密解密 (opens new window)
  • bilibili字幕提取 (opens new window)
  • 道理 (opens new window)
  • 关于博主

    • Github (opens new window)
    • CSDN (opens new window)
  • 关于本站

    • 如何搭建博客网站 (opens new window)
首页
  • Java (opens new window)
  • JUC (opens new window)
  • JVM (opens new window)
  • Redis

    • Redis安装 (opens new window)
    • Redis基础 (opens new window)
    • Redis实战 (opens new window)
    • Redis集群安装 (opens new window)
    • Redis分布式缓存 (opens new window)
    • Redis多级缓存 (opens new window)
    • Redis原理 (opens new window)
  • 管理工具

    • Maven (opens new window)
    • Git (opens new window)
  • SSM

    • Spring (opens new window)
    • SpringBoot (opens new window)
    • Mybatis (opens new window)
    • MybatisPlus (opens new window)
  • 微服务

    • Docker (opens new window)
    • RabbitMQ (opens new window)
    • SpringCloud (opens new window)
    • Dubbo (opens new window)
    • MongoDB (opens new window)
    • Zookeeper (opens new window)
  • Java面试题 (opens new window)
  • JUC面试题 (opens new window)
  • JVM面试题 (opens new window)
  • Linux面试题 (opens new window)
  • SQL面试题 (opens new window)
  • Maven面试题 (opens new window)
  • Redis面试题 (opens new window)
  • SSM面试题 (opens new window)
  • SpringCloud面试题 (opens new window)
  • Linux (opens new window)
  • C++ (opens new window)
  • 数据库

    • MySQL (opens new window)
    • NoSQL (opens new window)
  • 软件测试

    • 软件测试 (opens new window)
  • 加密解密 (opens new window)
  • bilibili字幕提取 (opens new window)
  • 道理 (opens new window)
  • 关于博主

    • Github (opens new window)
    • CSDN (opens new window)
  • 关于本站

    • 如何搭建博客网站 (opens new window)
  • 零成本搭建个人博客网站
  • 从零开始搭建博客
  • 更多配置
  • 域名
  • 图床
  • 同步GitHub和Gitee
  • 自动部署
  • 代码私有
    • 项目源代码私有(可选做)
  • 评论区
  • 站点信息
  • MoreMore
  • 障碍与反思
  • Blog
2025-03-28
0
0
目录

代码私有

# 项目源代码私有(可选做)

为了避免项目中的隐私代码泄漏,可以新建一个private仓库放源代码

GitHub上创建一个private仓库blog-code

将代码上传

 #从原来的仓库cyanyep拉取分支pages-code中的源代码
git clone -b <branch-name> --single-branch https://github.com/username/repository.git
#新仓库建立连接
git remote add origin git@github.com:username/my-project.git
git add .
git commit -m "init"
git push origin master
  • 设置新仓库的secret,

    • setting->secret and variables->action中将之前的GITEE_PRIVATE_KEY、GITEE_TOKEN、GITEE_USERNAME、PERSONAL_ACCESS_TOKEN设置过来
  • 修改deploy.yml中的代码,

on:
  push:
    branches:
      - master #!!修改为master
jobs:
  build-and-deploy:
    runs-on: ubuntu-latest
    steps:
      # ...
      
      ## !!删除。因为如果有这个同步的是dist静态文件,没什么用,gitee不能部署pages
      # 复制同步工作流syncToGitee 到 dist
      - name: Copy .github to dist
        run: |
          mkdir -p ./docs/.vuepress/dist/.github/workflows
          cp ./.github/workflows/syncToGitee.yml ./docs/.vuepress/dist/.github/workflows/
      
      # ...
      
      # 部署到 GitHub Pages
      - name: Deploy to GitHub Pages
        uses: peaceiris/actions-gh-pages@v3
        with:
          # !!这里的github_token修改为personal_token
          personal_token: ${{ secrets.PERSONAL_ACCESS_TOKEN  }} # 自动提供的 GitHub Token
		  # !!添加external_repository
          external_repository: cyanyep/cyanyep #用户名/仓库名
          publish_dir: ./docs/.vuepress/dist # VuePress 默认的输出目录
          publish_branch: cy-pages # 部署到的目标分支
          exclude_assets: ""

最终完整deploy.yml

name: Deploy VuePress to GitHub Pages
# 当 master 分支有 push 事件时触发
on:
  push:
    branches:
      - master
jobs:
  build-and-deploy:
    runs-on: ubuntu-latest
    steps:
      # 检出代码
      - uses: actions/checkout@v3
        with:
          fetch-depth: 0 # 获取完整的历史记录(包括 .git 文件夹)

      - name: Set timezone
        run: echo "TZ=Asia/Shanghai" >> $GITHUB_ENV # 替换为你的时区
        
      # 使用action库,安装node
      - name: Set up Node.js  # 使用action库  actions/setup-node安装node
        uses: actions/setup-node@v3
        with:
          node-version: 16 # 根据你的项目需求选择 Node.js 版本

      # 缓存 node_modules
      - name: Cache node_modules
        id: cache-node-modules
        uses: actions/cache@v3
        with:
          path: node_modules #表示要缓存项目的 node_modules 文件夹
          key: node-modules-${{ runner.os }}-${{ hashFiles('**/package-lock.json') }}
          restore-keys: |
            node-modules-${{ runner.os }}-

     # 安装依赖(仅在缓存未命中时执行)
      - name: npm install 
        if: steps.cache-node-modules.outputs.cache-hit != 'true'
        run: npm install 

      # 构建 VuePress 项目,并将workflow拷贝到dist中用于仓库同步到gitee
      - name: Build VuePress
        run: npm run docs:build

      # 复制 CNAME 文件到 dist
      - name: Copy NAME to dist
        run: cp ./CNAME ./docs/.vuepress/dist/

      # 部署到 GitHub Pages
      - name: Deploy to GitHub Pages
        uses: peaceiris/actions-gh-pages@v3
        with:
          personal_token: ${{ secrets.PERSONAL_ACCESS_TOKEN  }} # 自动提供的 GitHub Token
          external_repository: cyanyep/cyanyep #用户名/仓库名
          publish_dir: ./docs/.vuepress/dist # VuePress 默认的输出目录
          publish_branch: cy-pages # 部署到的目标分支
          exclude_assets: ""

syncToGitee.yml

name: syncToGitee
on:
  push:
    branches:
      # 修改为master触发事件
      - master
jobs:
  repo-sync:
    runs-on: ubuntu-latest
    steps:
      - name: Mirror the Github organization repos to Gitee.
        uses: Yikun/hub-mirror-action@master
        with:
          src: 'github/cyanyep'
          dst: 'gitee/ciian'
          # !!这里添加src_key,使用ssh密钥,一般ssh密钥我们用的同一个,所以GitHub与gitee的一样
          # 注意需要在GitHub上配置ssh公钥才能使用,
          # 一般与gitee一样,所以直接使用gitee的
          src_key: ${{ secrets.GITEE_PRIVATE_KEY  }}
          dst_key: ${{ secrets.GITEE_PRIVATE_KEY }}
          dst_token:  ${{ secrets.GITEE_TOKEN }}
          static_list: "blog-code" # !!你的private仓库
          # !!这里要指定ssh方式,https方式不能用不知道为什么,你们如果能用要告诉我为什么哦,求求了(っ´Ι`)っ
          clone_style: ssh # 使用 SSH 方式克隆
          force_update: true
          debug: true

原来的gitee仓库就可以删除,或者设置为private,GitHub的分支pages-code可以删除了(确保你当前的代码可以正常运行,否则还可以回滚到这个版本)

自己做的时候action库库报错,所以有点乱,不知道有没有漏了什么步骤,步骤也有点省略,哪里看不懂。评论区告诉我(●'◡'●)。

上次更新: 2025/4/3 11:03:46
自动部署
评论区

← 自动部署 评论区→

最近更新
01
项目优化
05-06
02
项目优化
05-06
03
延迟消息
05-05
更多文章>
Theme by Vdoing | Copyright © 2025-2025 Cyan Blog
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式