diff --git a/.github/workflows/release-please.yml b/.github/workflows/release-please.yml index 2a570d28..5daa4bcf 100644 --- a/.github/workflows/release-please.yml +++ b/.github/workflows/release-please.yml @@ -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 }} @@ -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 diff --git a/.github/workflows/snapshots.yml b/.github/workflows/snapshots.yml index c2530da4..7356f981 100644 --- a/.github/workflows/snapshots.yml +++ b/.github/workflows/snapshots.yml @@ -34,4 +34,4 @@ jobs: DISCORD_WEBHOOK: ${{ secrets.DISCORD_WEBHOOK }} run: | # Build - ./gradlew build + ./gradlew build discordupload diff --git a/build.gradle b/build.gradle index e9ccd177..3063e0ff 100644 --- a/build.gradle +++ b/build.gradle @@ -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', '') @@ -184,3 +190,6 @@ idea { } } } + +apply from: 'curse.gradle' +apply from: 'discord.gradle' diff --git a/curse.gradle b/curse.gradle index f3be7b22..a75ca7f4 100644 --- a/curse.gradle +++ b/curse.gradle @@ -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) { @@ -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", diff --git a/discord.gradle b/discord.gradle index 093ff84b..d4d9deb0 100644 --- a/discord.gradle +++ b/discord.gradle @@ -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) { @@ -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) @@ -48,7 +69,7 @@ task discordupload { println("Posted build") } else { - println("Discord webhook unspecified ${sha}") + println("Discord webhook unspecified") } } }