Can I maintain a single binary on GitHub outside git's tracking?

Viewed 381

I have a GitHub repository consisting of LaTeX code for my resume. Currently, I'm including the generated PDF file as a file in git, i.e. it's tracked in version control. The only purpose of including the PDF is to have a link to the latest resume PDF that I can send to people. Hence, I don't really need to track a binary file in version control at all.

Is there a way to get rid of tracking this binary through git? I'm thinking of generating the PDF with GitHub Actions, then uploading it somewhere. This way I don't have to include the PDF in git, while having a link to the latest build (off the master branch) that I can share. Does GitHub have a place where I can keep this PDF?

I've noticed that most GitHub release assets are available through a link like https://github.com/owner/repo/archive/file.tar.gz. Since I just want to maintain a single copy that is built with every commit, using GitHub releases would be overkill for this. Can I somehow "dump" the PDF from the latest build in https://github.com/me/resume/archive/resume.pdf? If not, is there any other way?

2 Answers

Your best bet is to have a single release and update that file again and again.

There's also artifacts for GitHub Actions, but they can only be downloaded by logged-in users.

Following up on @riQQ's answer, I was able to automate this using GitHub Actions. Here's a sample workflow YAML file:

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 }}

NOTE: This approach only works if you want to maintain a single release for the sole purpose of maintaining the binaries as release assets.

The binary will now be visible in the releases page, and its URL can be obtained.

Related