137 lines
5.0 KiB
YAML
137 lines
5.0 KiB
YAML
name: Build ModernFix using Gradle
|
|
|
|
on:
|
|
push:
|
|
branches:
|
|
- '**'
|
|
tags-ignore:
|
|
- '**'
|
|
pull_request:
|
|
|
|
jobs:
|
|
build:
|
|
runs-on: ubuntu-22.04
|
|
permissions:
|
|
issues: write
|
|
concurrency:
|
|
group: release-${{ github.ref }}
|
|
cancel-in-progress: true
|
|
steps:
|
|
- name: Checkout Repository
|
|
uses: actions/checkout@v4
|
|
with:
|
|
fetch-depth: 0
|
|
- name: Set up JDK 21
|
|
uses: actions/setup-java@v4
|
|
with:
|
|
distribution: 'temurin'
|
|
java-version: 21
|
|
check-latest: true
|
|
- name: Check if release branch
|
|
id: check_branch
|
|
if: github.event_name == 'push'
|
|
run: |
|
|
if [[ "${{ github.ref }}" =~ ^refs/heads/[0-9]+\. ]]; then
|
|
echo "is_release=true" >> $GITHUB_OUTPUT
|
|
else
|
|
echo "is_release=false" >> $GITHUB_OUTPUT
|
|
fi
|
|
- name: Setup Gradle
|
|
uses: gradle/actions/setup-gradle@v4
|
|
with:
|
|
cache-read-only: ${{ steps.check_branch.outputs.is_release != 'true' }}
|
|
gradle-home-cache-cleanup: true
|
|
- name: Remove tags for release on other versions
|
|
if: steps.check_branch.outputs.is_release == 'true'
|
|
run: ./scripts/tagcleaner.sh
|
|
- name: Build ModernFix using Gradle
|
|
run: ./gradlew build
|
|
- name: Run mixin audit
|
|
run: timeout 60 xvfb-run ./gradlew runAuditClient
|
|
- name: Publish mod to CurseForge & Modrinth
|
|
if: steps.check_branch.outputs.is_release == 'true'
|
|
run: ./gradlew publishMods copyJarToBin
|
|
env:
|
|
CURSEFORGE_TOKEN: ${{ secrets.CURSEFORGE_TOKEN }}
|
|
MODRINTH_TOKEN: ${{ secrets.MODRINTH_TOKEN }}
|
|
- name: Capture mod version
|
|
if: steps.check_branch.outputs.is_release == 'true'
|
|
run: |
|
|
echo "MOD_VERSION=$(./gradlew properties -q | grep '^version:' | awk '{print $2}')" >> $GITHUB_ENV
|
|
echo "MC_VERSION=$(grep '^minecraft_version=' gradle.properties | cut -d= -f2)" >> $GITHUB_ENV
|
|
- name: Comment on fixed issues
|
|
if: steps.check_branch.outputs.is_release == 'true'
|
|
uses: actions/github-script@v7
|
|
with:
|
|
script: |
|
|
const { execSync } = require('child_process');
|
|
|
|
const branch = context.ref.replace('refs/heads/', '');
|
|
const { data: runs } = await github.rest.actions.listWorkflowRuns({
|
|
owner: context.repo.owner,
|
|
repo: context.repo.repo,
|
|
workflow_id: 'gradle.yml',
|
|
branch,
|
|
status: 'success',
|
|
per_page: 1
|
|
});
|
|
|
|
const logArgs = runs.workflow_runs.length > 0
|
|
? `${runs.workflow_runs[0].head_sha}..${context.sha}`
|
|
: `-1 ${context.sha}`;
|
|
const log = execSync(`git log ${logArgs} --format=%s%n%b`, { encoding: 'utf8' });
|
|
|
|
const issueNumbers = new Set();
|
|
const pattern = /(?:fix(?:es|ed)?|close[sd]?|resolve[sd]?)\s+#(\d+)/gi;
|
|
let match;
|
|
while ((match = pattern.exec(log)) !== null) {
|
|
issueNumbers.add(parseInt(match[1]));
|
|
}
|
|
|
|
if (issueNumbers.size === 0) {
|
|
console.log('No fixed issues found in commits');
|
|
return;
|
|
}
|
|
|
|
const MARKER = '<!-- modernfix-fix-tracker -->';
|
|
const modVersion = process.env.MOD_VERSION;
|
|
const mcVersion = process.env.MC_VERSION;
|
|
const newLine = `- ${modVersion} for Minecraft ${mcVersion}`;
|
|
|
|
for (const issueNumber of issueNumbers) {
|
|
try {
|
|
const { data: comments } = await github.rest.issues.listComments({
|
|
owner: context.repo.owner,
|
|
repo: context.repo.repo,
|
|
issue_number: issueNumber,
|
|
per_page: 100
|
|
});
|
|
|
|
const existing = comments.find(c => c.body.includes(MARKER));
|
|
if (existing) {
|
|
await github.rest.issues.updateComment({
|
|
owner: context.repo.owner,
|
|
repo: context.repo.repo,
|
|
comment_id: existing.id,
|
|
body: existing.body + `\n${newLine}`
|
|
});
|
|
console.log(`Updated comment on issue #${issueNumber}`);
|
|
} else {
|
|
await github.rest.issues.createComment({
|
|
owner: context.repo.owner,
|
|
repo: context.repo.repo,
|
|
issue_number: issueNumber,
|
|
body: `${MARKER}\nThe fix for this issue has been released in the following versions of ModernFix:\n${newLine}`
|
|
});
|
|
console.log(`Created comment on issue #${issueNumber}`);
|
|
}
|
|
} catch (e) {
|
|
console.log(`Could not comment on #${issueNumber}: ${e.message}`);
|
|
}
|
|
}
|
|
- name: Upload Artifacts to GitHub
|
|
uses: actions/upload-artifact@v4
|
|
with:
|
|
name: Package
|
|
path: bin
|