mirror of
https://github.com/sekwah41/Advanced-Portals.git
synced 2024-11-22 02:25:49 +01:00
chore(ci): add pre-commit as well as split variables out
This commit is contained in:
parent
d46d6e4787
commit
7fe48075ab
41
.github/workflows/pre-commit-check.yaml
vendored
Normal file
41
.github/workflows/pre-commit-check.yaml
vendored
Normal file
@ -0,0 +1,41 @@
|
||||
name: "Pre-commit consistency check"
|
||||
|
||||
on:
|
||||
workflow_dispatch:
|
||||
pull_request:
|
||||
|
||||
concurrency:
|
||||
group: ${{ github.head_ref }}-precommit
|
||||
cancel-in-progress: true
|
||||
|
||||
jobs:
|
||||
pre-commit-check:
|
||||
name: Run pre-commit checks
|
||||
runs-on: ubuntu-20.04
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v2
|
||||
with:
|
||||
fetch-depth: 0
|
||||
|
||||
- uses: dorny/paths-filter@v2
|
||||
id: filter
|
||||
with:
|
||||
list-files: shell
|
||||
filters: |
|
||||
addedOrModified:
|
||||
- added|modified: '**'
|
||||
|
||||
# run only if changed files were detected
|
||||
- name: Run against changes
|
||||
uses: pre-commit/action@v2.0.3
|
||||
if: steps.filter.outputs.addedOrModified == 'true'
|
||||
with:
|
||||
extra_args: --files ${{ steps.filter.outputs.addedOrModified_files }}
|
||||
|
||||
# run if no changed files were detected (e.g. workflow_dispatch on master branch)
|
||||
- name: Run against all files
|
||||
uses: pre-commit/action@v2.0.3
|
||||
if: steps.filter.outputs.addedOrModified != 'true'
|
||||
with:
|
||||
extra_args: --all-files
|
17
.pre-commit-config.yaml
Normal file
17
.pre-commit-config.yaml
Normal file
@ -0,0 +1,17 @@
|
||||
# See https://pre-commit.com for more information
|
||||
repos:
|
||||
- repo: https://github.com/pre-commit/pre-commit-hooks
|
||||
rev: v4.0.1
|
||||
hooks:
|
||||
- id: trailing-whitespace
|
||||
- id: end-of-file-fixer
|
||||
- id: fix-byte-order-marker
|
||||
- id: mixed-line-ending
|
||||
- id: check-merge-conflict
|
||||
- id: check-case-conflict
|
||||
|
||||
- repo: https://github.com/Lucas-C/pre-commit-hooks
|
||||
rev: v1.1.10
|
||||
hooks:
|
||||
- id: remove-crlf
|
||||
- id: remove-tabs
|
18
TODO.md
18
TODO.md
@ -1,18 +0,0 @@
|
||||
TODO
|
||||
================
|
||||
Main Tasks (Generally should be done in order)
|
||||
|
||||
Tag registration system (Mostly done, just needs to be tested and implemented)
|
||||
|
||||
Portal trigger system
|
||||
|
||||
Configs for language files to allow all messages to change
|
||||
|
||||
Change item data from strings to an object with strings in maybe
|
||||
|
||||
Bungee Support Set Locations
|
||||
|
||||
Keept the data storage for destinations and portals generally the same
|
||||
but modify it a little to be nicer for the tag registry.
|
||||
|
||||
Recode for spongepowered or find a way to make it work easier for them.
|
@ -83,15 +83,13 @@ buildscript {
|
||||
}
|
||||
}
|
||||
|
||||
apply from: 'env-variables.gradle'
|
||||
|
||||
archivesBaseName = "Advanced-Portals"
|
||||
group = 'com.sekwah.advancedportals'
|
||||
|
||||
description = ""
|
||||
|
||||
def branch = System.getenv("GITHUB_REF");
|
||||
def sha = System.getenv("GITHUB_SHA");
|
||||
def isDevBranch = branch == null || !(branch.startsWith("refs/tags/") && !branch.contains("-"))
|
||||
|
||||
tasks.withType(JavaCompile) {
|
||||
options.encoding = 'UTF-8'
|
||||
}
|
||||
|
172
curse.gradle
Normal file
172
curse.gradle
Normal file
@ -0,0 +1,172 @@
|
||||
import org.apache.commons.codec.Charsets
|
||||
import org.apache.http.HttpResponse
|
||||
import org.apache.http.client.HttpClient
|
||||
import org.apache.http.client.config.CookieSpecs
|
||||
import org.apache.http.client.config.RequestConfig
|
||||
import org.apache.http.client.methods.HttpPost
|
||||
import org.apache.http.entity.ContentType
|
||||
import org.apache.http.entity.mime.MultipartEntityBuilder
|
||||
import org.apache.http.impl.client.HttpClientBuilder
|
||||
import org.apache.http.client.methods.HttpGet
|
||||
import com.google.gson.Gson
|
||||
|
||||
buildscript {
|
||||
repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
dependencies {
|
||||
classpath "org.apache.httpcomponents:httpmime:4.5.13"
|
||||
classpath "com.google.code.gson:gson:2.8.6"
|
||||
classpath "org.apache.httpcomponents:httpclient:4.5.13"
|
||||
}
|
||||
}
|
||||
|
||||
apply from: 'env-variables.gradle'
|
||||
|
||||
static String getValueFromCurseAPI(apiKey, endpoint) {
|
||||
String API_BASE_URL = 'https://minecraft.curseforge.com'
|
||||
|
||||
HttpClient client = HttpClientBuilder.create()
|
||||
.setDefaultRequestConfig(RequestConfig.custom()
|
||||
.setCookieSpec(CookieSpecs.IGNORE_COOKIES).build()).build()
|
||||
|
||||
HttpGet get = new HttpGet(API_BASE_URL + endpoint)
|
||||
get.setHeader('X-Api-Token', apiKey)
|
||||
|
||||
HttpResponse response = client.execute(get)
|
||||
|
||||
int statusCode = response.statusLine.statusCode
|
||||
|
||||
if (statusCode == 200) {
|
||||
byte[] data = response.entity.content.bytes
|
||||
return new String(data, Charsets.UTF_8)
|
||||
} else {
|
||||
if (response.getFirstHeader('content-type').value.contains('json')) {
|
||||
InputStreamReader reader = new InputStreamReader(response.entity.content)
|
||||
reader.close()
|
||||
throw new RuntimeException("[CurseForge] Error")
|
||||
} else {
|
||||
throw new RuntimeException("[CurseForge] HTTP Error Code $response.statusLine.statusCode: $response.statusLine.reasonPhrase")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Upload a single file (in case you also want to upload the other files like source n stuff)
|
||||
* @param json
|
||||
* @param file
|
||||
* @return
|
||||
* @throws IOException
|
||||
* @throws URISyntaxException
|
||||
*/
|
||||
UploadResponse uploadFile(Metadata metadata, File file, String apiKey, Gson gson) throws IOException, URISyntaxException {
|
||||
String API_BASE_URL = 'https://minecraft.curseforge.com'
|
||||
String UPLOAD_URL = "/api/projects/%s/upload-file"
|
||||
// Upload
|
||||
// Important info
|
||||
String uploadUrl = String.format(API_BASE_URL + UPLOAD_URL, project.curse_project_id)
|
||||
|
||||
HttpClient client = HttpClientBuilder.create()
|
||||
.setDefaultRequestConfig(RequestConfig.custom()
|
||||
.setCookieSpec(CookieSpecs.IGNORE_COOKIES).build()).build()
|
||||
|
||||
HttpPost post = new HttpPost(uploadUrl)
|
||||
post.setHeader('X-Api-Token', apiKey)
|
||||
|
||||
|
||||
// https://support.curseforge.com/en/support/solutions/articles/9000197321-curseforge-api
|
||||
post.setEntity(MultipartEntityBuilder.create()
|
||||
.addTextBody('metadata', gson.toJson(metadata), ContentType.APPLICATION_JSON)
|
||||
.addBinaryBody('file', file)
|
||||
.build())
|
||||
|
||||
HttpResponse response = client.execute(post)
|
||||
InputStreamReader reader = new InputStreamReader(response.entity.content)
|
||||
UploadResponse uploadResponse = gson.fromJson(reader, UploadResponse)
|
||||
reader.close()
|
||||
return uploadResponse
|
||||
}
|
||||
|
||||
class GameVersion {
|
||||
int id
|
||||
int gameVersionTypeID
|
||||
String name
|
||||
String slug
|
||||
}
|
||||
|
||||
/**
|
||||
* As described here https://support.curseforge.com/en/support/solutions/articles/9000197321-curseforge-api
|
||||
*/
|
||||
class Metadata {
|
||||
String changelog
|
||||
String changelogType
|
||||
int[] gameVersions
|
||||
String releaseType
|
||||
}
|
||||
|
||||
class UploadResponse {
|
||||
int id
|
||||
}
|
||||
|
||||
|
||||
// Based on https://github.com/matthewprenger/CurseGradle as it didnt support Bukkit uploads at the time.
|
||||
task curseforge {
|
||||
dependsOn(jar)
|
||||
doLast {
|
||||
String apiKey = null
|
||||
|
||||
if (System.getenv("CURSE_API") != null) {
|
||||
apiKey = System.getenv("CURSE_API")
|
||||
}
|
||||
|
||||
if(apiKey != null) {
|
||||
|
||||
Gson gson = new Gson()
|
||||
|
||||
//String VERSION_TYPES_URL = "/api/game/version-types"
|
||||
int gameVersionTypeID = 1
|
||||
String VERSION_URL = "/api/game/versions"
|
||||
println("Uploading to CurseForge")
|
||||
|
||||
// Get game versions
|
||||
String gameVersionsString = getValueFromCurseAPI(apiKey, VERSION_URL)
|
||||
GameVersion[] gameVersions = gson.fromJson(gameVersionsString, GameVersion[].class)
|
||||
def versions = gameVersions.findAll {it.gameVersionTypeID == gameVersionTypeID}
|
||||
|
||||
String[] supportedVersions = [
|
||||
"1.18",
|
||||
"1.17",
|
||||
"1.16",
|
||||
"1.15",
|
||||
"1.14",
|
||||
"1.13"
|
||||
]
|
||||
|
||||
def supportedGameVersions = versions.findAll {supportedVersions.contains(it.name)}
|
||||
int[] supportedGameVersionIds = supportedGameVersions.collect {it.id}.toArray()
|
||||
|
||||
println("Supported Version Id's ${supportedGameVersionIds}")
|
||||
|
||||
Metadata uploadMetadata = new Metadata()
|
||||
|
||||
uploadMetadata.changelog = "${project.github}/blob/${ext.githubSha}/docs/changelogs/CHANGELOG.md"
|
||||
uploadMetadata.changelogType = "markdown"
|
||||
uploadMetadata.releaseType = ext.isDevBranch ? "beta" : "release"
|
||||
uploadMetadata.gameVersions = supportedGameVersionIds
|
||||
|
||||
def uploadId = uploadFile(uploadMetadata, file(jar.archiveFile), apiKey, gson)
|
||||
|
||||
println("Uploaded with ID: ${uploadId.id}")
|
||||
|
||||
println("Published build")
|
||||
|
||||
} else {
|
||||
println("Curse token unspecified")
|
||||
}
|
||||
}
|
||||
// id = project.curse_project_id
|
||||
// // TODO add code to reference this but also cut the latest change logs in for the files
|
||||
// changelog = "${project.github}/blob/${sha}/CHANGELOG.md"
|
||||
// changelogType = 'markdown'
|
||||
// releaseType = 'release'
|
||||
}
|
54
discord.gradle
Normal file
54
discord.gradle
Normal file
@ -0,0 +1,54 @@
|
||||
import org.apache.http.HttpEntity
|
||||
import org.apache.http.client.methods.CloseableHttpResponse
|
||||
import org.apache.http.client.methods.HttpPost
|
||||
import org.apache.http.entity.ContentType
|
||||
import org.apache.http.entity.mime.MultipartEntityBuilder
|
||||
import org.apache.http.impl.client.CloseableHttpClient
|
||||
import org.apache.http.impl.client.HttpClients
|
||||
|
||||
buildscript {
|
||||
repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
dependencies {
|
||||
classpath "org.apache.httpcomponents:httpmime:4.5.13"
|
||||
}
|
||||
}
|
||||
|
||||
apply from: 'env-variables.gradle'
|
||||
|
||||
/** For pre-releases and testers to be able to try the latest commits if they want.
|
||||
* If the builds start exceeding 8MB then we may want to upload to s3 instead and periodically clear.
|
||||
* TODO possibly add a task that announces when builds are made?
|
||||
* Though add a note that it may take a while for Curse to approve the files.
|
||||
*/
|
||||
task discordupload {
|
||||
dependsOn(jar)
|
||||
doLast {
|
||||
String discordWebhook = System.getenv("DISCORD_WEBHOOK")
|
||||
|
||||
if(discordWebhook != null) {
|
||||
println("Logging Into Discord")
|
||||
|
||||
CloseableHttpClient httpClient = HttpClients.createDefault()
|
||||
HttpPost uploadFile = new HttpPost(discordWebhook)
|
||||
|
||||
MultipartEntityBuilder builder = MultipartEntityBuilder.create()
|
||||
builder.addTextBody("content", "New automated dev build\n\n" +
|
||||
"Current Features: <${project.github}/blob/${ext.githubSha}/docs/changelogs/SNAPSHOT_CHANGELOG.md>")
|
||||
|
||||
builder.addBinaryBody("file", file(jar.archiveFile).newInputStream(), ContentType.APPLICATION_OCTET_STREAM, jar.archiveName)
|
||||
|
||||
HttpEntity multipart = builder.build()
|
||||
|
||||
uploadFile.setEntity(multipart)
|
||||
CloseableHttpResponse response = httpClient.execute(uploadFile)
|
||||
response.getEntity()
|
||||
|
||||
println("Posted build")
|
||||
|
||||
} else {
|
||||
println("Discord webhook unspecified ${sha}")
|
||||
}
|
||||
}
|
||||
}
|
16
env-variables.gradle
Normal file
16
env-variables.gradle
Normal file
@ -0,0 +1,16 @@
|
||||
|
||||
def branch = System.getenv("GITHUB_REF")
|
||||
if(branch != null) {
|
||||
branch = branch.replace('refs/heads/', '')
|
||||
}
|
||||
def isRelease = System.getenv("IS_RELEASE") == "true"
|
||||
|
||||
def snapshotName = (branch == null || branch.startsWith("release-please")) ? "SNAPSHOT" : branch
|
||||
def githubSha = System.getenv("GITHUB_SHA")
|
||||
def shaRef = githubSha != null ? "-${githubSha.substring(0, 8)}" : ""
|
||||
|
||||
ext.branch = branch
|
||||
ext.snapshotName = snapshotName
|
||||
ext.githubSha = githubSha
|
||||
ext.shaRef = shaRef
|
||||
ext.isRelease = isRelease
|
@ -1,3 +1 @@
|
||||
// Check the root build.gradle under allprojects for common settings
|
||||
|
||||
|
||||
|
@ -90,4 +90,3 @@ command.trans.help=Copy translation new default translation file
|
||||
command.version.help=Returns the current version of the plugin
|
||||
|
||||
command.subcommand.nopermission= Sorry but you don't have permission for that, please use \u00A7e/%1$s help \u00A7cif you would like a list of possible sub commands.
|
||||
|
||||
|
1
version.txt
Normal file
1
version.txt
Normal file
@ -0,0 +1 @@
|
||||
0.9.2
|
Loading…
Reference in New Issue
Block a user