【问题标题】:Can I make releases public from a private github repo?我可以从私人 github 存储库公开发布吗?
【发布时间】:2014-11-30 19:31:47
【问题描述】:

我有一个位于私人 github 存储库中的应用程序,我想知道是否可以公开发布,以便应用程序可以从 github 自动更新自身,而无需我们托管它。

此外,我想知道是否可以使用已部署应用程序中的 github api 来检查新更新。

【问题讨论】:

  • 不,目前无法在私有存储库中发布公开版本。是的,您可以使用 API 检查是否有新版本 -- 使用发布 API:developer.github.com/v3/repos/releases
  • 有什么消息吗?这是一个 5 年前的问题,需要一个功能。

标签: github github-api


【解决方案1】:

正如@VonC 提到的,我们必须为此创建第二个存储库。这不是禁止的,我已经在这样做了。通过 github 工作流,我自动化了这个任务,我使用了开发/主分支,所以当我将任何东西推送到主分支时,总是会构建一个新版本并将其推送到公共“Realease”回购。

在我的特定用例中,我正在构建一个 android apk 并通过非官方的 github api“集线器”发布它。这样做的一些额外优势是您可以有一个额外的问题跟踪器来跟踪外部问题和错误。

name: Master CI CD

# using checkout@v2 instead of v1 caus it needs further configuration

on:
  pull_request:
    types: [closed]

jobs:
  UnitTest:
    runs-on: ubuntu-latest
    if: github.event.pull_request.merged
    steps:
      - uses: actions/checkout@v2
      - name: make executable
        run: chmod +x gradlew
      - name: Unit tests
        run: |
          ./gradlew test
  IncrementVersionCode:
    needs: UnitTest
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - name: set up JDK 1.8
        uses: actions/setup-java@v1
        with:
          java-version: 1.8
      - name: make executable
        run: chmod +x gradlew
      - name: increment version
        run: ./gradlew incrementVersionCode
      - name: Push new version to master
        run: |
          git config --local user.email "workflow@bot.com"
          git config --local user.name "WorkflowBot"
          git commit -m "Increment Build version" -a
          # maybe better amend commits to avoid bot commits
  BuildArtifacts:
    needs: IncrementVersionCode
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - name: set up JDK 1.8
        uses: actions/setup-java@v1
        with:
          java-version: 1.8
      - name: make executable
        run: chmod +x gradlew
      - name: Build with Gradle
        run: ./gradlew build -x lint

      - name: Rename artifacts
        run: |
          cp app/build/outputs/apk/release/app-release.apk MyApp.apk
      - name: Upload Release
        uses: actions/upload-artifact@master
        with:
          name: Release Apk
          path: MyApp.apk
      - name: Upload Debug
        uses: actions/upload-artifact@master
        with:
          name: Debug Apk
          path: app/build/outputs/apk/debug/app-debug.apk

  # https://dev.to/ychescale9/running-android-emulators-on-ci-from-bitrise-io-to-github-actions-3j76
  E2ETest:
    needs: BuildArtifacts
    runs-on: macos-latest
    strategy:
      matrix:
        api-level: [21, 27]
        arch: [x86]
    steps:
      - name: checkout
        uses: actions/checkout@v2
      - name: Make gradlew executable
        run: chmod +x ./gradlew
      - name: run tests
        uses: reactivecircus/android-emulator-runner@v2
        with:
          api-level: ${{ matrix.api-level }}
          arch: ${{ matrix.arch }}
          script: ./gradlew connectedCheck

  Deploy:
    needs: E2ETest
    runs-on: ubuntu-latest
    if: github.ref == 'refs/heads/master'
    steps:
      - uses: actions/checkout@v2 # Needed for gradle file to get version information
      - name: Get Hub
        run: |
          curl -fsSL https://github.com/github/hub/raw/master/script/get | bash -s 2.14.1
          cd bin
          chmod +x hub
          cd ..
      - name: Get Apk
        uses: actions/download-artifact@master
        with:
          name: Release Apk
      - name: Publish
        env:
          GITHUB_TOKEN: "${{ secrets.RELEASE_REPO_SECRET }}"
        run: |
          APP_NAME=MyApp
          VERSION_NAME=`grep -oP 'versionName "\K(.*?)(?=")' ./app/build.gradle`
          VERSION_CODE=`cat version.properties | grep "VERSION_CODE" | cut -d'=' -f2`
          FILENAME="${APP_NAME}-v${VERSION_NAME}-${VERSION_CODE}"
          TAG="v${VERSION_NAME}-${VERSION_CODE}"
          TAG="latest-master"
          echo $APP_NAME
          echo $VERSION_NAME
          echo $VERSION_CODE
          echo $FILENAME
          echo $TAG
          git clone https://github.com/MyUser/MyApp-Releases
          cd MyApp-Releases
          ./../bin/hub release delete "${TAG}" || echo "Failed deleting TAG: ${TAG}" # If release got lost catch error with message
          ./../bin/hub release create -a "../${APP_NAME}.apk" -m "Current Master Build: ${FILENAME}" -p "${TAG}"
  EvaluateCode:
    needs: Deploy
    runs-on: ubuntu-latest
    steps:
      - name: Get Hub
        run: |
          echo "TDOO: Run Jacoco for coverage, and other profiling tools"

【讨论】:

  • 很好地使用了 GitHub Actions,肯定比我 2014 年的回答更新。赞成。
【解决方案2】:

一种解决方法是创建一个公共回购,包括:

  • 空提交 (git commit --allow-empty)
  • 标记每个提交
  • 每个标签都有一个版本
  • 每个版本都包含交付(您的私有应用程序的二进制文件)

这样,您就有了一个专用于发布托管的可见存储库,以及一个用于源代码开发的私有存储库。

【讨论】:

  • 我不明白的是,为什么我要标记每个提交?为什么我不仅可以做一个空提交并标记它?我可能想多了,但是做rm -rf .git然后启动一个新的git并强制推送到新的open repo有什么区别
  • “为什么我不能只做一个空的提交并标记它?” :这是标记每个提交,因为您为每个版本创建一个(空或不)提交。您可以将发布与标签相关联,因此需要为每个提交/发布创建一个标签。
  • 哪里有这样的例子?
  • @hamaney 不直接可见(因为涉及私有存储库)
  • 一般我在Github网站上传
猜你喜欢
  • 2021-09-29
  • 1970-01-01
  • 2015-09-24
  • 1970-01-01
  • 2021-11-30
  • 2019-01-19
  • 2019-11-08
  • 1970-01-01
  • 2018-09-24
相关资源
最近更新 更多