Wow*_*nch 5 github github-api git-tag github-release github-actions
目前在我的 GitHub 存储库中,我有以下每天发布夜间快照的工作流程,并使用当前日期作为发布名称和标签名称:
name: Nightly Snapshot
on:
schedule:
- cron: "59 23 * * *"
jobs:
build:
name: Release
runs-on: ubuntu-latest
steps:
- name: Get current date
id: date
run: echo "::set-output name=date::$(date +'%Y-%m-%d')"
- name: Checkout branch "master"
uses: actions/checkout@v2
with:
ref: 'master'
- name: Release snapshot
id: release-snapshot
uses: actions/create-release@latest
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ steps.date.outputs.date }}
release_name: ${{ steps.date.outputs.date }}
draft: false
prerelease: false
Run Code Online (Sandbox Code Playgroud)
GitHub 将所有以这种方式创建的快照标记为最新版本。但是,我想避免这种情况,并实现类似于Swift 快照的效果:快照只是标签;尽管它们出现在版本中,但它们的处理方式不同。
我应该如何修改我的工作流程文件来实现这一点?谢谢!
小智 29
另一种选择是使用GitHub Script。这将创建一个名为 的轻量级标签tagname:
- name: Create tag
uses: actions/github-script@v3
with:
github-token: ${{ github.token }}
script: |
github.git.createRef({
owner: context.repo.owner,
repo: context.repo.repo,
ref: "refs/tags/tagname",
sha: context.sha
})
Run Code Online (Sandbox Code Playgroud)
编辑:Michael Ganß 的解决方案更好。
我发现这个 GitHub action按需标记。使用它,我的工作流程可以这样修改:
name: Nightly Snapshot
on:
schedule:
- cron: "59 23 * * *"
jobs:
tag:
name: Tag
runs-on: ubuntu-latest
steps:
- name: Get current date
id: date
run: echo "::set-output name=date::$(date +'%Y-%m-%d')"
- name: Checkout branch "master"
uses: actions/checkout@v2
with:
ref: 'master'
- name: Tag snapshot
uses: tvdias/github-tagger@v0.0.1
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
tag: ${{ steps.date.outputs.date }}
Run Code Online (Sandbox Code Playgroud)
我仅成功: git tag + git push
我正在使用 gitVersion 自动生成标签
semver:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Install GitVersion
uses: gittools/actions/gitversion/setup@v0.9.7
with:
versionSpec: '5.x'
- name: Determine Version
uses: gittools/actions/gitversion/execute@v0.9.7
- name: Display SemVer
run: |
echo "SemVer: $GITVERSION_SEMVER" && echo "$version" && echo "$major.$minor.$patch"
- name: Create git tag
run: |
git tag $GITVERSION_SEMVER
- name: Push git tag
run: git push origin $GITVERSION_SEMVER
Run Code Online (Sandbox Code Playgroud)