From 7792e29065b94b9246ac70686c9cab08cb624ce5 Mon Sep 17 00:00:00 2001 From: Timofei Larkin Date: Mon, 26 May 2025 16:44:48 +0300 Subject: [PATCH] Detail errors for workflows Signed-off-by: Timofei Larkin --- .github/workflows/pull-requests-release.yaml | 32 +++++++++++--------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/.github/workflows/pull-requests-release.yaml b/.github/workflows/pull-requests-release.yaml index 49fc63c6..1e82175c 100644 --- a/.github/workflows/pull-requests-release.yaml +++ b/.github/workflows/pull-requests-release.yaml @@ -96,34 +96,36 @@ jobs: repo: context.repo.repo, ref: `tags/${tag}` }); + const commitSha = ref.data.object.sha; try { - // Check if branch exists await github.rest.repos.getBranch({ owner: context.repo.owner, - repo: context.repo.repo, + repo: context.repo.repo, branch }); - - // Force update existing branch to the tag commit + await github.rest.git.updateRef({ owner: context.repo.owner, - repo: context.repo.repo, - ref: `refs/heads/${branch}`, - sha: commitSha, + repo: context.repo.repo, + ref: `heads/${branch}`, + sha: commitSha, force: true }); console.log(`🔁 Force-updated '${branch}' to ${commitSha}`); } catch (err) { - // Branch doesn't exist, create it - await github.rest.git.createRef({ - owner: context.repo.owner, - repo: context.repo.repo, - ref: `refs/heads/${branch}`, - sha: commitSha - }); - console.log(`✅ Created branch '${branch}' at ${commitSha}`); + if (err.status === 404) { + await github.rest.git.createRef({ + owner: context.repo.owner, + repo: context.repo.repo, + ref: `refs/heads/${branch}`, + sha: commitSha + }); + console.log(`✅ Created branch '${branch}' at ${commitSha}`); + } else { + console.error('Unexpected error --', err); + } } # Get the latest published release