- Notifications
You must be signed in to change notification settings - Fork469
Catching 404 response when calling github.rest.repos.getReleaseByTag()#468
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
-
Hi, I apologize in advance if this is a beginner's question but I am not a node expert so I am struggling a bit to do something that is probably pretty simple. I currently have the following step in my workflow: -name:Check if release already existsid:check-releaseuses:actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea# v7.0.1script:| const { VERSION } = process.env github.rest.repos.getReleaseByTag({ owner: context.repo.owner, repo: context.repo.repo, tag: `v${VERSION}`, }) This step succeeds when the tag exists and fails ( Regards, Thomas |
BetaWas this translation helpful?Give feedback.
All reactions
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 existsif:env.VERSION != ''uses:actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea# v7.0.1id:check-releasewith:script:| const { VERSION } = process.env return github.rest.repos.getReleaseByTag({ owner: context.repo.owner, repo: context.repo.repo, tag: `v${VERSIO…
Replies: 2 comments
-
👋 Hey@thomasleplus, I think something like this would work for you: try{const{VERSION}=process.envgithub.rest.repos.getReleaseByTag({owner:context.repo.owner,repo:context.repo.repo,tag:`v${VERSION}`,})core.info(`Release v${VERSION} found`)}catch(error){if(error.status===404){core.info(`Release v${VERSION} not found`)}else{throwerror}} That's based on the error handling example inhttps://github.com/octokit/request-error.js |
BetaWas this translation helpful?Give feedback.
All reactions
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
-
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: -name:Check if release already existsif:env.VERSION != ''uses:actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea# v7.0.1id:check-releasewith:script:| const { VERSION } = process.env return github.rest.repos.getReleaseByTag({ owner: context.repo.owner, repo: context.repo.repo, tag: `v${VERSION}`, }).then(function(result) { core.info(`Release ${result.data.name} found`) return result.data.name }).catch(function(error) { if (error.status === 404) { core.info(`Release v${VERSION} not found`) return } else { throw error } })result-encoding:string Again I am not a node expert so maybe I am missing something but the workflow seems to work now so thanks again, Thomas |
BetaWas this translation helpful?Give feedback.