Use GitHub Actions to create a tag but not a release

Wowbagger and his liquid lunch picture Wowbagger and his liquid lunch · Apr 1, 2020 · Viewed 13.7k times · Source

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!

Answer

Michael Ganß picture Michael Ganß · Oct 22, 2020

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