Skip to content

Update Issue Template #4

Update Issue Template

Update Issue Template #4

name: Update Issue Template
on:
workflow_dispatch:
push:
tags:
- '*'
jobs:
generate-bug_report:
runs-on: ubuntu-latest
steps:
- name: Checkout Sources
uses: actions/checkout@v7
with:
ref: ${{ github.event.repository.default_branch }}
fetch-depth: 0
- name: Generate Version List
uses: actions/github-script@v9
with:
script: |
const fs = require("fs")
const MAX_MC_VERSIONS = 3
const MAX_MOD_VERSIONS = 5
const SKIP_MC_VERSIONS = {
'1.20.4': true,
'1.19.3': true,
}
const ALPHA_TAGS = {
'a': true,
// 'b': true,
}
let output = ''
await exec.exec('git tag --list', {
listeners: {
stdout: (data) => output += data.toString(),
},
})
const tagMatcher = /^(\d+(?:\.\d+)*)-(\d+(?:\.\d+)*)(\D?)\S*$/
const versionComparer = (a, b) => {
const n1 = a.split('.').map(x => parseInt(x))
const n2 = b.split('.').map(x => parseInt(x))
const n = Math.min(n1.length, n2.length)
for (let i = 0; i < n; i++) {
if (n1[i] === undefined) {
return -1
}
if (n2[i] === undefined) {
return 1
}
if (n1[i] < n2[i]) {
return -1
}
if (n1[i] > n2[i]) {
return 1
}
}
return 0
}
const tags = []
for (const t of output.split('\n')) {
const match = tagMatcher.exec(t)
if (!match) {
continue
}
const [fullTag, minecraftVersion, modVersion, releaseType] = match
tags.push({
full: fullTag,
minecraft: minecraftVersion,
version: modVersion,
type: releaseType,
})
}
tags.sort((a, b) => {
const c1 = versionComparer(a.minecraft, b.minecraft)
if (c1) {
return -c1
}
return -versionComparer(a.version, b.version)
})
const outputVersions = [
'Own compiled build.'
]
let currentMcVersion = null
let passedMcVersion = 0
let passedVersion = 0
for (const t of tags) {
if (t.minecraft in SKIP_MC_VERSIONS) {
continue
}
if (t.minecraft !== currentMcVersion) {
if (passedMcVersion >= MAX_MC_VERSIONS) {
break
}
passedMcVersion++
passedVersion = 0
currentMcVersion = t.minecraft
}
if (passedVersion >= MAX_MOD_VERSIONS) {
continue
}
if (passedVersion > 0 && t.type in ALPHA_TAGS) {
continue
}
passedVersion++
let v = t.full
if (passedVersion === 1) {
v += ' (Latest ' + t.minecraft + ')'
}
console.log('adding version:', v)
outputVersions.push(v)
}
outputVersions.push('Other. (probably unsupported)')
let bugReportYml = fs.readFileSync('.github/ISSUE_TEMPLATE/bug_report.yml.template', 'utf8')
bugReportYml = bugReportYml.replace('{{versions}}', JSON.stringify(outputVersions))
fs.writeFileSync('.github/ISSUE_TEMPLATE/bug_report.yml', bugReportYml)
- name: Push Updates
run: |
git config user.name github-actions
git config user.email github-actions[bot]@users.noreply.github.com
git add .github/ISSUE_TEMPLATE/bug_report.yml
git commit -m 'action: update issue template bug_report.yml' || exit 0
git push