GitHub Action with MacOS-latest : Process completed with exit code 1 : with grep and curl command

317 views Asked by At

Introduction

Currently, I'm writing a customized GitHub workflow inside it I use a curl and grep command.
GitHub repo

action.yml

    - name: get new tag
      id: get_new_tag
      shell: bash
      run: |
        temp_result=$(curl -s https://api.github.com/repos/${{inputs.github_repository}}/tags | grep -h "name" | grep -h "${{inputs.selector}}" |  head -1 | grep -ho "${{inputs.regex}}")
        echo "new-tag=${temp_result}" >> $GITHUB_OUTPUT

Full code here

test for action.yml

        uses: ./
        with:
          files: tests/test1.txt tests/test2.txt
          github_repository: MathieuSoysal/file-updater-for-release
          prefix: MathieuSoysal/file-updater-for-release@

Full code are is here

Problem

I don't understand why but my GitHub Actions don't work with MacOS.

The given error:

  temp_result=$(curl -s https://api.github.com/repos/MathieuSoysal/file-updater-for-release/tags | grep -h "name" | grep -h "" |  head -1 | grep -ho "v\?[0-9.]*")
  echo "new-tag=${temp_result}" >> $GITHUB_OUTPUT
  shell: /bin/bash --noprofile --norc -e -o pipefail {0}
Error: Process completed with exit code 1.

Full log error is here

Question

Does someone know how we can fix this issue?

2

There are 2 answers

0
ThrowsError On

The issue is from this command grep -h "", this command is not supported on MacOS.

The empty string is not supported, the solution is to add something inside it.

0
Azeem On

Alternatively, you can simply use the jq command line utility for this which is already installed and available on the GitHub runners. See the preinstalled software.

$ export URL='https://api.github.com/repos/MathieuSoysal/file-updater-for-release/tags'
$ curl -s $URL | jq -r .[0].name
v1.0.3