Skip to content

Commit

Permalink
Merge pull request #595 from Marcono1234/improve-workflows
Browse files Browse the repository at this point in the history
Improve GitHub workflows
  • Loading branch information
karianna authored Mar 8, 2024
2 parents 3ff85ba + 6df9e2f commit 8bbfd21
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 30 deletions.
6 changes: 6 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
version: 2
updates:
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "monthly"
11 changes: 7 additions & 4 deletions .github/workflows/format-crash-report-in-issue-body.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@ on:
issues:
types: [opened]

permissions:
issues: write

jobs:
format-crash-report:
runs-on: ubuntu-latest
steps:
- name: Format crash report
uses: actions/github-script@v6
uses: actions/github-script@v7
with:
script: |
const issueNumber = context.issue.number
Expand All @@ -23,7 +26,7 @@ jobs:
// Check if issue contains code block
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
}
Expand All @@ -32,9 +35,9 @@ jobs:
const newIssueBody = issueBody.replace(crashReportPattern, '\n```\n$&\n```\n')
if (newIssueBody === issueBody) {
console.log('Did not find crash report in issue body')
core.info('Did not find crash report in issue body')
} 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({
owner: owner,
repo: repo,
Expand Down
15 changes: 9 additions & 6 deletions .github/workflows/minecraft-crash-reported-upstream-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ on:
issue_comment:
types: [created, edited]

permissions:
issues: write

jobs:
check-reported-upstream:
runs-on: ubuntu-latest
Expand All @@ -11,7 +14,7 @@ jobs:
# Ignore pull request comments, see
# https://docs.github.com/en/actions/learn-github-actions/events-that-trigger-workflows#issue_comment
if: ${{ !github.event.issue.pull_request }}
uses: actions/github-script@v6
uses: actions/github-script@v7
with:
script: |
// See documentation for payload properties
Expand All @@ -21,19 +24,19 @@ jobs:
const sender = context.payload.sender.login
if (issue.user.login !== sender) {
console.log('Ignoring comment by user other than author')
core.info('Ignoring comment by user other than author')
return
}
const reportedUpstreamLabel = 'Reported Upstream'
const issueLabels = issue.labels.map(label => label.name)
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
}
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
}
Expand All @@ -44,10 +47,10 @@ jobs:
const matchedMojiraIssueKey = /(?<!\w)MC-\d{6,}(?!\w)(?<!MC-123456)/i.exec(commentBody)
if (matchedMojiraIssueKey === null) {
console.log('Did not find Mojira issue key in comment')
core.info('Did not find Mojira issue key in comment')
}
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 repo = context.repo.repo
Expand Down
36 changes: 16 additions & 20 deletions .github/workflows/minecraft-crash.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,15 @@ on:
issues:
types: [opened]

permissions:
issues: write

jobs:
check-minecraft-crash:
runs-on: ubuntu-latest
steps:
- uses: actions/setup-node@v3
with:
node-version: 16
- run: npm install axios
- name: Check Minecraft crash
uses: actions/github-script@v6
uses: actions/github-script@v7
with:
script: |
// Strings which indicate that Minecraft is modded
Expand All @@ -27,16 +26,12 @@ jobs:
'--fml.forgeVersion',
]
const axios = require('axios')
async function httpGet(url) {
const result = await axios.get(url, {
responseType: 'text'
})
const status = result.status
const data = result.data
const response = await fetch(url)
const status = response.status
const data = await response.text()
if (status < 200 || status >= 300) {
throw new Error(`GET request to ${url} failed with ${status} '${result.statusText}': ${data}`)
throw new Error(`GET request to ${url} failed with ${status} '${response.statusText}': ${data}`)
}
return data
}
Expand All @@ -58,26 +53,26 @@ jobs:
const foundModdedStrings = moddedStrings.filter(s => issueBody.includes(s))
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
// 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 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) {
let attachment = undefined
try {
attachment = await httpGet(url)
} catch (e) {
// 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
}
if (!isMinecraftIssue) {
isMinecraftIssue = minecraftRegex.test(attachment)
if (isMinecraftIssue) {
console.log('Found Minecraft string in attachment')
core.info('Found Minecraft string in attachment')
}
}
Expand All @@ -92,14 +87,15 @@ jobs:
let isCrashFromModdedMinecraft = foundModdedStrings.length > 0
if (isCrashFromModdedMinecraft) {
console.log('Found modded strings', foundModdedStrings)
core.notice(`Found modded strings: ${foundModdedStrings}`)
} else {
console.log('Did not find modded strings')
core.info('Did not find modded strings')
}
isMinecraftIssue = isMinecraftIssue || isCrashFromModdedMinecraft
console.log('Is Minecraft issue: ' + isMinecraftIssue)
if (isMinecraftIssue) {
core.notice('Detected issue to be about Minecraft')
let commentBody
if (isCrashFromModdedMinecraft) {
// Don't tell user to report modded crashes on Mojang's bug tracker; they will most likely be considered Invalid
Expand Down

0 comments on commit 8bbfd21

Please sign in to comment.