Skip to content

Commit

Permalink
chore: switch to using env
Browse files Browse the repository at this point in the history
BREAKING CHANGE: This is a complete recode, features may be missing or different, if there are issues please open an issue on github or contact us about it on discord.
  • Loading branch information
sekwah41 committed Nov 19, 2024
1 parent 7229070 commit d672954
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 14 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/release-please.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ name: release-please
jobs:
release-please:
runs-on: ubuntu-latest
environment: release
outputs:
release_created: ${{ steps.release.outputs.release_created }}
upload_url: ${{ steps.release.outputs.upload_url }}
Expand All @@ -28,6 +29,7 @@ jobs:
release-task: [curseforge, discordupload, modrinth]
needs: release-please
runs-on: ubuntu-latest
environment: release
if: ${{ needs.release-please.outputs.release_created }}
steps:
- uses: actions/checkout@v3
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/snapshots.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,4 @@ jobs:
DISCORD_WEBHOOK: ${{ secrets.DISCORD_WEBHOOK }}
run: |
# Build
./gradlew build
./gradlew build discordupload
9 changes: 9 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ allprojects {

apply from: 'env-variables.gradle'


println("Branch ${ext.branch}${ext.shaRef} isRelease: '${ext.isRelease}'")
println("Snapshot Name: ${ext.snapshotName}")
println("Github SHA: ${ext.githubSha}")
println("Sha Ref: ${ext.shaRef}")

archivesBaseName = "Advanced-Portals"
group = 'com.sekwah.advancedportals'
def versionString = (file('./version.txt').text + (isRelease ? "" : "-${snapshotName}${shaRef}")).replaceAll('\n', '').replaceAll('\r', '')
Expand Down Expand Up @@ -184,3 +190,6 @@ idea {
}
}
}

apply from: 'curse.gradle'
apply from: 'discord.gradle'
21 changes: 16 additions & 5 deletions curse.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,7 @@ class UploadResponse {
task curseforge {
dependsOn(jar)
doLast {
String apiKey = null

if (System.getenv("CURSE_API") != null) {
apiKey = System.getenv("CURSE_API")
}
String apiKey = System.getenv("CURSE_API")

if(apiKey != null) {

Expand All @@ -134,6 +130,21 @@ task curseforge {
def versions = gameVersions.findAll {it.gameVersionTypeID == gameVersionTypeID}

String[] supportedVersions = [
"1.21",
"1.20.6",
"1.20.5",
"1.20.4",
"1.20.3",
"1.20.2",
"1.20.1",
"1.20",
"1.19.4",
"1.19.3",
"1.19.2",
"1.19.1",
"1.19",
"1.18.2",
"1.18.1",
"1.18",
"1.17",
"1.16",
Expand Down
37 changes: 29 additions & 8 deletions discord.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,17 @@ buildscript {

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.
*/
def getReleaseChangelog() {
def changelogFile = file('CHANGELOG.md')
def changelog = "## [${changelogFile.text.split('\n## \\[')[1]}\n\n"// ${project.github}/blob/${branch}/CHANGELOG.md
return changelog;
}

task discordupload {
dependsOn(jar)

doLast {

String discordWebhook = System.getenv("DISCORD_WEBHOOK")

if(discordWebhook != null) {
Expand All @@ -34,8 +37,26 @@ task discordupload {
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>")
if(!isRelease) {
builder.addTextBody("content", "New snapshot or testing build")
} else {
def maxLength = 2000

def content = "New release build\n" +
"```markdown\n" +
"${getReleaseChangelog()}\n" +
"```"

if (content.length() > maxLength) {
def trimmedChangelog = getReleaseChangelog().take(maxLength - 15) // Reserve space for ending message
content = "New release build\n" +
"```markdown\n" +
"${trimmedChangelog}\n" +
"``` [Truncated]"
}

builder.addTextBody("content", content)
}

builder.addBinaryBody("file", file(jar.archiveFile).newInputStream(), ContentType.APPLICATION_OCTET_STREAM, jar.archiveName)

Expand All @@ -48,7 +69,7 @@ task discordupload {
println("Posted build")

} else {
println("Discord webhook unspecified ${sha}")
println("Discord webhook unspecified")
}
}
}

0 comments on commit d672954

Please sign in to comment.