我可以在 GitHub 上在 git 跟踪之外维护一个二进制文件吗?

时间:2021-02-24 16:26:18

标签: github github-actions github-release

我有一个 GitHub 存储库,其中包含用于我的简历的 LaTeX 代码。目前,我将生成的 PDF 文件作为文件包含在 git 中,即在版本控制中进行跟踪。包含 PDF 的唯一目的是提供指向我可以发送给人们的最新简历 PDF 的链接。因此,我根本不需要在版本控制中跟踪二进制文件。

有没有办法摆脱通过 git 跟踪这个二进制文件?我正在考虑使用 GitHub Actions 生成 PDF,然后将其上传到某个地方。这样我就不必在 git 中包含 PDF,同时拥有指向我可以共享的最新版本(在 master 分支之外)的链接。 GitHub 有可以保存此 PDF 的地方吗?

我注意到大多数 GitHub 发布资产都可以通过 https://github.com/owner/repo/archive/file.tar.gz 之类的链接获得。由于我只想维护一个随每次提交而构建的副本,因此使用 GitHub 版本将是过度的。我可以以某种方式从 https://github.com/me/resume/archive/resume.pdf 中的最新版本“转储”PDF 吗?如果没有,还有其他方法吗?

2 个答案:

答案 0 :(得分:1)

最好的办法是发布一个版本并一次又一次地更新该文件。

GitHub Actions 也有工件,但只能由登录用户下载。

答案 1 :(得分:1)

根据@riQQ 的回答,我能够使用 GitHub Actions 自动执行此操作。这是一个示例工作流 YAML 文件:

name: Update binary
on:
  push:
    branches:
      - master

jobs:
  build:
    name: Update binary
    runs-on: ubuntu-latest
    steps:
      # Checkout the repo at the commit which triggered this job
      - name: Set up git repo
        uses: actions/checkout@v2
        with:
          fetch-depth: 0  # used to get the tag of the latest release

      # TODO: Action for compiling and generating the binary
      - name: Compile code

      # Removes the latest release, so that we can create a new one in its place
      - name: Delete latest release
        uses: ame-yu/action-delete-latest-release@v2
        with:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

      # (optional) Removes the tag associated with the latest release
      - name: Delete release tag
        run: |
          git tag -d release
          git push origin :release
        continue-on-error: true # in case there's no existing release
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

      # Creates the new release with the binary as a release asset.
      # If the previous Action was skipped, then this keeps the same tag as the
      # previous release.
      - name: Create new release
        uses: softprops/action-gh-release@v1
        with:
          body: "Release notes"
          name: Latest
          tag_name: release
          files: /path/to/binary
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

注意:此方法仅适用于您希望维护单个版本的唯一目的是将二进制文件作为版本资产进行维护。

二进制文件现在将在发布页面中可见,并且可以获取其 URL。