本文以lxk0301大佬的库作为示例
第一步.申请PAT
点击 GitHub 用户设置页面 最下方的 Developer setting ,然后选择 Personal access tokens
来生成一个 token,由于我们只需要能够对普通仓库 push 就行了,所以把 repo
和workflow
部分勾上即可。
备份红框内的信息
第二步.创建仓库并写入yml文件
创建仓库
不详细讲解
写入yml文件步骤
在下图箭头所指填写.github/workflows/main.yml
在文本框中填写以下内容
# File: .github/workflows/repo-sync.yml
name: sync-lxk0301-scripts #action名字,随便起
on:
schedule:
- cron: '1 0,15 * * *'
workflow_dispatch:
watch:
types: started
push:
branches: [ master ]
repository_dispatch:
types: sync-lxk0301-jd_scripts #同随便起
jobs:
repo-sync:
env:
PAT: ${{ secrets.PAT }}
dst_key: ${{ secrets.GITEE_PRIVATE_KEY }} # 我自己同步到gitee使用,其他人可忽略
runs-on: ubuntu-latest
if: github.event.repository.owner.id == github.event.sender.id
steps:
- uses: actions/[email protected]
with:
persist-credentials: false
- name: sync lxk0301-scripts
uses: repo-sync/[email protected]
if: env.PAT
with:
source_repo: "https://github.com/lxk0301/jd_scripts.git" #关键内容,对方github库信息
source_branch: "master"
destination_branch: "master"
github_token: ${{ secrets.PAT }}
# 我自己同步到gitee使用,其他人可忽略
- name: sync github -> gitee
uses: Yikun/[email protected]
if: env.dst_key
with:
src: github/lxk0301
dst: gitee/lxk0301
static_list: "jd_scripts"
dst_key: ${{ secrets.GITEE_PRIVATE_KEY }}
dst_token: ${{ secrets.GITEE_TOKEN }}
第三步.在settings—secrets内新建一个secret
命名为PAT
值为第一步中获得的那串字符
第四步.试运行
点击绿色箭头后稍等片刻,按f5刷新,看是否是绿色对勾
若是绿色对勾,则已配置成功
回到code界面点击分支即可看到master分支
有问题请自行解决,恕不负责
版权声明: 版权归 Hanhan 所有,未经允许不得转载!
想问下,代码一样,
UPSTREAM_REPO=https://github.com/sazs34/MyActions.git
BRANCHES=master:main
Resetting origin to: *github.com/joshua-hua/code
Adding tmp_upstream https://github.com/sazs34/MyActions.git
Fetching tmp_upstream
fatal: could not read Username for 'https://github.com': No such device or address
提示这个报错,怎么解决呢,找了好久都找不到答案。