GitHub Actions and fewer false positives (#2)

- Set Up Github Actions
- Refactored code
- Upgrade Gradle, Loom
- Catches more valid licenses
- Ignores mods of type "builtin"
master
macbrayne 2021-09-16 00:43:09 +02:00 committed by GitHub
parent 26b491a647
commit 33e34df139
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 85 additions and 26 deletions

64
.github/workflows/build.yml vendored Normal file
View File

@ -0,0 +1,64 @@
# Builds and tests the project
name: Build
# On pull requests
on:
push:
paths:
- '**/src/**'
- '**/build.gradle'
- '**/gradle.properties'
- '**/settings.gradle'
- .github/workflows/build.yml
- LICENCE
pull_request:
paths:
- '**/src/**'
- '**/build.gradle'
- '**/gradle.properties'
- '**/settings.gradle'
- .github/workflows/build.yml
- LICENCE
jobs:
build:
name: Build
runs-on: ubuntu-latest
steps:
- name: ✨ Checkout repository
uses: actions/checkout@v2
- name: 🛂 Validate Gradle wrapper
uses: gradle/wrapper-validation-action@v1
- name: 🏗 Set up JDK 16
uses: actions/setup-java@v2
with:
java-version: 16
distribution: adopt
- name: 📷 Begin Gradle cache
uses: actions/cache@v2
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
restore-keys: |
${{ runner.os }}-gradle-
- name: 🔨 Build artifacts
run: ./gradlew clean build
- name: 📦 Upload artifacts
uses: actions/upload-artifact@v2
with:
name: artifacts
path: '**/build/libs/'
- name: 🧨 Cleanup Gradle cache
run: |
rm -f ~/.gradle/caches/modules-2/modules-2.lock
rm -f ~/.gradle/caches/modules-2/gc.properties

View File

@ -1,5 +1,5 @@
plugins {
id 'fabric-loom' version '0.7-SNAPSHOT'
id 'fabric-loom' version '0.9-SNAPSHOT'
id 'maven-publish'
}
@ -13,8 +13,8 @@ group = project.maven_group
dependencies {
//to change the versions see the gradle.properties file
minecraft "com.mojang:minecraft:${project.minecraft_version}"
mappings "net.fabricmc:yarn:${project.yarn_mappings}+build.+:v2"
modImplementation "net.fabricmc:fabric-loader:${project.loader_version}+build.+"
mappings "net.fabricmc:yarn:${project.minecraft_version}+${project.yarn_build}:v2"
modImplementation "net.fabricmc:fabric-loader:${project.loader_version}"
// PSA: Some older mods, compiled on Loom 0.2.1, might have outdated Maven POMs.
// You may need to force-disable transitiveness on them.
@ -23,14 +23,9 @@ dependencies {
processResources {
inputs.property "version", project.version
from(sourceSets.main.resources.srcDirs) {
include "fabric.mod.json"
filesMatching("fabric.mod.json") {
expand "version": project.version
}
from(sourceSets.main.resources.srcDirs) {
exclude "fabric.mod.json"
}
}
// ensure that the encoding is set to UTF-8, no matter what the system default is
@ -40,12 +35,11 @@ tasks.withType(JavaCompile) {
options.encoding = "UTF-8"
}
java {
// Loom will automatically attach sourcesJar to a RemapSourcesJar task and to the "build" task
// if it is present.
// If you remove this task, sources will not be generated.
task sourcesJar(type: Jar, dependsOn: classes) {
classifier = "sources"
from sourceSets.main.allSource
// If you remove this line, sources will not be generated.
withSourcesJar()
}
jar {

View File

@ -4,8 +4,8 @@ org.gradle.jvmargs=-Xmx1G
# Fabric Properties
# check these on https://fabricmc.net/use
minecraft_version=1.15.2
yarn_mappings=1.15.2
loader_version=0.8.2
yarn_build=build.17
loader_version=0.11.6
# Mod Properties
mod_version = 1.2.0

Binary file not shown.

View File

@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.3-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

View File

@ -1,8 +1,5 @@
package com.halotroop.arrchecker;
import java.util.ArrayList;
import java.util.List;
import net.fabricmc.api.ModInitializer;
import net.fabricmc.loader.api.FabricLoader;
import net.fabricmc.loader.api.ModContainer;
@ -10,6 +7,9 @@ import net.fabricmc.loader.api.metadata.ModMetadata;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import java.util.ArrayList;
import java.util.List;
public class ARRChecker implements ModInitializer {
private static final List<String> arrMods = new ArrayList<>();
private static final Logger LOGGER = LogManager.getLogger("arrchecker");
@ -20,11 +20,12 @@ public class ARRChecker implements ModInitializer {
for (ModContainer mod : FabricLoader.getInstance().getAllMods()) {
ModMetadata modMeta = mod.getMetadata();
// Assume all authors don't know how capitalization works, and don't use an array for the string!
String modLicense = modMeta.getLicense().toString().toLowerCase().replace('[', ' ').replace(']', ' ').trim();
// '-' is being replaced with ' ' due to some mod authors having specified their creative commons license without '-' but with spaces instead
final String modLicense = modMeta.getLicense().toString().toLowerCase().replaceAll("[\\[\\]-]", " ").trim();
// Create a constant of the mod name and ID to be used multiple times: Don't use an array for the string!
String modNameAndID = (modMeta.getName() + " (" + modMeta.getId() + ")").replace('[', ' ').replace(']', ' ').trim();
// Give a different warning for Minecraft itself.
if (!modMeta.getId().equals("minecraft") && !modMeta.getId().equals("java")) {
final String modNameAndID = (modMeta.getName() + " (" + modMeta.getId() + ")").replaceAll("[\\[\\]]", " ").trim();
// Ignore built in mods
if (!modMeta.getType().equals("builtin")) {
if (modLicense.isEmpty()) {
// If no license is found, assume mod is not correctly licensed, and therefore, not modpack-friendly.
LOGGER.warn(modNameAndID + " has no license! It may be ARR!");
@ -37,7 +38,7 @@ public class ARRChecker implements ModInitializer {
String[] validLicenses =
{
"gpl", "mit", "cc0", "apache", "unlicense", "mpl", // Short form names
"gnu public license", "mozilla public license", "creative commons" // Long form (incorrect, but check anyway)
"gnu lesser general public license", "gnu general public license", "mozilla public license", "creative commons", "cc by nc" // Long form (incorrect, but check anyway)
};
boolean modLicenseInvalid = true;
for (String validLicense : validLicenses) {