使用 GitHub 操作来创建标签而不是发布
Use GitHub Actions to create a tag but not a release
目前在我的 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
GitHub 将以这种方式创建的所有快照标记为最新版本。但是,我想避免这种情况,并实现类似于 what Swift's snapshots are like 的效果:快照只是标签;尽管它们出现在发行版中,但它们的处理方式不同。
我应该如何修改我的工作流文件来实现这一点?谢谢!
编辑:Michael Ganß 的解决方案更好。
我发现 this 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 }}
另一种选择是使用 GitHub Script。这将创建一个名为 <tagname>
的轻量级标签(将其替换为您的标签名称):
- name: Create tag
uses: actions/github-script@v5
with:
script: |
github.rest.git.createRef({
owner: context.repo.owner,
repo: context.repo.repo,
ref: 'refs/tags/<tagname>',
sha: context.sha
})
目前在我的 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
GitHub 将以这种方式创建的所有快照标记为最新版本。但是,我想避免这种情况,并实现类似于 what Swift's snapshots are like 的效果:快照只是标签;尽管它们出现在发行版中,但它们的处理方式不同。
我应该如何修改我的工作流文件来实现这一点?谢谢!
编辑:Michael Ganß 的解决方案更好。
我发现 this 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 }}
另一种选择是使用 GitHub Script。这将创建一个名为 <tagname>
的轻量级标签(将其替换为您的标签名称):
- name: Create tag
uses: actions/github-script@v5
with:
script: |
github.rest.git.createRef({
owner: context.repo.owner,
repo: context.repo.repo,
ref: 'refs/tags/<tagname>',
sha: context.sha
})