Skip to content
\n

This step succeeds when the tag exists and fails (Unhandled error: HttpError: Not Found) when the tag doesn't. Instead I would like the step to succeed for both 200 and 404 responses (but not 400, 401 etc) and to be able to tell the difference between 200 and 404 in the following steps. For example it would return an empty result when the response is 404, or it could return the response status itself (since I don't use the body of the getReleaseByTag() response at the moment). I found discussions on how to do this by invoking the underlying REST API (#386) but I'd rather find a way to do it using the more convenient getReleaseByTag() method. Any suggestion on how to do this?

\n

Regards,

\n

Thomas

","upvoteCount":1,"answerCount":2,"acceptedAnswer":{"@type":"Answer","text":"

Hi @joshmgross,

\n

Thanks, you've pointed me in the right direction. With the code that you've posted, the step was still failing with an HttpError but then I noticed an extra message: Promise { <pending> }. I believe the issue is that getReleaseByTag() returns a Promise and so I modified your code like this and it seems to work now:

\n
- name: Check if release already exists\n  if: env.VERSION != ''\n  uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1\n  id: check-release\n  with:\n    script: |\n      const { VERSION } = process.env\n      return github.rest.repos.getReleaseByTag({\n        owner: context.repo.owner,\n        repo: context.repo.repo,\n        tag: `v${VERSION}`,\n      }).then(function(result) {\n        core.info(`Release ${result.data.name} found`)\n        return result.data.name\n      }).catch(function(error) {\n        if (error.status === 404) {\n          core.info(`Release v${VERSION} not found`)\n          return\n        } else {\n          throw error\n        }\n      })\n    result-encoding: string
\n

Again I am not a node expert so maybe I am missing something but the workflow seems to work now so thanks again,

\n

Thomas

","upvoteCount":1,"url":"https://github.com/actions/github-script/discussions/468#discussioncomment-9194478"}}}
Discussion options

You must be logged in to vote

Hi @joshmgross,

Thanks, you've pointed me in the right direction. With the code that you've posted, the step was still failing with an HttpError but then I noticed an extra message: Promise { <pending> }. I believe the issue is that getReleaseByTag() returns a Promise and so I modified your code like this and it seems to work now:

- name: Check if release already exists
  if: env.VERSION != ''
  uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
  id: check-release
  with:
    script: |
      const { VERSION } = process.env
      return github.rest.repos.getReleaseByTag({
        owner: context.repo.owner,
        repo: context.repo.repo,
        tag: `v${VERSIO…

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by thomasleplus
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants