# Github的如何实现私有仓库但release公开?

**URL:** <https://meta.appinn.net/t/topic/56187>\
**Category:** 问题求助\
**Tags:** github\
**Created:** [2024 年5 月 8 日 11:05 UTC](https://meta.appinn.net/t/topic/56187 "2024-05-08T11:05:15Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

作者： ![Stars-One](https://meta-edge.appinn.com/user_avatar/meta.appinn.net/stars-one/32/21660_2.png) [@Stars-One](https://meta.appinn.net/u/Stars-One)\
发布日期： [2024 年5 月 8 日 11:05 UTC](https://meta.appinn.net/t/topic/56187/1 "2024-05-08T11:05:16Z")

</div>

有这样一个需求:

> 我Github有个私有库(此私有库利用github action来实现自动打包,编译二进制安装文件,并发布release)
> 
> 我不想公开我的代码,但我的release对应的二进制产物我希望可以公开给他人下载

我想到方法是

> 用一个公有库,创建一个新的github action,能够定时拉取我私有库的release(可以看做为同步私有库的release及对应的二进制文件)

或者各位大佬有其他不同思路?

看了各种github action教程,研究了一天还是不行… :smiling_face_with_tear:

这是我要整的公有库的地址:

> **[GitHub - stars-one/XnApp-PC-Release: 星念社PC版](https://github.com/stars-one/XnApp-PC-Release)**
>
> 星念社PC版

---

<div class="post-metadata">

作者： ![TecNico](https://meta-edge.appinn.com/user_avatar/meta.appinn.net/tecnico/32/78882_2.png) [@TecNico](https://meta.appinn.net/u/TecNico)\
发布日期： [2024 年5 月 8 日 11:12 UTC](https://meta.appinn.net/t/topic/56187/2 "2024-05-08T11:12:51Z")

</div>

私有仓库编译的二进制可以推到公开仓库的release

---

<div class="post-metadata">

作者： ![txyyh](https://meta-edge.appinn.com/user_avatar/meta.appinn.net/txyyh/32/30036_2.png) [@txyyh](https://meta.appinn.net/u/txyyh)\
发布日期： [2024 年5 月 8 日 11:19 UTC](https://meta.appinn.net/t/topic/56187/3 "2024-05-08T11:19:01Z")

</div>

我之前是使用 cpina/github-action-push-to-another-repository 把编译产物 push 到目标仓库的特定分支，然后目标仓库再写个 action 处理 push 过来的内容，比如发布 Releases

---

<div class="post-metadata">

作者： ![RachelSherman](https://meta-edge.appinn.com/letter_avatar_proxy/v4/letter/r/74df32/32.png) [@RachelSherman](https://meta.appinn.net/u/RachelSherman)\
发布日期： [2024 年5 月 8 日 11:57 UTC](https://meta.appinn.net/t/topic/56187/4 "2024-05-08T11:57:47Z")

</div>

[GitHub - softprops/action-gh-release: 📦 GitHub Action for creating GitHub Releases](https://github.com/softprops/action-gh-release) 设置`repository`可以推送到其他仓库，可能需要设置token来获取其他仓库的写入权限。

---

<div class="post-metadata">

作者： ![shadows](https://meta-edge.appinn.com/user_avatar/meta.appinn.net/shadows/32/17001_2.png) [@shadows](https://meta.appinn.net/u/shadows)\
发布日期： [2024 年5 月 8 日 13:46 UTC](https://meta.appinn.net/t/topic/56187/5 "2024-05-08T13:46:42Z")

</div>

最简单：私有仓库运行action时，也一并推送到另一个仓库的release就是了，去生成一个拥有你公开仓库content项write权限的token，填到私有仓库github action里发布release的那个action设置

基本所有这种功能的action都有这功能，自定义token与目标。 **建议你把你用来发布release的那个action的文档看一遍**

你的想法也可行，只不过更适合来源不受你控制，但想同步。例如，备份某些公开仓库的release

另外一个比较神经质和折腾的方法是：

1. 私有仓库运行action：把文件放到artifact里，然后通过rest api触发公开仓库的action运行(通过input传参)
2. 然后公开仓库：从input里读参数，用 [GitHub - actions/download-artifact](https://github.com/actions/download-artifact) v4下载私有仓库的artifact，然后发布

绝对可行，但明显过于复杂且浪费时间，并且需要对Github action了解深入些，不推荐使用尝试 :joy:

---

<div class="post-metadata">

作者： ![Stars-One](https://meta-edge.appinn.com/user_avatar/meta.appinn.net/stars-one/32/21660_2.png) [@Stars-One](https://meta.appinn.net/u/Stars-One)\
发布日期： [2024 年5 月 10 日 01:53 UTC](https://meta.appinn.net/t/topic/56187/6 "2024-05-10T01:53:30Z")

</div>

感谢上面几个大佬的思路,目前我的实现方式:

> 先通过action下载已发布release的版本的所有资源文件,之后再对私有库进行发布一个新的release,并上传之前下载的资源文件

```auto
name: Build Release Binaries

on:
  push:
    tags:
      - '*'

jobs:
	#生成的二进制上传到公开库
  sysnc-release:
    runs-on: ubuntu-latest

    permissions:
      contents: write

    steps:
      # 下载最新版本的资源文件
      - name: download latest release asset files
        uses: robinraju/release-downloader@v1.10
        with:
          # 当前私有库
          repository: 'stars-one/XnApp-PC'
          latest: true
          token: ${{ secrets.MY_PERSON_TOKEN }}
		  # 下载所有资源文件
          fileName: '*'

      - name: Check for new release
        run: echo "A new release was published"

      - name: Draft Release
        uses: ncipollo/release-action@v1
        with:
          draft: false
          allowUpdates: true
          generateReleaseNotes: true #自动生成发行说明。
          tag: "${{ github.ref_name }}"
          owner: "stars-one"
          repo: "XnApp-PC-Release"
          artifacts: '${{ github.workspace }}/*'
          token: ${{ secrets.MY_PERSON_TOKEN }}

```
