Skip to content

Commit 98bdf49

Browse files
authored
Make gh action to be downloading repo and scanning results (#20)
1 parent 9cd6a37 commit 98bdf49

File tree

3 files changed

+40
-26
lines changed

3 files changed

+40
-26
lines changed

action.yaml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
name: Validate the-mod-index
22
description: Validate the index.json and all manifest.json files for ReviversMC/the-mod-index styled indexes.
3-
inputs:
4-
repoUrl:
5-
description: The URL of the repository to validate. Defaults to ReviversMC/the-mod-index.
6-
required: false
73
runs:
84
using: composite
95
steps:
10-
- name: Checkout the repo. Ensure this is the action repo, not the consumer repo!
6+
- name: Checkout the action repo
117
uses: actions/checkout@v3
128
with:
139
repository: ReviversMC/the-mod-index-validation
10+
- name: Checkout the repo to check
11+
uses: actions/checkout@v3
12+
with:
13+
path: repo-to-check
1414
- name: Set up JDK 17
1515
uses: actions/setup-java@v3
1616
with:
@@ -21,4 +21,4 @@ runs:
2121
run: ./gradlew shadowJar
2222
- name: Run the-mod-index validator
2323
shell: bash
24-
run: java -jar build/libs/*.jar ${{ inputs.repoUrl }}
24+
run: java -jar build/libs/*.jar repo-to-check/mods

build.gradle.kts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@ plugins {
44
}
55

66
group = "com.github.reviversmc.themodindex.validation"
7-
version = "4.4.0"
7+
version = "5.0.0"
88

99
repositories {
1010
mavenCentral()
1111
maven("https://jitpack.io")
1212
}
1313

1414
dependencies {
15-
api("com.github.reviversmc:the-mod-index-api:9.0.0")
15+
api("com.github.reviversmc:the-mod-index-api:9.1.1")
1616
api("org.jetbrains.kotlinx:kotlinx-coroutines-core-jvm:1.6.4")
1717
}
1818

src/main/kotlin/com/github/reviversmc/themodindex/validation/Validation.kt

Lines changed: 32 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@ package com.github.reviversmc.themodindex.validation
22

33
import com.github.reviversmc.themodindex.api.data.IndexJson
44
import com.github.reviversmc.themodindex.api.data.ManifestJson
5-
import com.github.reviversmc.themodindex.api.downloader.DefaultApiDownloader
65
import kotlinx.coroutines.*
76
import kotlinx.coroutines.sync.Semaphore
87
import kotlinx.coroutines.sync.withPermit
98
import kotlinx.serialization.SerializationException
10-
import java.io.IOException
9+
import kotlinx.serialization.decodeFromString
10+
import kotlinx.serialization.json.Json
11+
import java.io.File
1112
import java.util.concurrent.atomic.AtomicInteger
1213
import kotlin.system.exitProcess
1314

@@ -23,19 +24,27 @@ private fun validateIndexRegex(indexJson: IndexJson) {
2324

2425
private fun validateManifestRegex(manifestJson: ManifestJson) {
2526
if (!Regex("^[0-9]+\\.[0-9]+\\.[0-9]+\$").matches(manifestJson.indexVersion)) throw IllegalArgumentException("Invalid index version: ${manifestJson.indexVersion} in ${manifestJson.genericIdentifier}")
26-
if (!Regex("^[a-z0-9\\-_]+:[a-z0-9\\-_]+\$").matches(manifestJson.genericIdentifier)) throw IllegalArgumentException("Invalid generic identifier: ${manifestJson.genericIdentifier}")
27+
if (!Regex("^[a-z0-9\\-_]+:[a-z0-9\\-_]+\$").matches(manifestJson.genericIdentifier)) throw IllegalArgumentException(
28+
"Invalid generic identifier: ${manifestJson.genericIdentifier}"
29+
)
2730
if (!Regex("^[a-zA-Z0-9\\-_\\s]+\$").matches(manifestJson.fancyName)) throw IllegalArgumentException("Invalid fancy name: ${manifestJson.fancyName} in ${manifestJson.genericIdentifier}")
2831
if (!Regex("^[a-zA-Z0-9\\-_\\s]+\$").matches(manifestJson.author)) throw IllegalArgumentException("Invalid author name: ${manifestJson.author} in ${manifestJson.genericIdentifier}")
29-
if (manifestJson.license?.let { Regex("^[a-zA-Z0-9\\-_\\s]+\$").matches(it) } == false) throw IllegalArgumentException("Invalid license: ${manifestJson.license} in ${manifestJson.genericIdentifier}")
32+
if (manifestJson.license?.let { Regex("^[a-zA-Z0-9\\-_\\s]+\$").matches(it) } == false) throw IllegalArgumentException(
33+
"Invalid license: ${manifestJson.license} in ${manifestJson.genericIdentifier}"
34+
)
3035
// No validation needed for CF id (int)
3136
if (manifestJson.modrinthId?.let { Regex("^[a-zA-Z0-9]+\$").matches(it) } == false) throw IllegalArgumentException("Invalid modrinth id: ${manifestJson.modrinthId} in ${manifestJson.genericIdentifier}")
32-
if (manifestJson.links.issue?.let { Regex("^[a-zA-Z0-9\\-_]+\$").matches(it) } == false) throw IllegalArgumentException("Invalid issue link: ${manifestJson.links.issue} in ${manifestJson.genericIdentifier}")
33-
if (manifestJson.links.sourceControl?.let { Regex("^[a-zA-Z0-9\\-_]+\$").matches(it) } == false) throw IllegalArgumentException("Invalid source control link: ${manifestJson.links.sourceControl} in ${manifestJson.genericIdentifier}")
37+
if (manifestJson.links.issue?.let { Regex("^[a-zA-Z0-9\\-_]+\$").matches(it) } == false) throw IllegalArgumentException(
38+
"Invalid issue link: ${manifestJson.links.issue} in ${manifestJson.genericIdentifier}"
39+
)
40+
if (manifestJson.links.sourceControl?.let { Regex("^[a-zA-Z0-9\\-_]+\$").matches(it) } == false) throw IllegalArgumentException(
41+
"Invalid source control link: ${manifestJson.links.sourceControl} in ${manifestJson.genericIdentifier}"
42+
)
3443
manifestJson.links.others.forEach {
3544
if (!Regex("^[a-zA-Z0-9\\-_\\s]+\$").matches(it.linkName)) throw IllegalArgumentException("Invalid link name: ${it.linkName} in ${manifestJson.genericIdentifier}")
3645
if (!Regex("^[a-zA-Z0-9\\-_:/?&]+\$").matches(it.url)) throw IllegalArgumentException("Invalid link url: ${it.url} in ${manifestJson.genericIdentifier}")
3746
}
38-
manifestJson.files.forEach {versionFile ->
47+
manifestJson.files.forEach { versionFile ->
3948
if (!Regex("^[a-zA-Z0-9\\-_\\s]+\$").matches(versionFile.fileName)) throw IllegalArgumentException("Invalid file name: ${versionFile.fileName} in ${manifestJson.genericIdentifier}")
4049
versionFile.mcVersions.forEach {
4150
if (!Regex("^[0-9]+\\.[0-9]+\\.[0-9]+[a-zA-Z0-9\\-+._\\s]*\$").matches(it)) throw IllegalArgumentException("Invalid MC version: $it in ${manifestJson.genericIdentifier}")
@@ -57,16 +66,18 @@ private fun validateManifestRegex(manifestJson: ManifestJson) {
5766

5867
fun main(args: Array<String>) {
5968

60-
val apiDownloader = if (args.isEmpty()) DefaultApiDownloader()
61-
else DefaultApiDownloader(baseUrl = args[0])
62-
69+
val repoToCheck = File(args.getOrNull(0) ?: throw IllegalArgumentException("No repository to check specified"))
70+
val json = Json {
71+
ignoreUnknownKeys = true
72+
prettyPrint = true
73+
}
6374
println("Attempting to validate index file...")
6475

65-
val indexJson = try {
66-
apiDownloader.getOrDownloadIndexJson()
76+
val indexJson: IndexJson = try {
77+
json.decodeFromString(File(repoToCheck, "index.json").readText())
6778
} catch (ex: SerializationException) {
68-
throw SerializationException("Serialization error of \"index.json\" at repository ${apiDownloader.formattedBaseUrl}.")
69-
} ?: throw IOException("Could not download \"index.json\" at repository ${apiDownloader.formattedBaseUrl}.")
79+
throw SerializationException("Serialization error of \"index.json\".")
80+
}
7081

7182
validateIndexRegex(indexJson)
7283
val availableManifests = indexJson.identifiers.map { it.substringBeforeLast(":") }.distinct()
@@ -105,7 +116,12 @@ fun main(args: Array<String>) {
105116
launch {
106117
manifestDownloadSemaphore.withPermit {
107118
try {
108-
val manifest = apiDownloader.downloadManifestJson(it) ?: throw IOException("Could not download manifest for $it")
119+
val manifest: ManifestJson = json.decodeFromString(
120+
File(
121+
"$repoToCheck/${it.substringBefore(":")}",
122+
"${it.substringAfter(":")}.json"
123+
).readText()
124+
)
109125
val currentlyChecked = checkedManifests.incrementAndGet()
110126
try {
111127
validateManifestRegex(manifest)
@@ -116,9 +132,7 @@ fun main(args: Array<String>) {
116132
if (currentlyChecked % 10 == 0) println("Checked $currentlyChecked / ${availableManifests.size} of manifests.")
117133

118134
} catch (ex: SerializationException) {
119-
throw SerializationException("Serialization error of manifest \"$it\" at repository ${apiDownloader.formattedBaseUrl}.")
120-
} catch (ex: IOException) {
121-
throw IOException("Could not download manifest \"$it\" at repository ${apiDownloader.formattedBaseUrl}.")
135+
throw SerializationException("Serialization error of manifest \"$it\".")
122136
}
123137
}
124138
}

0 commit comments

Comments
 (0)