Skip to content

Commit 8dfbcba

Browse files
hudeng-goBLumia
authored andcommitted
fix: auto-tag workflow error
1 parent 78a1b5f commit 8dfbcba

1 file changed

Lines changed: 50 additions & 19 deletions

File tree

.github/workflows/auto-tag.yml

Lines changed: 50 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,10 @@ on:
77
required: true
88
APP_PRIVATE_KEY:
99
required: true
10-
TRANSIFEX_API_TOKEN:
11-
required: true
1210

1311
env:
1412
APP_ID: ${{ secrets.APP_ID }}
1513
APP_PRIVATE_KEY: ${{ secrets.APP_PRIVATE_KEY }}
16-
TRANSIFEX_API_TOKEN: ${{ secrets.TRANSIFEX_API_TOKEN }}
1714

1815
jobs:
1916
auto_tag:
@@ -136,22 +133,30 @@ jobs:
136133
core.info("UNRELEASED will not create tag")
137134
return
138135
}
139-
const { data } = await github.rest.git.createTag({
140-
repo: context.repo.repo,
141-
owner: context.repo.owner,
142-
message: "Release " + context.repo.repo + " ${{ steps.get-tag.outputs.TAG }}\n",
143-
type: 'commit',
144-
object: context.sha,
145-
tag: "${{ steps.get-tag.outputs.TAG }}",
146-
tagger: {
147-
name: "${{ github.event.pull_request.user.login }}",
148-
email: "${{ steps.get-email.outputs.email }}",
149-
date: (() => {
150-
const date = new Date();
151-
return date.toISOString();
152-
})(),
153-
},
154-
})
136+
let data
137+
const mergeCommitSha = context.payload.pull_request.head.sha
138+
try {
139+
const tagResult = await github.rest.git.createTag({
140+
repo: context.repo.repo,
141+
owner: context.repo.owner,
142+
message: "Release " + context.repo.repo + " ${{ steps.get-tag.outputs.TAG }}\n",
143+
type: 'commit',
144+
object: mergeCommitSha,
145+
tag: "${{ steps.get-tag.outputs.TAG }}",
146+
tagger: {
147+
name: "${{ github.event.pull_request.user.login }}",
148+
email: "${{ steps.get-email.outputs.email }}",
149+
date: (() => {
150+
const date = new Date();
151+
return date.toISOString();
152+
})(),
153+
},
154+
})
155+
data = tagResult.data
156+
} catch (error) {
157+
core.setFailed(`Failed to create tag: ${error.message}`)
158+
throw error
159+
}
155160
156161
const res = await github.rest.git.createRef({
157162
owner: context.repo.owner,
@@ -167,6 +172,31 @@ jobs:
167172
tag_name: '${{ steps.get-tag.outputs.TAG }}',
168173
})
169174
175+
// Comment tag creation status on PR
176+
const tag_body = "**TAG Bot**\n\n" +
177+
"✅ **Tag created successfully**\n\n" +
178+
"<details>\n" +
179+
"<summary>📋 Tag Details</summary>\n" +
180+
"\n" +
181+
"- **Tag Name**: `" + data.tag + "`\n" +
182+
"- **Tag SHA**: `" + data.sha + "`\n" +
183+
"- **Commit SHA**: `" + mergeCommitSha + "`\n" +
184+
"- **Tag Message**:\n" +
185+
" ```\n" +
186+
" " + data.message + "\n" +
187+
" ```\n" +
188+
"- **Tagger**:\n" +
189+
" - Name: " + data.tagger.name + "\n" +
190+
"- **Distribution**: " + distribution + "\n" +
191+
"</details>"
192+
193+
await github.rest.issues.createComment({
194+
issue_number: context.issue.number,
195+
owner: context.repo.owner,
196+
repo: context.repo.repo,
197+
body: tag_body
198+
})
199+
170200
// Add a reminder for needed rebase to PR in open state
171201
const BOT_NAME = "TAG Bot"
172202
const COMMENT_HEAD = "**" + BOT_NAME + "**\n\n"
@@ -195,3 +225,4 @@ jobs:
195225
}
196226
}
197227
}
228+

0 commit comments

Comments
 (0)