【问题标题】:Use GitHub Actions to create a tag but not a release使用 GitHub Actions 创建标签而不是发布
【发布时间】:2020-07-12 18:46:19
【问题描述】:

目前在我的 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 的效果:快照只是标签;尽管它们出现在版本中,但它们的处理方式不同。

我应该如何修改我的工作流程文件来实现这一点?谢谢!

【问题讨论】:

    标签: github github-api github-actions git-tag github-release


    【解决方案1】:

    另一种选择是使用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 自己的操作。奇迹般有效。感谢发帖
    • tagname 将包含用于命名您的标签的值
    【解决方案2】:

    编辑: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.com/simpleactions/create-tag
    • 为什么 Michael Ganß 的解决方案更好?这似乎更简洁。
    • Michael Ganß 的解决方案直接使用 GitHub 自己的 API,而不是通过第三方操作。
    猜你喜欢
    • 2021-02-10
    • 2021-12-10
    • 2022-10-25
    • 1970-01-01
    • 2023-02-22
    • 2015-04-14
    • 2020-07-25
    • 1970-01-01
    • 2020-04-16
    相关资源
    最近更新 更多