Use GitHub Actions to create a tag but not a release

Viewed 17320

Currently on my GitHub repository, I have the following workflow that releases a nightly snapshot every day, and uses the current date as release name and tag name:

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 labels all snapshots created this way as the latest release. However, I want to avoid this, and achieve something akin to what Swift's snapshots are like: the snapshots are only tags; although they appear among the releases, they're treated differently.

How should I modify my workflow file to make this happen? Thanks!

3 Answers

Another option is to use GitHub Script. This creates a lightweight tag called <tagname> (replace this with the name of your tag):

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

Edit: Michael Ganß's solution is better.


I found this GitHub action that tags on demand. Using it, my workflow can be revised as such:

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

I succeed with only : git tag + git push
I'm using gitVersion to automatically generate the tag

  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
Related