GitHub Action - Error undefined: No tag found in ref or input

Viewed 1227

I am trying to create a GitHub action that will detect when a change has happened on a certain branch and then build a release. The problem I’m getting is that in my yml file I use this line:

ncipollo/release-action@v1. This requires a tag to be available otherwise it will fail. I have created and pushed a tag but when I run the action I get this error

Error undefined: No tag found in ref or input!

This is my yml file:

# Creates a release whenever a new change gets pushed onto the dev branch
# https://github.com/ncipollo/release-action

name: Dev-Build
on:  
  push:
    branches:
      - dev
jobs:
  build:
    name: setup environment 
    runs-on: ubuntu-latest
    strategy:
      matrix:
        node-version: [12.x]

    steps:
      - uses: actions/checkout@v2
        with:
          fetch-depth: 0
      - name: Cache node modules
        uses: actions/cache@v2.1.3
        with:
          path: ~/.npm
          key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
          restore-keys: |
            ${{ runner.os }}-node-
            
      - name: Node ${{ matrix.node-version }}
        uses: actions/setup-node@v1.4.4
        with:
          node-version: ${{ matrix.node-version }}
        
      - name: npm install      
        run: |
          npm i
          npm run build:ci  
      - name: Create Release
        uses: ncipollo/release-action@v1
        with:
          token: ${{ secrets.TOKEN }}
2 Answers

By default, the tags are not pulled from a remote using checkout action:

Only a single commit is fetched by default, for the ref/SHA that triggered the workflow. Set fetch-depth: 0 to fetch all history for all branches and tags.

See the docs how to fetch all history for all tags and branches:

steps:
 - uses: actions/checkout@v2
   with:
     fetch-depth: 0

The solution was to change the trigger to be when a tag gets pushed

name: Dev-Build
on:
  create:
    tags:
      - v*
Related