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



我的简历有一个由LaTeX代码组成的GitHub仓库。目前,我将生成的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 ?如果不行,还有其他办法吗?

最好的办法是只发布一个版本,然后一次又一次地更新这个文件。

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

根据@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。

相关内容

最新更新