跟进@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。