Use GitHub action logging in workflows

This commit is contained in:
Marcono1234 2024-03-07 21:50:44 +01:00
Родитель bf8064f335
Коммит 6df9e2f401
3 изменённых файлов: 16 добавлений и 15 удалений

Просмотреть файл

@ -26,7 +26,7 @@ jobs:
// Check if issue contains code block // Check if issue contains code block
if (issueBody.includes('```')) { if (issueBody.includes('```')) {
console.log('Issue body seems to contain code block; skipping formatting') core.info('Issue body seems to contain code block; skipping formatting')
return return
} }
@ -35,9 +35,9 @@ jobs:
const newIssueBody = issueBody.replace(crashReportPattern, '\n```\n$&\n```\n') const newIssueBody = issueBody.replace(crashReportPattern, '\n```\n$&\n```\n')
if (newIssueBody === issueBody) { if (newIssueBody === issueBody) {
console.log('Did not find crash report in issue body') core.info('Did not find crash report in issue body')
} else { } else {
console.log('Found crash report in issue body, formatting it') core.notice('Found crash report in issue body, formatting it')
github.rest.issues.update({ github.rest.issues.update({
owner: owner, owner: owner,
repo: repo, repo: repo,

Просмотреть файл

@ -24,7 +24,7 @@ jobs:
const sender = context.payload.sender.login const sender = context.payload.sender.login
if (issue.user.login !== sender) { if (issue.user.login !== sender) {
console.log('Ignoring comment by user other than author') core.info('Ignoring comment by user other than author')
return return
} }
@ -32,11 +32,11 @@ jobs:
const issueLabels = issue.labels.map(label => label.name) const issueLabels = issue.labels.map(label => label.name)
if (issueLabels.includes(reportedUpstreamLabel)) { if (issueLabels.includes(reportedUpstreamLabel)) {
console.log('Ignoring issue because it already has upstream label') core.info('Ignoring issue because it already has upstream label')
return return
} }
if (!issueLabels.includes('Minecraft')) { if (!issueLabels.includes('Minecraft')) {
console.log('Ignoring issue because it is not labeled as Minecraft') core.info('Ignoring issue because it is not labeled as Minecraft')
return return
} }
@ -47,10 +47,10 @@ jobs:
const matchedMojiraIssueKey = /(?<!\w)MC-\d{6,}(?!\w)(?<!MC-123456)/i.exec(commentBody) const matchedMojiraIssueKey = /(?<!\w)MC-\d{6,}(?!\w)(?<!MC-123456)/i.exec(commentBody)
if (matchedMojiraIssueKey === null) { if (matchedMojiraIssueKey === null) {
console.log('Did not find Mojira issue key in comment') core.info('Did not find Mojira issue key in comment')
} }
else { else {
console.log(`Found Mojira issue key ${matchedMojiraIssueKey[0]}, adding label`) core.notice(`Found Mojira issue key ${matchedMojiraIssueKey[0]}, adding label`)
const owner = context.repo.owner const owner = context.repo.owner
const repo = context.repo.repo const repo = context.repo.repo

15
.github/workflows/minecraft-crash.yml поставляемый
Просмотреть файл

@ -53,26 +53,26 @@ jobs:
const foundModdedStrings = moddedStrings.filter(s => issueBody.includes(s)) const foundModdedStrings = moddedStrings.filter(s => issueBody.includes(s))
if (foundModdedStrings.length === 0) { if (foundModdedStrings.length === 0) {
console.log('Did not find modded string in issue body, searching attachments') core.info('Did not find modded string in issue body, searching attachments')
// Try searching in attachments // Try searching in attachments
// There is currently no API so try to find URL then get attachment content, see https://github.community/t/get-files-attached-in-issue/117443 // There is currently no API so try to find URL then get attachment content, see https://github.community/t/get-files-attached-in-issue/117443
const attachmentPattern = new RegExp(`https://github\\.com/${owner}/${repo}/files/\\d+/[a-zA-Z0-9_\\-.]+`, 'g') const attachmentPattern = new RegExp(`https://github\\.com/${owner}/${repo}/files/\\d+/[a-zA-Z0-9_\\-.]+`, 'g')
const attachmentUrls = Array.from(issueBody.matchAll(attachmentPattern), m => m[0]) const attachmentUrls = Array.from(issueBody.matchAll(attachmentPattern), m => m[0])
console.log('Found attachment URLs', attachmentUrls) core.info(`Found attachment URLs: ${attachmentUrls}`)
for (const url of attachmentUrls) { for (const url of attachmentUrls) {
let attachment = undefined let attachment = undefined
try { try {
attachment = await httpGet(url) attachment = await httpGet(url)
} catch (e) { } catch (e) {
// Only log message because complete error is rather verbose // Only log message because complete error is rather verbose
console.log('Failed getting attachment for ' + url, e.message) core.warning(`Failed getting attachment for ${url}: ${e.message}`)
continue continue
} }
if (!isMinecraftIssue) { if (!isMinecraftIssue) {
isMinecraftIssue = minecraftRegex.test(attachment) isMinecraftIssue = minecraftRegex.test(attachment)
if (isMinecraftIssue) { if (isMinecraftIssue) {
console.log('Found Minecraft string in attachment') core.info('Found Minecraft string in attachment')
} }
} }
@ -87,14 +87,15 @@ jobs:
let isCrashFromModdedMinecraft = foundModdedStrings.length > 0 let isCrashFromModdedMinecraft = foundModdedStrings.length > 0
if (isCrashFromModdedMinecraft) { if (isCrashFromModdedMinecraft) {
console.log('Found modded strings', foundModdedStrings) core.notice(`Found modded strings: ${foundModdedStrings}`)
} else { } else {
console.log('Did not find modded strings') core.info('Did not find modded strings')
} }
isMinecraftIssue = isMinecraftIssue || isCrashFromModdedMinecraft isMinecraftIssue = isMinecraftIssue || isCrashFromModdedMinecraft
console.log('Is Minecraft issue: ' + isMinecraftIssue)
if (isMinecraftIssue) { if (isMinecraftIssue) {
core.notice('Detected issue to be about Minecraft')
let commentBody let commentBody
if (isCrashFromModdedMinecraft) { if (isCrashFromModdedMinecraft) {
// Don't tell user to report modded crashes on Mojang's bug tracker; they will most likely be considered Invalid // Don't tell user to report modded crashes on Mojang's bug tracker; they will most likely be considered Invalid