From d4a4bdbd6dd1858713feae7890989ca8d289c04f Mon Sep 17 00:00:00 2001 From: Johann Bernhardt Date: Fri, 12 Nov 2021 13:49:09 +0100 Subject: [PATCH 01/45] Draft for potential build script update hint --- build.gradle | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/build.gradle b/build.gradle index 09490ee..a03073c 100644 --- a/build.gradle +++ b/build.gradle @@ -51,6 +51,18 @@ if(JavaVersion.current() != JavaVersion.VERSION_1_8) { throw new GradleException("This project requires Java 8, but it's running on " + JavaVersion.current()) } +def checkForUpdate() { + Thread.start { + Map parameters = [ "connectTimeout" : 2000, "readTimeout": 2000 ] + String currentBuildScript = new File("build.gradle").getText() + String availableBuildScript = new URL("https://raw.githubusercontent.com/SinTh0r4s/ExampleMod1.7.10/main/build.gradle").newInputStream(parameters).getText() + if (availableBuildScript.equals("") == false && currentBuildScript.equals(availableBuildScript) == false) { + println("Build script update available! Check https://github.com/SinTh0r4s/ExampleMod1.7.10/blob/main/build.gradle"); + } + } +} +checkForUpdate() + def checkPropertyExsists(String propertyName) { if (project.hasProperty(propertyName) == false) { throw new GradleException("This project requires a property \"" + propertyName + "\"! Please add it your \"gradle.properties\". You can find all properties and their description here: https://github.com/SinTh0r4s/ExampleMod1.7.10/blob/main/gradle.properties") From 39b9d261b92d4864e518c5b388a9ea131a9c6aeb Mon Sep 17 00:00:00 2001 From: Telan <13066272+TheElan@users.noreply.github.com> Date: Fri, 12 Nov 2021 19:06:21 +0200 Subject: [PATCH 02/45] embed build script version in its file; add zip-packages job to CI --- .github/scripts/update-version.sh | 8 ++++ .github/workflows/repository-specific.yml | 54 +++++++++++++++++++++++ README.md | 8 ++-- build.gradle | 1 + docs/migration.md | 2 +- 5 files changed, 68 insertions(+), 5 deletions(-) create mode 100755 .github/scripts/update-version.sh create mode 100644 .github/workflows/repository-specific.yml diff --git a/.github/scripts/update-version.sh b/.github/scripts/update-version.sh new file mode 100755 index 0000000..77136c0 --- /dev/null +++ b/.github/scripts/update-version.sh @@ -0,0 +1,8 @@ +if [ ! -z $(git diff --name-only HEAD HEAD~1 | grep dependencies.gradle) ]; then + new_version="$(git log -n1 --format=format:"%H")" + sed --in-place "s!//version:.*!//version: $new_version!g" build.gradle + git add build.gradle + git commit -m "update buildscript version to $new_version" + git push + echo "[ci skip] update buildscript version"; +fi diff --git a/.github/workflows/repository-specific.yml b/.github/workflows/repository-specific.yml new file mode 100644 index 0000000..4768ea4 --- /dev/null +++ b/.github/workflows/repository-specific.yml @@ -0,0 +1,54 @@ +# This workflow only meant for the source mod youy shouldn't bring it into your own project + +name: Buildscript update CI + +on: + push: + branches: [ master, main, buildscript-versioning-and-migration-zip ] # todo: remove temporary test branch from here + pull_request: + branches: [ master, main ] + +jobs: + buildscript-maintenece: + runs-on: ubuntu-latest + steps: + - name: ensure build script version is updated + run: ./.github/scripts/update-version.sh + + zip-packages: + runs-on: ubuntu-latest + steps: + - name: Zip migration + run: > + zip -r migration.zip . \ + \ + -x "*.git/*" \ + \ + -x ".github/scripts/update-version.sh" \ + -x ".github/workflows/repository-specific.yml" \ + \ + -x "*docs/*" \ + -x "*src/*" \ + -x "LICENSE" \ + -x "README.md" + + - name: Zip starter + run: > + zip -r starter.zip . \ + \ + -x "*.git/*" \ + \ + -x ".github/scripts/update-version.sh" \ + -x ".github/workflows/repository-specific.yml" \ + \ + -x "*docs/*" \ + -x "LICENSE" \ + -x "README.md" + + - uses: "marvinpinto/action-automatic-releases@latest" + with: + repo_token: "${{ secrets.GITHUB_TOKEN }}" + automatic_release_tag: "latest-packages" + prerelease: true + title: "Latest starter and migration packages" + files: "*.zip" diff --git a/README.md b/README.md index 3bef3f5..b0ef929 100644 --- a/README.md +++ b/README.md @@ -12,12 +12,12 @@ We had our fair share in struggles with build scripts for Minecraft Forge. There ### Getting started Creating mod from scratch: -1. Fork this repository (you can keep the fork to simplify merging any build script updates in the future) -2. Clone repository +1. Unzip [project starter](TODO: insert the latest starter.zip link) +2. Commit it to your VCS of choice for later reference (e.g. in root directory `git init; git commit -m "initialise repository"`) 3. Replace placeholders (edit values in gradle.properties, change example package and class names, etc.) 4. Run `./gradlew setupDecompWorkspace` (if build fails with `Could not find :forgeBin:1.7.10-10.13.4.1614-1.7.10.` this should fix it) -5. Make sure to checkout the rest sections of this file. -6. You are good to go! +5. Make sure to check out the rest sections of this file. +6. You are good to go! We also have described guidelines for existing mod [migration](docs/migration.md) and [porting](docs/porting.md) diff --git a/build.gradle b/build.gradle index 46f5232..715ee07 100644 --- a/build.gradle +++ b/build.gradle @@ -1,3 +1,4 @@ +//version: commit hash placeholder /* DO NOT CHANGE THIS FILE! diff --git a/docs/migration.md b/docs/migration.md index 4b92331..21bb17e 100644 --- a/docs/migration.md +++ b/docs/migration.md @@ -5,7 +5,7 @@ Migration for the typical mod which doesn't use anything special but Minecraft f For core plugin, Mixins, shadowing, access transformers, ASM or etc. you'll need to do some extra steps. If they are missing in this document - we will gladly receive your suggestions/contribution. -1. Copy and replace all files from template to your repository, but: +1. Copy and replace all files from [template](TODO: insert the latest migration.zip link) to your repository, but: 1. `build.gradle` 2. `src` 3. `LICENSE` From 45f5360acc59499d2078bf8ee25d54740e01685b Mon Sep 17 00:00:00 2001 From: Telan <13066272+TheElan@users.noreply.github.com> Date: Fri, 12 Nov 2021 19:08:26 +0200 Subject: [PATCH 03/45] fix update-version.sh reference in ci jobs --- .github/workflows/repository-specific.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/repository-specific.yml b/.github/workflows/repository-specific.yml index 4768ea4..ea6bd32 100644 --- a/.github/workflows/repository-specific.yml +++ b/.github/workflows/repository-specific.yml @@ -13,7 +13,7 @@ jobs: runs-on: ubuntu-latest steps: - name: ensure build script version is updated - run: ./.github/scripts/update-version.sh + run: .github/scripts/update-version.sh zip-packages: runs-on: ubuntu-latest From 17e6a5204b2dac16b7216272aedd8fc6d2358a76 Mon Sep 17 00:00:00 2001 From: Telan <13066272+TheElan@users.noreply.github.com> Date: Fri, 12 Nov 2021 19:20:07 +0200 Subject: [PATCH 04/45] make repository-specific.yml workflow checkout latest commit --- .github/workflows/repository-specific.yml | 58 +++++++++++++---------- 1 file changed, 32 insertions(+), 26 deletions(-) diff --git a/.github/workflows/repository-specific.yml b/.github/workflows/repository-specific.yml index ea6bd32..326ae4a 100644 --- a/.github/workflows/repository-specific.yml +++ b/.github/workflows/repository-specific.yml @@ -1,4 +1,4 @@ -# This workflow only meant for the source mod youy shouldn't bring it into your own project +# This workflow only meant for the source mod you shouldn't bring it into your own project name: Buildscript update CI @@ -12,38 +12,44 @@ jobs: buildscript-maintenece: runs-on: ubuntu-latest steps: + - uses: actions/checkout@v2 + - name: ensure build script version is updated run: .github/scripts/update-version.sh zip-packages: runs-on: ubuntu-latest steps: - - name: Zip migration - run: > - zip -r migration.zip . \ - \ - -x "*.git/*" \ - \ - -x ".github/scripts/update-version.sh" \ - -x ".github/workflows/repository-specific.yml" \ - \ - -x "*docs/*" \ - -x "*src/*" \ - -x "LICENSE" \ - -x "README.md" + - uses: actions/checkout@v2 - - name: Zip starter - run: > - zip -r starter.zip . \ - \ - -x "*.git/*" \ - \ - -x ".github/scripts/update-version.sh" \ - -x ".github/workflows/repository-specific.yml" \ - \ - -x "*docs/*" \ - -x "LICENSE" \ - -x "README.md" + - uses: montudor/action-zip@v1 + with: + args: > + zip -r migration.zip . \ + \ + -x "*.git/*" \ + \ + -x ".github/scripts/update-version.sh" \ + -x ".github/workflows/repository-specific.yml" \ + \ + -x "*docs/*" \ + -x "*src/*" \ + -x "LICENSE" \ + -x "README.md" + + - uses: montudor/action-zip@v1 + with: + args: > + zip -r starter.zip . \ + \ + -x "*.git/*" \ + \ + -x ".github/scripts/update-version.sh" \ + -x ".github/workflows/repository-specific.yml" \ + \ + -x "*docs/*" \ + -x "LICENSE" \ + -x "README.md" - uses: "marvinpinto/action-automatic-releases@latest" with: From 47bf008af2e7daddf2bf14c31144f347a8b926cf Mon Sep 17 00:00:00 2001 From: Telan <13066272+TheElan@users.noreply.github.com> Date: Fri, 12 Nov 2021 19:25:53 +0200 Subject: [PATCH 05/45] add names to tasks; split package releases; increase fetch depth for buildscript maintenance job --- .github/workflows/repository-specific.yml | 60 ++++++++++++++--------- 1 file changed, 38 insertions(+), 22 deletions(-) diff --git a/.github/workflows/repository-specific.yml b/.github/workflows/repository-specific.yml index 326ae4a..d80e172 100644 --- a/.github/workflows/repository-specific.yml +++ b/.github/workflows/repository-specific.yml @@ -12,17 +12,46 @@ jobs: buildscript-maintenece: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - name: Checkout + uses: actions/checkout@v2 + with: + fetch-depth: 1 - - name: ensure build script version is updated + - name: Ensure build script version is updated run: .github/scripts/update-version.sh zip-packages: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - name: Checkout + uses: actions/checkout@v2 - - uses: montudor/action-zip@v1 + - name: Zip starter + uses: montudor/action-zip@v1 + with: + args: > + zip -r starter.zip . \ + \ + -x "*.git/*" \ + \ + -x ".github/scripts/update-version.sh" \ + -x ".github/workflows/repository-specific.yml" \ + \ + -x "*docs/*" \ + -x "LICENSE" \ + -x "README.md" + + - name: Publish starter package + uses: "marvinpinto/action-automatic-releases@latest" + with: + repo_token: "${{ secrets.GITHUB_TOKEN }}" + automatic_release_tag: "latest-starer" + prerelease: true + title: "Latest starter package" + files: "starter.zip" + + - name: Zip migration + uses: montudor/action-zip@v1 with: args: > zip -r migration.zip . \ @@ -37,24 +66,11 @@ jobs: -x "LICENSE" \ -x "README.md" - - uses: montudor/action-zip@v1 - with: - args: > - zip -r starter.zip . \ - \ - -x "*.git/*" \ - \ - -x ".github/scripts/update-version.sh" \ - -x ".github/workflows/repository-specific.yml" \ - \ - -x "*docs/*" \ - -x "LICENSE" \ - -x "README.md" - - - uses: "marvinpinto/action-automatic-releases@latest" + - name: Publish migration package + uses: "marvinpinto/action-automatic-releases@latest" with: repo_token: "${{ secrets.GITHUB_TOKEN }}" - automatic_release_tag: "latest-packages" + automatic_release_tag: "latest-starer" prerelease: true - title: "Latest starter and migration packages" - files: "*.zip" + title: "Latest migration package" + files: "migration.zip" From 01c33c5044089be6b8b7b76edf925474c7c24648 Mon Sep 17 00:00:00 2001 From: Telan <13066272+TheElan@users.noreply.github.com> Date: Fri, 12 Nov 2021 19:27:28 +0200 Subject: [PATCH 06/45] add message when ignoring version update --- .github/scripts/update-version.sh | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/scripts/update-version.sh b/.github/scripts/update-version.sh index 77136c0..226cb95 100755 --- a/.github/scripts/update-version.sh +++ b/.github/scripts/update-version.sh @@ -2,7 +2,9 @@ if [ ! -z $(git diff --name-only HEAD HEAD~1 | grep dependencies.gradle) ]; then new_version="$(git log -n1 --format=format:"%H")" sed --in-place "s!//version:.*!//version: $new_version!g" build.gradle git add build.gradle - git commit -m "update buildscript version to $new_version" + git commit -m "[ci skip] update buildscript version to $new_version" git push - echo "[ci skip] update buildscript version"; + echo "updated buildscript version to $new_version"; +else + echo "no buildscript changes detected - ignoring version update" fi From d0178328370ab440a2bbd11f989165aa797e3057 Mon Sep 17 00:00:00 2001 From: Telan <13066272+TheElan@users.noreply.github.com> Date: Fri, 12 Nov 2021 19:29:11 +0200 Subject: [PATCH 07/45] fix migration release tag --- .github/workflows/repository-specific.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/repository-specific.yml b/.github/workflows/repository-specific.yml index d80e172..6f59035 100644 --- a/.github/workflows/repository-specific.yml +++ b/.github/workflows/repository-specific.yml @@ -70,7 +70,7 @@ jobs: uses: "marvinpinto/action-automatic-releases@latest" with: repo_token: "${{ secrets.GITHUB_TOKEN }}" - automatic_release_tag: "latest-starer" + automatic_release_tag: "latest-migration" prerelease: true title: "Latest migration package" files: "migration.zip" From 7663643a830b8e4975f9921341f0297e8683c227 Mon Sep 17 00:00:00 2001 From: Telan <13066272+TheElan@users.noreply.github.com> Date: Fri, 12 Nov 2021 19:29:48 +0200 Subject: [PATCH 08/45] ci: increase fetch-depth for buildscript-maintenance --- .github/workflows/repository-specific.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/repository-specific.yml b/.github/workflows/repository-specific.yml index 6f59035..2c6ccb9 100644 --- a/.github/workflows/repository-specific.yml +++ b/.github/workflows/repository-specific.yml @@ -9,13 +9,13 @@ on: branches: [ master, main ] jobs: - buildscript-maintenece: + buildscript-maintenance: runs-on: ubuntu-latest steps: - name: Checkout uses: actions/checkout@v2 with: - fetch-depth: 1 + fetch-depth: 2 - name: Ensure build script version is updated run: .github/scripts/update-version.sh From f5f39138e2d441748a13de372b5a78f4a64608e4 Mon Sep 17 00:00:00 2001 From: Telan <13066272+TheElan@users.noreply.github.com> Date: Fri, 12 Nov 2021 19:38:49 +0200 Subject: [PATCH 09/45] ci: exclude starter and migration packages from themselves excluding both in each step case order of steps will change --- .github/workflows/repository-specific.yml | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/.github/workflows/repository-specific.yml b/.github/workflows/repository-specific.yml index 2c6ccb9..958eceb 100644 --- a/.github/workflows/repository-specific.yml +++ b/.github/workflows/repository-specific.yml @@ -1,10 +1,10 @@ # This workflow only meant for the source mod you shouldn't bring it into your own project -name: Buildscript update CI +name: Repository specific CI on: push: - branches: [ master, main, buildscript-versioning-and-migration-zip ] # todo: remove temporary test branch from here + branches: [ master, main ] pull_request: branches: [ master, main ] @@ -17,7 +17,7 @@ jobs: with: fetch-depth: 2 - - name: Ensure build script version is updated + - name: Ensure build script version is up to date run: .github/scripts/update-version.sh zip-packages: @@ -39,7 +39,10 @@ jobs: \ -x "*docs/*" \ -x "LICENSE" \ - -x "README.md" + -x "README.md" \ + \ + -x "starter.zip" \ + -x "migration.zip" - name: Publish starter package uses: "marvinpinto/action-automatic-releases@latest" @@ -64,7 +67,10 @@ jobs: -x "*docs/*" \ -x "*src/*" \ -x "LICENSE" \ - -x "README.md" + -x "README.md" \ + \ + -x "starter.zip" \ + -x "migration.zip" - name: Publish migration package uses: "marvinpinto/action-automatic-releases@latest" From 73195c0a9287b66505a9d37b47d354d6a0088221 Mon Sep 17 00:00:00 2001 From: Telan <13066272+TheElan@users.noreply.github.com> Date: Fri, 12 Nov 2021 19:39:14 +0200 Subject: [PATCH 10/45] docs: update starter and migration package links to reference the latest tag assets --- README.md | 4 ++-- docs/migration.md | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index b0ef929..d837abc 100644 --- a/README.md +++ b/README.md @@ -12,8 +12,8 @@ We had our fair share in struggles with build scripts for Minecraft Forge. There ### Getting started Creating mod from scratch: -1. Unzip [project starter](TODO: insert the latest starter.zip link) -2. Commit it to your VCS of choice for later reference (e.g. in root directory `git init; git commit -m "initialise repository"`) +1. Unzip [project starter](https://github.com/SinTh0r4s/ExampleMod1.7.10/releases/download/latest-starer/starter.zip) into project directory. +2. Ensure your project is under VCS. For example initialise git repository by running `git init; git commit --message "initialized repository"`. 3. Replace placeholders (edit values in gradle.properties, change example package and class names, etc.) 4. Run `./gradlew setupDecompWorkspace` (if build fails with `Could not find :forgeBin:1.7.10-10.13.4.1614-1.7.10.` this should fix it) 5. Make sure to check out the rest sections of this file. diff --git a/docs/migration.md b/docs/migration.md index 21bb17e..5029cfc 100644 --- a/docs/migration.md +++ b/docs/migration.md @@ -5,7 +5,7 @@ Migration for the typical mod which doesn't use anything special but Minecraft f For core plugin, Mixins, shadowing, access transformers, ASM or etc. you'll need to do some extra steps. If they are missing in this document - we will gladly receive your suggestions/contribution. -1. Copy and replace all files from [template](TODO: insert the latest migration.zip link) to your repository, but: +1. Copy and replace all files from [template](https://github.com/SinTh0r4s/ExampleMod1.7.10/releases/download/latest-migration/migration.zip) to your repository, but: 1. `build.gradle` 2. `src` 3. `LICENSE` From dc1e8025b462002e7ca132a560c9aa6e0b352d33 Mon Sep 17 00:00:00 2001 From: Telan <13066272+TheElan@users.noreply.github.com> Date: Fri, 12 Nov 2021 19:40:51 +0200 Subject: [PATCH 11/45] docs: update migration.md to match package content --- docs/migration.md | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/docs/migration.md b/docs/migration.md index 5029cfc..c8c9bd7 100644 --- a/docs/migration.md +++ b/docs/migration.md @@ -5,15 +5,10 @@ Migration for the typical mod which doesn't use anything special but Minecraft f For core plugin, Mixins, shadowing, access transformers, ASM or etc. you'll need to do some extra steps. If they are missing in this document - we will gladly receive your suggestions/contribution. -1. Copy and replace all files from [template](https://github.com/SinTh0r4s/ExampleMod1.7.10/releases/download/latest-migration/migration.zip) to your repository, but: - 1. `build.gradle` - 2. `src` - 3. `LICENSE` - 4. `README.md` - 5. `build.gradle(.kts)` +1. Copy and replace all files from [template](https://github.com/SinTh0r4s/ExampleMod1.7.10/releases/download/latest-migration/migration.zip) to your repository, but `build.gradle` 2. Copy all repositories from your `build.gradle(.kts)` to `repositories.gradle` 3. Copy all dependencies from your `build.gradle(.kts)` to `dependecies.gradle` -4. replace your `build.gradle(.kts)` with `build.gradle` from template. In case you have written some custom tasks/configurations not present in the template - you'll best to move them to separate file and link it in this, like for example it does this with `dependencies.gradle` +4. replace your `build.gradle(.kts)` with `build.gradle` from template. In case you have written some custom tasks/configurations not present in the template - move them to separate file and link it in this, like for example it does this with `dependencies.gradle` 5. Adapt `gradle.properties` to your mod 6. Ensure `src/main/resources/mcmod.info` contains `${modId}`, `${modName}`. `${modVersion}` and `${minecraftVersion}` 7. Re-import the project to your IDE (e.g. restart with clean caches in IntelliJ IDEA) From 4f5eba7642f9bd6fb085446f72b2a9cd333accdf Mon Sep 17 00:00:00 2001 From: Telan <13066272+TheElan@users.noreply.github.com> Date: Fri, 12 Nov 2021 19:45:12 +0200 Subject: [PATCH 12/45] build: update main build script to test automatic version update --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 715ee07..696fda4 100644 --- a/build.gradle +++ b/build.gradle @@ -1,4 +1,4 @@ -//version: commit hash placeholder +//version: commit hash placeholder; dummy changes to test automatic version update /* DO NOT CHANGE THIS FILE! From 260e34e0fa4abae5fdb21b3e1df7ad3ba9099213 Mon Sep 17 00:00:00 2001 From: Telan <13066272+TheElan@users.noreply.github.com> Date: Fri, 12 Nov 2021 19:48:51 +0200 Subject: [PATCH 13/45] fix update-version.sh checking wrong file --- .github/scripts/update-version.sh | 8 ++++---- build.gradle | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/scripts/update-version.sh b/.github/scripts/update-version.sh index 226cb95..6c38420 100755 --- a/.github/scripts/update-version.sh +++ b/.github/scripts/update-version.sh @@ -1,10 +1,10 @@ -if [ ! -z $(git diff --name-only HEAD HEAD~1 | grep dependencies.gradle) ]; then +if [ ! -z $(git diff --name-only HEAD HEAD~1 | grep build.gradle) ]; then new_version="$(git log -n1 --format=format:"%H")" sed --in-place "s!//version:.*!//version: $new_version!g" build.gradle git add build.gradle - git commit -m "[ci skip] update buildscript version to $new_version" + git commit -m "[ci skip] update build script version to $new_version" git push - echo "updated buildscript version to $new_version"; + echo "Updated build script version to $new_version"; else - echo "no buildscript changes detected - ignoring version update" + echo "Ignored build script version update: no changed detected" fi diff --git a/build.gradle b/build.gradle index 696fda4..715ee07 100644 --- a/build.gradle +++ b/build.gradle @@ -1,4 +1,4 @@ -//version: commit hash placeholder; dummy changes to test automatic version update +//version: commit hash placeholder /* DO NOT CHANGE THIS FILE! From ef157d88076651d2b0e2b7c13f6d5d4f93933fcd Mon Sep 17 00:00:00 2001 From: Telan <13066272+TheElan@users.noreply.github.com> Date: Fri, 12 Nov 2021 19:51:49 +0200 Subject: [PATCH 14/45] ci: configure git before committing updated buildscript --- .github/scripts/update-version.sh | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/.github/scripts/update-version.sh b/.github/scripts/update-version.sh index 6c38420..5158684 100755 --- a/.github/scripts/update-version.sh +++ b/.github/scripts/update-version.sh @@ -1,10 +1,14 @@ if [ ! -z $(git diff --name-only HEAD HEAD~1 | grep build.gradle) ]; then new_version="$(git log -n1 --format=format:"%H")" sed --in-place "s!//version:.*!//version: $new_version!g" build.gradle + + git config user.email "johann.bernhardt@tum.de" + git config user.name "Github CI Worker" + git add build.gradle git commit -m "[ci skip] update build script version to $new_version" git push - echo "Updated build script version to $new_version"; + echo "Updated buildscript version to $new_version"; else - echo "Ignored build script version update: no changed detected" + echo "Ignored buildscript version update: no changes detected" fi From b6408ca4719c0b046b00de9a6efad3ba1726324b Mon Sep 17 00:00:00 2001 From: Telan <13066272+TheElan@users.noreply.github.com> Date: Fri, 12 Nov 2021 19:52:16 +0200 Subject: [PATCH 15/45] build: update main build script to test automatic version update --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 715ee07..696fda4 100644 --- a/build.gradle +++ b/build.gradle @@ -1,4 +1,4 @@ -//version: commit hash placeholder +//version: commit hash placeholder; dummy changes to test automatic version update /* DO NOT CHANGE THIS FILE! From 61028b6cf18d40e122bb0fa25b23dbc37c10e856 Mon Sep 17 00:00:00 2001 From: Telan <13066272+TheElan@users.noreply.github.com> Date: Fri, 12 Nov 2021 19:57:50 +0200 Subject: [PATCH 16/45] ci: configure git in separate step; specify current branch when pushing new builscript version --- .github/scripts/update-version.sh | 6 +----- .github/workflows/repository-specific.yml | 4 ++++ build.gradle | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/scripts/update-version.sh b/.github/scripts/update-version.sh index 5158684..cd60431 100755 --- a/.github/scripts/update-version.sh +++ b/.github/scripts/update-version.sh @@ -1,13 +1,9 @@ if [ ! -z $(git diff --name-only HEAD HEAD~1 | grep build.gradle) ]; then new_version="$(git log -n1 --format=format:"%H")" sed --in-place "s!//version:.*!//version: $new_version!g" build.gradle - - git config user.email "johann.bernhardt@tum.de" - git config user.name "Github CI Worker" - git add build.gradle git commit -m "[ci skip] update build script version to $new_version" - git push + git push origin ${GITHUB_REF##*/} echo "Updated buildscript version to $new_version"; else echo "Ignored buildscript version update: no changes detected" diff --git a/.github/workflows/repository-specific.yml b/.github/workflows/repository-specific.yml index 958eceb..0780ad2 100644 --- a/.github/workflows/repository-specific.yml +++ b/.github/workflows/repository-specific.yml @@ -16,6 +16,10 @@ jobs: uses: actions/checkout@v2 with: fetch-depth: 2 + - name: setup git config + run: | + git config user.name "GitHub CI Bot" + git config user.email "<>" - name: Ensure build script version is up to date run: .github/scripts/update-version.sh diff --git a/build.gradle b/build.gradle index 696fda4..715ee07 100644 --- a/build.gradle +++ b/build.gradle @@ -1,4 +1,4 @@ -//version: commit hash placeholder; dummy changes to test automatic version update +//version: commit hash placeholder /* DO NOT CHANGE THIS FILE! From b49c99b008eb1427913bd61c66ee9113cd116cbe Mon Sep 17 00:00:00 2001 From: Telan <13066272+TheElan@users.noreply.github.com> Date: Fri, 12 Nov 2021 20:01:08 +0200 Subject: [PATCH 17/45] ci: fix formatting --- .github/workflows/repository-specific.yml | 9 +++++---- build.gradle | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/.github/workflows/repository-specific.yml b/.github/workflows/repository-specific.yml index 0780ad2..5a9dedc 100644 --- a/.github/workflows/repository-specific.yml +++ b/.github/workflows/repository-specific.yml @@ -16,10 +16,11 @@ jobs: uses: actions/checkout@v2 with: fetch-depth: 2 - - name: setup git config - run: | - git config user.name "GitHub CI Bot" - git config user.email "<>" + + - name: setup git config + run: | + git config user.name "GitHub CI Bot" + git config user.email "<>" - name: Ensure build script version is up to date run: .github/scripts/update-version.sh diff --git a/build.gradle b/build.gradle index 715ee07..696fda4 100644 --- a/build.gradle +++ b/build.gradle @@ -1,4 +1,4 @@ -//version: commit hash placeholder +//version: commit hash placeholder; dummy changes to test automatic version update /* DO NOT CHANGE THIS FILE! From 62988f1c0a0d54387258dec45f869b6320afdca5 Mon Sep 17 00:00:00 2001 From: Telan <13066272+TheElan@users.noreply.github.com> Date: Fri, 12 Nov 2021 20:08:40 +0200 Subject: [PATCH 18/45] split workflows to only release on main branches --- .github/workflows/buildscript-maintenance.yml | 26 +++++++++++++++ ...itory-specific.yml => package-release.yml} | 28 ++++------------ .github/workflows/pull-request.yml | 32 +++++++++++++++++++ .github/workflows/{gradle.yml => release.yml} | 4 +-- 4 files changed, 65 insertions(+), 25 deletions(-) create mode 100644 .github/workflows/buildscript-maintenance.yml rename .github/workflows/{repository-specific.yml => package-release.yml} (75%) create mode 100644 .github/workflows/pull-request.yml rename .github/workflows/{gradle.yml => release.yml} (93%) diff --git a/.github/workflows/buildscript-maintenance.yml b/.github/workflows/buildscript-maintenance.yml new file mode 100644 index 0000000..5d9a417 --- /dev/null +++ b/.github/workflows/buildscript-maintenance.yml @@ -0,0 +1,26 @@ +# This workflow only meant for the source mod you shouldn't bring it into your own project + +name: Buildscript maintenance + +on: + push: + branches: [ master, main ] + pull_request: + branches: [ master, main ] + +jobs: + buildscript-maintenance: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v2 + with: + fetch-depth: 2 + + - name: setup git config + run: | + git config user.name "GitHub CI Bot" + git config user.email "<>" + + - name: Ensure build script version is up to date + run: .github/scripts/update-version.sh diff --git a/.github/workflows/repository-specific.yml b/.github/workflows/package-release.yml similarity index 75% rename from .github/workflows/repository-specific.yml rename to .github/workflows/package-release.yml index 5a9dedc..b036a04 100644 --- a/.github/workflows/repository-specific.yml +++ b/.github/workflows/package-release.yml @@ -1,30 +1,12 @@ # This workflow only meant for the source mod you shouldn't bring it into your own project -name: Repository specific CI +name: Release packages on: push: branches: [ master, main ] - pull_request: - branches: [ master, main ] jobs: - buildscript-maintenance: - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v2 - with: - fetch-depth: 2 - - - name: setup git config - run: | - git config user.name "GitHub CI Bot" - git config user.email "<>" - - - name: Ensure build script version is up to date - run: .github/scripts/update-version.sh - zip-packages: runs-on: ubuntu-latest steps: @@ -40,7 +22,8 @@ jobs: -x "*.git/*" \ \ -x ".github/scripts/update-version.sh" \ - -x ".github/workflows/repository-specific.yml" \ + -x ".github/workflows/buildscript-maintenance.yml" \ + -x ".github/workflows/package-release.yml" \ \ -x "*docs/*" \ -x "LICENSE" \ @@ -67,7 +50,8 @@ jobs: -x "*.git/*" \ \ -x ".github/scripts/update-version.sh" \ - -x ".github/workflows/repository-specific.yml" \ + -x ".github/workflows/buildscript-maintenance.yml" \ + -x ".github/workflows/package-release.yml" \ \ -x "*docs/*" \ -x "*src/*" \ @@ -76,7 +60,7 @@ jobs: \ -x "starter.zip" \ -x "migration.zip" - + - name: Publish migration package uses: "marvinpinto/action-automatic-releases@latest" with: diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml new file mode 100644 index 0000000..f4e30c1 --- /dev/null +++ b/.github/workflows/pull-request.yml @@ -0,0 +1,32 @@ +# This workflow will build a Java project with Gradle and cache/restore any dependencies to improve the workflow execution time +# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-gradle + +name: Build pull request + +on: + pull_request: + branches: [ master, main ] + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + with: + fetch-depth: 0 + + - name: Set up JDK 8 + uses: actions/setup-java@v2 + with: + java-version: '8' + distribution: 'adopt' + cache: gradle + + - name: Grant execute permission for gradlew + run: chmod +x gradlew + + - name: Setup the workspace + run: ./gradlew setupCIWorkspace + + - name: Build the mod + run: ./gradlew build diff --git a/.github/workflows/gradle.yml b/.github/workflows/release.yml similarity index 93% rename from .github/workflows/gradle.yml rename to .github/workflows/release.yml index 7533889..6a64794 100644 --- a/.github/workflows/gradle.yml +++ b/.github/workflows/release.yml @@ -1,13 +1,11 @@ # This workflow will build a Java project with Gradle and cache/restore any dependencies to improve the workflow execution time # For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-gradle -name: Java CI with Gradle +name: Build and release main branch on: push: branches: [ master, main ] - pull_request: - branches: [ master, main ] jobs: build: From 7a4593ecc954c5c7f32787b02112ac1bbbb86a30 Mon Sep 17 00:00:00 2001 From: Telan <13066272+TheElan@users.noreply.github.com> Date: Fri, 12 Nov 2021 20:11:04 +0200 Subject: [PATCH 19/45] fix update-version.sh not pushing HEAD to branch --- .github/scripts/update-version.sh | 2 +- build.gradle | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/scripts/update-version.sh b/.github/scripts/update-version.sh index cd60431..ec9e040 100755 --- a/.github/scripts/update-version.sh +++ b/.github/scripts/update-version.sh @@ -3,7 +3,7 @@ if [ ! -z $(git diff --name-only HEAD HEAD~1 | grep build.gradle) ]; then sed --in-place "s!//version:.*!//version: $new_version!g" build.gradle git add build.gradle git commit -m "[ci skip] update build script version to $new_version" - git push origin ${GITHUB_REF##*/} + git push origin HEAD:${GITHUB_REF##*/} echo "Updated buildscript version to $new_version"; else echo "Ignored buildscript version update: no changes detected" diff --git a/build.gradle b/build.gradle index 696fda4..715ee07 100644 --- a/build.gradle +++ b/build.gradle @@ -1,4 +1,4 @@ -//version: commit hash placeholder; dummy changes to test automatic version update +//version: commit hash placeholder /* DO NOT CHANGE THIS FILE! From 82c8c9dcad3465ef46c4d0518c447a42388244f4 Mon Sep 17 00:00:00 2001 From: Telan <13066272+TheElan@users.noreply.github.com> Date: Fri, 12 Nov 2021 20:12:37 +0200 Subject: [PATCH 20/45] fix update-version.sh not pushing HEAD to branch --- .github/scripts/update-version.sh | 3 ++- build.gradle | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/scripts/update-version.sh b/.github/scripts/update-version.sh index ec9e040..7005ea5 100755 --- a/.github/scripts/update-version.sh +++ b/.github/scripts/update-version.sh @@ -1,9 +1,10 @@ +git checkout ${GITHUB_REF##*/} if [ ! -z $(git diff --name-only HEAD HEAD~1 | grep build.gradle) ]; then new_version="$(git log -n1 --format=format:"%H")" sed --in-place "s!//version:.*!//version: $new_version!g" build.gradle git add build.gradle git commit -m "[ci skip] update build script version to $new_version" - git push origin HEAD:${GITHUB_REF##*/} + git push echo "Updated buildscript version to $new_version"; else echo "Ignored buildscript version update: no changes detected" diff --git a/build.gradle b/build.gradle index 715ee07..ab772ae 100644 --- a/build.gradle +++ b/build.gradle @@ -1,4 +1,4 @@ -//version: commit hash placeholder +//version: commit hash placeholder; dummysome changes to test automatic version update /* DO NOT CHANGE THIS FILE! From c926328a0e1cdfd8090175bd0befd48a9054527a Mon Sep 17 00:00:00 2001 From: Telan <13066272+TheElan@users.noreply.github.com> Date: Fri, 12 Nov 2021 20:16:24 +0200 Subject: [PATCH 21/45] debug to check if branch name is correctly obtained --- .github/scripts/update-version.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/scripts/update-version.sh b/.github/scripts/update-version.sh index 7005ea5..420439c 100755 --- a/.github/scripts/update-version.sh +++ b/.github/scripts/update-version.sh @@ -1,4 +1,5 @@ -git checkout ${GITHUB_REF##*/} +echo "Currently only ${GITHUB_REF_NAME}" +git checkout $GITHUB_REF_NAME if [ ! -z $(git diff --name-only HEAD HEAD~1 | grep build.gradle) ]; then new_version="$(git log -n1 --format=format:"%H")" sed --in-place "s!//version:.*!//version: $new_version!g" build.gradle From 9e47698f9074cb75ed6cc45dbc20494233908ca5 Mon Sep 17 00:00:00 2001 From: Telan <13066272+TheElan@users.noreply.github.com> Date: Fri, 12 Nov 2021 20:57:53 +0200 Subject: [PATCH 22/45] run buildscript-maintenance.yml on all branch pushes --- .github/scripts/update-version.sh | 4 ++-- .github/workflows/buildscript-maintenance.yml | 6 +----- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/.github/scripts/update-version.sh b/.github/scripts/update-version.sh index 420439c..f73c5a1 100755 --- a/.github/scripts/update-version.sh +++ b/.github/scripts/update-version.sh @@ -1,5 +1,5 @@ -echo "Currently only ${GITHUB_REF_NAME}" -git checkout $GITHUB_REF_NAME +echo "Currently on ${GITHUB_REF##*/}" +git checkout ${GITHUB_REF##*/} if [ ! -z $(git diff --name-only HEAD HEAD~1 | grep build.gradle) ]; then new_version="$(git log -n1 --format=format:"%H")" sed --in-place "s!//version:.*!//version: $new_version!g" build.gradle diff --git a/.github/workflows/buildscript-maintenance.yml b/.github/workflows/buildscript-maintenance.yml index 5d9a417..d7ea0cd 100644 --- a/.github/workflows/buildscript-maintenance.yml +++ b/.github/workflows/buildscript-maintenance.yml @@ -2,11 +2,7 @@ name: Buildscript maintenance -on: - push: - branches: [ master, main ] - pull_request: - branches: [ master, main ] +on: [push] jobs: buildscript-maintenance: From edb7416b756cc57c99d5c53f0dd3b9477b764628 Mon Sep 17 00:00:00 2001 From: Telan <13066272+TheElan@users.noreply.github.com> Date: Fri, 12 Nov 2021 20:59:05 +0200 Subject: [PATCH 23/45] build: update main build script to test automatic version update --- .github/scripts/update-version.sh | 2 -- build.gradle | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/.github/scripts/update-version.sh b/.github/scripts/update-version.sh index f73c5a1..d4d9c3d 100755 --- a/.github/scripts/update-version.sh +++ b/.github/scripts/update-version.sh @@ -1,5 +1,3 @@ -echo "Currently on ${GITHUB_REF##*/}" -git checkout ${GITHUB_REF##*/} if [ ! -z $(git diff --name-only HEAD HEAD~1 | grep build.gradle) ]; then new_version="$(git log -n1 --format=format:"%H")" sed --in-place "s!//version:.*!//version: $new_version!g" build.gradle diff --git a/build.gradle b/build.gradle index ab772ae..715ee07 100644 --- a/build.gradle +++ b/build.gradle @@ -1,4 +1,4 @@ -//version: commit hash placeholder; dummysome changes to test automatic version update +//version: commit hash placeholder /* DO NOT CHANGE THIS FILE! From 281e84c4f69665c4990294c3b2c42d2fe3c090a6 Mon Sep 17 00:00:00 2001 From: GitHub CI Bot <> Date: Fri, 12 Nov 2021 18:59:36 +0000 Subject: [PATCH 24/45] [ci skip] update build script version to edb7416b756cc57c99d5c53f0dd3b9477b764628 --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 715ee07..2977547 100644 --- a/build.gradle +++ b/build.gradle @@ -1,4 +1,4 @@ -//version: commit hash placeholder +//version: edb7416b756cc57c99d5c53f0dd3b9477b764628 /* DO NOT CHANGE THIS FILE! From 62e04b207f3ee659e5faaa4620caea0c722cb322 Mon Sep 17 00:00:00 2001 From: Dmytro <13066272+TheElan@users.noreply.github.com> Date: Sat, 13 Nov 2021 21:05:10 +0200 Subject: [PATCH 25/45] add default MIT license to starter --- .github/workflows/package-release.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/package-release.yml b/.github/workflows/package-release.yml index b036a04..7644611 100644 --- a/.github/workflows/package-release.yml +++ b/.github/workflows/package-release.yml @@ -26,7 +26,6 @@ jobs: -x ".github/workflows/package-release.yml" \ \ -x "*docs/*" \ - -x "LICENSE" \ -x "README.md" \ \ -x "starter.zip" \ From 0475c12ef3e1737315f64194e8fa62ee43a15629 Mon Sep 17 00:00:00 2001 From: Dmytro <13066272+TheElan@users.noreply.github.com> Date: Sat, 13 Nov 2021 21:17:06 +0200 Subject: [PATCH 26/45] exclude original license from starter --- .github/workflows/package-release.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/package-release.yml b/.github/workflows/package-release.yml index 7644611..c720cfa 100644 --- a/.github/workflows/package-release.yml +++ b/.github/workflows/package-release.yml @@ -27,6 +27,7 @@ jobs: \ -x "*docs/*" \ -x "README.md" \ + -x "LICENSE" \ \ -x "starter.zip" \ -x "migration.zip" From 410cfddb912d22eaf9e032fc343e00c4962c58e5 Mon Sep 17 00:00:00 2001 From: Dmytro <13066272+TheElan@users.noreply.github.com> Date: Sat, 13 Nov 2021 21:17:56 +0200 Subject: [PATCH 27/45] add template license --- LICENSE-template | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 LICENSE-template diff --git a/LICENSE-template b/LICENSE-template new file mode 100644 index 0000000..242da62 --- /dev/null +++ b/LICENSE-template @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. From 43b34e5b64f2aeda9547c06753fce5d4ad90970f Mon Sep 17 00:00:00 2001 From: Dmytro <13066272+TheElan@users.noreply.github.com> Date: Sat, 13 Nov 2021 21:29:37 +0200 Subject: [PATCH 28/45] readme: add license step to getting started --- README.md | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index d837abc..30bd841 100644 --- a/README.md +++ b/README.md @@ -13,11 +13,12 @@ We had our fair share in struggles with build scripts for Minecraft Forge. There Creating mod from scratch: 1. Unzip [project starter](https://github.com/SinTh0r4s/ExampleMod1.7.10/releases/download/latest-starer/starter.zip) into project directory. -2. Ensure your project is under VCS. For example initialise git repository by running `git init; git commit --message "initialized repository"`. -3. Replace placeholders (edit values in gradle.properties, change example package and class names, etc.) -4. Run `./gradlew setupDecompWorkspace` (if build fails with `Could not find :forgeBin:1.7.10-10.13.4.1614-1.7.10.` this should fix it) -5. Make sure to check out the rest sections of this file. -6. You are good to go! +2. Replace placeholders in LICENSE-template and rename it to LICENSE, or remove LICENSE-template and put any other license you like on your code. This is an permissive OSS project and we encourage you participate in OSS movement by having permissive license like one in template. You can find out pros and cons of OSS software in [this article](https://www.freecodecamp.org/news/what-is-great-about-developing-open-source-and-what-is-not/) +3. Ensure your project is under VCS. For example initialise git repository by running `git init; git commit --message "initialized repository"`. +4. Replace placeholders (edit values in gradle.properties, change example package and class names, etc.) +5. Run `./gradlew setupDecompWorkspace` (if build fails with `Could not find :forgeBin:1.7.10-10.13.4.1614-1.7.10.` this should fix it) +6. Make sure to check out the rest sections of this file. +7. You are good to go! We also have described guidelines for existing mod [migration](docs/migration.md) and [porting](docs/porting.md) From b61969b80aa3f0b5eab40e92bf943011395d0114 Mon Sep 17 00:00:00 2001 From: Johann Bernhardt Date: Sat, 13 Nov 2021 22:44:47 +0100 Subject: [PATCH 29/45] Add update check in build.gradle --- build.gradle | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index a2c99de..4d6edcd 100644 --- a/build.gradle +++ b/build.gradle @@ -52,12 +52,23 @@ if(JavaVersion.current() != JavaVersion.VERSION_1_8) { throw new GradleException("This project requires Java 8, but it's running on " + JavaVersion.current()) } +String getVersionHash(String buildScriptContent) { + String[] lines = buildScriptContent.split("\n") + if(lines.size() > 0 && lines[0].startsWith("//version: ")) { + return lines[0].substring(11) + } + return "" +} + def checkForUpdate() { Thread.start { Map parameters = [ "connectTimeout" : 2000, "readTimeout": 2000 ] String currentBuildScript = new File("build.gradle").getText() + String currentBuildScriptHash = getVersionHash(currentBuildScript) String availableBuildScript = new URL("https://raw.githubusercontent.com/SinTh0r4s/ExampleMod1.7.10/main/build.gradle").newInputStream(parameters).getText() - if (availableBuildScript.equals("") == false && currentBuildScript.equals(availableBuildScript) == false) { + String availableBuildScriptHash = getVersionHash(availableBuildScript) + if (currentBuildScriptHash.equals("") == false && availableBuildScriptHash.equals("") == false + && currentBuildScriptHash.equals(availableBuildScriptHash) == false) { println("Build script update available! Check https://github.com/SinTh0r4s/ExampleMod1.7.10/blob/main/build.gradle"); } } From fa415ec9e657b7f2a4f0e03799da45ed83030617 Mon Sep 17 00:00:00 2001 From: GitHub CI Bot <> Date: Sat, 13 Nov 2021 21:45:02 +0000 Subject: [PATCH 30/45] [ci skip] update build script version to b61969b80aa3f0b5eab40e92bf943011395d0114 --- build.gradle | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/build.gradle b/build.gradle index 4d6edcd..608b813 100644 --- a/build.gradle +++ b/build.gradle @@ -1,4 +1,4 @@ -//version: edb7416b756cc57c99d5c53f0dd3b9477b764628 +//version: b61969b80aa3f0b5eab40e92bf943011395d0114 /* DO NOT CHANGE THIS FILE! @@ -54,7 +54,7 @@ if(JavaVersion.current() != JavaVersion.VERSION_1_8) { String getVersionHash(String buildScriptContent) { String[] lines = buildScriptContent.split("\n") - if(lines.size() > 0 && lines[0].startsWith("//version: ")) { + if(lines.size() > 0 && lines[0].startsWith("//version: b61969b80aa3f0b5eab40e92bf943011395d0114 return lines[0].substring(11) } return "" From ea29d6853b81cfaeb46cfc52ef88bd27037471ed Mon Sep 17 00:00:00 2001 From: Telan <13066272+TheElan@users.noreply.github.com> Date: Sun, 14 Nov 2021 21:23:42 +0200 Subject: [PATCH 31/45] build: fix maintenance script replacing too much strings --- .github/scripts/update-version.sh | 2 +- build.gradle | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/scripts/update-version.sh b/.github/scripts/update-version.sh index d4d9c3d..2c862bd 100755 --- a/.github/scripts/update-version.sh +++ b/.github/scripts/update-version.sh @@ -1,6 +1,6 @@ if [ ! -z $(git diff --name-only HEAD HEAD~1 | grep build.gradle) ]; then new_version="$(git log -n1 --format=format:"%H")" - sed --in-place "s!//version:.*!//version: $new_version!g" build.gradle + sed --in-place "s!//^version:.*!//version: $new_version!g" build.gradle git add build.gradle git commit -m "[ci skip] update build script version to $new_version" git push diff --git a/build.gradle b/build.gradle index 608b813..ab33b92 100644 --- a/build.gradle +++ b/build.gradle @@ -1,4 +1,4 @@ -//version: b61969b80aa3f0b5eab40e92bf943011395d0114 +//version: b61969b80aa3f0b5eab40e92bf943011395d0114ssssss /* DO NOT CHANGE THIS FILE! @@ -52,10 +52,10 @@ if(JavaVersion.current() != JavaVersion.VERSION_1_8) { throw new GradleException("This project requires Java 8, but it's running on " + JavaVersion.current()) } -String getVersionHash(String buildScriptContent) { - String[] lines = buildScriptContent.split("\n") - if(lines.size() > 0 && lines[0].startsWith("//version: b61969b80aa3f0b5eab40e92bf943011395d0114 - return lines[0].substring(11) +static String getVersionHash(String buildScriptContent) { + String versionLine = buildScriptContent.find("^//version: [a-z0-9]*") + if(versionLine != null) { + return versionLine.split(": ").last() } return "" } From 1686cf954fdf9330b69f0b6b19e51bf2dcbe9c2c Mon Sep 17 00:00:00 2001 From: Telan <13066272+TheElan@users.noreply.github.com> Date: Sun, 14 Nov 2021 21:29:04 +0200 Subject: [PATCH 32/45] [ci skip] update build script version to ea29d6853b81cfaeb46cfc52ef88bd27037471ed --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index ab33b92..29a4507 100644 --- a/build.gradle +++ b/build.gradle @@ -1,4 +1,4 @@ -//version: b61969b80aa3f0b5eab40e92bf943011395d0114ssssss +//version: ea29d6853b81cfaeb46cfc52ef88bd27037471ed /* DO NOT CHANGE THIS FILE! From 87f95561f0b7146863678eb239280ac829d1de0a Mon Sep 17 00:00:00 2001 From: Telan <13066272+TheElan@users.noreply.github.com> Date: Sun, 14 Nov 2021 21:29:40 +0200 Subject: [PATCH 33/45] build: fix maintenance not picking up version --- .github/scripts/update-version.sh | 2 +- build.gradle | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/scripts/update-version.sh b/.github/scripts/update-version.sh index 2c862bd..6ab1b17 100755 --- a/.github/scripts/update-version.sh +++ b/.github/scripts/update-version.sh @@ -1,6 +1,6 @@ if [ ! -z $(git diff --name-only HEAD HEAD~1 | grep build.gradle) ]; then new_version="$(git log -n1 --format=format:"%H")" - sed --in-place "s!//^version:.*!//version: $new_version!g" build.gradle + sed --in-place "s!^//version:.*!//version: $new_version!g" build.gradle git add build.gradle git commit -m "[ci skip] update build script version to $new_version" git push diff --git a/build.gradle b/build.gradle index 29a4507..b1d0135 100644 --- a/build.gradle +++ b/build.gradle @@ -1,4 +1,4 @@ -//version: ea29d6853b81cfaeb46cfc52ef88bd27037471ed +//version: ea29d6853b81cfaeb46cfc52ef88bd27037471 test CI /* DO NOT CHANGE THIS FILE! From 30c0c0f606323221df56dbd1c4c8c03cbe8f7329 Mon Sep 17 00:00:00 2001 From: GitHub CI Bot <> Date: Sun, 14 Nov 2021 19:29:54 +0000 Subject: [PATCH 34/45] [ci skip] update build script version to 87f95561f0b7146863678eb239280ac829d1de0a --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index b1d0135..76f8122 100644 --- a/build.gradle +++ b/build.gradle @@ -1,4 +1,4 @@ -//version: ea29d6853b81cfaeb46cfc52ef88bd27037471 test CI +//version: 87f95561f0b7146863678eb239280ac829d1de0a /* DO NOT CHANGE THIS FILE! From 04059a9fcbe502f677c7e2e757f97699da5f049f Mon Sep 17 00:00:00 2001 From: Telan <13066272+TheElan@users.noreply.github.com> Date: Sun, 14 Nov 2021 21:39:07 +0200 Subject: [PATCH 35/45] build: refine checkForUpdate --- build.gradle | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/build.gradle b/build.gradle index 76f8122..d65fd67 100644 --- a/build.gradle +++ b/build.gradle @@ -8,6 +8,7 @@ Please check https://github.com/SinTh0r4s/ExampleMod1.7.10/blob/main/build.gradl import com.github.jengelman.gradle.plugins.shadow.tasks.ConfigureShadowRelocation + import java.util.concurrent.TimeUnit buildscript { @@ -60,17 +61,19 @@ static String getVersionHash(String buildScriptContent) { return "" } -def checkForUpdate() { +static def checkForUpdate() { Thread.start { - Map parameters = [ "connectTimeout" : 2000, "readTimeout": 2000 ] + Map parameters = ["connectTimeout": 2000, "readTimeout": 2000] + String currentBuildScript = new File("build.gradle").getText() String currentBuildScriptHash = getVersionHash(currentBuildScript) + String availableBuildScript = new URL("https://raw.githubusercontent.com/SinTh0r4s/ExampleMod1.7.10/main/build.gradle").newInputStream(parameters).getText() String availableBuildScriptHash = getVersionHash(availableBuildScript) - if (currentBuildScriptHash.equals("") == false && availableBuildScriptHash.equals("") == false - && currentBuildScriptHash.equals(availableBuildScriptHash) == false) { - println("Build script update available! Check https://github.com/SinTh0r4s/ExampleMod1.7.10/blob/main/build.gradle"); - } + + if (currentBuildScriptHash.empty || availableBuildScriptHash.empty || currentBuildScriptHash == availableBuildScriptHash) return + + println("Build script update available! Check https://github.com/SinTh0r4s/ExampleMod1.7.10/blob/main/build.gradle") } } checkForUpdate() From 8339f70ccbd70674d623405e3bbda6ccb4b8e4bf Mon Sep 17 00:00:00 2001 From: GitHub CI Bot <> Date: Sun, 14 Nov 2021 19:39:21 +0000 Subject: [PATCH 36/45] [ci skip] update build script version to 04059a9fcbe502f677c7e2e757f97699da5f049f --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index d65fd67..adc7c43 100644 --- a/build.gradle +++ b/build.gradle @@ -1,4 +1,4 @@ -//version: 87f95561f0b7146863678eb239280ac829d1de0a +//version: 04059a9fcbe502f677c7e2e757f97699da5f049f /* DO NOT CHANGE THIS FILE! From 68c6e70f7cdb392fc3a5c130029320674b848050 Mon Sep 17 00:00:00 2001 From: Telan <13066272+TheElan@users.noreply.github.com> Date: Sun, 14 Nov 2021 21:41:53 +0200 Subject: [PATCH 37/45] ci: only perform build script maintenance on main branches to avoid conflicts Merge commits will have buildscript changes anyways, and with this active on all branches it will be inconvenient and require pulling things after push, so you won't get in conflict with bot update --- .github/workflows/buildscript-maintenance.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/buildscript-maintenance.yml b/.github/workflows/buildscript-maintenance.yml index d7ea0cd..f5128e3 100644 --- a/.github/workflows/buildscript-maintenance.yml +++ b/.github/workflows/buildscript-maintenance.yml @@ -2,7 +2,9 @@ name: Buildscript maintenance -on: [push] +on: + push: + branches: [ master, main ] jobs: buildscript-maintenance: From 8ccd388ae01ffd5cc64ed91a86338ddca9503302 Mon Sep 17 00:00:00 2001 From: Johann Bernhardt Date: Mon, 15 Nov 2021 01:05:30 +0100 Subject: [PATCH 38/45] Implement gradle update task --- build.gradle | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/build.gradle b/build.gradle index adc7c43..ae7c36a 100644 --- a/build.gradle +++ b/build.gradle @@ -61,7 +61,7 @@ static String getVersionHash(String buildScriptContent) { return "" } -static def checkForUpdate() { +static boolean checkForUpdate() { Thread.start { Map parameters = ["connectTimeout": 2000, "readTimeout": 2000] @@ -71,12 +71,16 @@ static def checkForUpdate() { String availableBuildScript = new URL("https://raw.githubusercontent.com/SinTh0r4s/ExampleMod1.7.10/main/build.gradle").newInputStream(parameters).getText() String availableBuildScriptHash = getVersionHash(availableBuildScript) - if (currentBuildScriptHash.empty || availableBuildScriptHash.empty || currentBuildScriptHash == availableBuildScriptHash) return - println("Build script update available! Check https://github.com/SinTh0r4s/ExampleMod1.7.10/blob/main/build.gradle") + if (currentBuildScriptHash.empty || availableBuildScriptHash.empty || currentBuildScriptHash == availableBuildScriptHash) + return false + + return true } } -checkForUpdate() +if(checkForUpdate()) { + println("Build script update available! Run 'gradle updateGTNHBuildScript'") +} def checkPropertyExsists(String propertyName) { if (project.hasProperty(propertyName) == false) { @@ -154,6 +158,21 @@ configurations.all { System.setProperty("org.gradle.internal.http.socketTimeout", 120000 as String) } +task updateGTNHBuildScript { + doLast { + if (checkForUpdate()) { + def f = new File("build.gradle") + new URL("https://raw.githubusercontent.com/SinTh0r4s/ExampleMod1.7.10/main/build.gradle") + .withInputStream { i -> f.withOutputStream { it << i } } + } + } +} + +configure(updateGTNHBuildScript) { + group = 'forgegradle' + description = 'Updates the build script to the latest version' +} + // Fix Jenkins' Git: chmod a file should not be detected as a change and append a '.dirty' to the version 'git config core.fileMode false'.execute() // Pulls version from git tag From a95cf8673e32affea2f0b3449e8bd98de81bebd3 Mon Sep 17 00:00:00 2001 From: Johann Bernhardt Date: Mon, 15 Nov 2021 19:56:34 +0100 Subject: [PATCH 39/45] Small refactors --- build.gradle | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/build.gradle b/build.gradle index ae7c36a..a430ce3 100644 --- a/build.gradle +++ b/build.gradle @@ -61,7 +61,7 @@ static String getVersionHash(String buildScriptContent) { return "" } -static boolean checkForUpdate() { +static boolean isNewBuildScriptVersionAvailable() { Thread.start { Map parameters = ["connectTimeout": 2000, "readTimeout": 2000] @@ -70,16 +70,14 @@ static boolean checkForUpdate() { String availableBuildScript = new URL("https://raw.githubusercontent.com/SinTh0r4s/ExampleMod1.7.10/main/build.gradle").newInputStream(parameters).getText() String availableBuildScriptHash = getVersionHash(availableBuildScript) - - if (currentBuildScriptHash.empty || availableBuildScriptHash.empty || currentBuildScriptHash == availableBuildScriptHash) - return false - return true + boolean isUpToDate = currentBuildScriptHash.empty || availableBuildScriptHash.empty || currentBuildScriptHash == availableBuildScriptHash + return !isUpToDate } } -if(checkForUpdate()) { - println("Build script update available! Run 'gradle updateGTNHBuildScript'") +if(isNewBuildScriptVersionAvailable()) { + println("Build script update available! Run 'gradle updateBuildScript'") } def checkPropertyExsists(String propertyName) { @@ -158,17 +156,18 @@ configurations.all { System.setProperty("org.gradle.internal.http.socketTimeout", 120000 as String) } -task updateGTNHBuildScript { +task updateBuildScript { doLast { - if (checkForUpdate()) { - def f = new File("build.gradle") + if (isNewBuildScriptVersionAvailable()) { + def builscriptFile = new File("build.gradle") new URL("https://raw.githubusercontent.com/SinTh0r4s/ExampleMod1.7.10/main/build.gradle") - .withInputStream { i -> f.withOutputStream { it << i } } + .withInputStream { i -> builscriptFile.withOutputStream { it << i } } + print("Build script updated. Please REIMPORT the project or RESTART your IDE!") } } } -configure(updateGTNHBuildScript) { +configure(updateBuildScript) { group = 'forgegradle' description = 'Updates the build script to the latest version' } From 9d532e92a00de88d30adb06c1e283be090867d2f Mon Sep 17 00:00:00 2001 From: Johann Bernhardt Date: Mon, 15 Nov 2021 20:11:59 +0100 Subject: [PATCH 40/45] Add automatic update option --- build.gradle | 98 +++++++++++++++++++++++++++-------------------- gradle.properties | 3 ++ 2 files changed, 59 insertions(+), 42 deletions(-) diff --git a/build.gradle b/build.gradle index a430ce3..5025472 100644 --- a/build.gradle +++ b/build.gradle @@ -49,46 +49,10 @@ idea { } -if(JavaVersion.current() != JavaVersion.VERSION_1_8) { - throw new GradleException("This project requires Java 8, but it's running on " + JavaVersion.current()) -} - -static String getVersionHash(String buildScriptContent) { - String versionLine = buildScriptContent.find("^//version: [a-z0-9]*") - if(versionLine != null) { - return versionLine.split(": ").last() - } - return "" -} - -static boolean isNewBuildScriptVersionAvailable() { - Thread.start { - Map parameters = ["connectTimeout": 2000, "readTimeout": 2000] - - String currentBuildScript = new File("build.gradle").getText() - String currentBuildScriptHash = getVersionHash(currentBuildScript) - - String availableBuildScript = new URL("https://raw.githubusercontent.com/SinTh0r4s/ExampleMod1.7.10/main/build.gradle").newInputStream(parameters).getText() - String availableBuildScriptHash = getVersionHash(availableBuildScript) - - - boolean isUpToDate = currentBuildScriptHash.empty || availableBuildScriptHash.empty || currentBuildScriptHash == availableBuildScriptHash - return !isUpToDate - } -} -if(isNewBuildScriptVersionAvailable()) { - println("Build script update available! Run 'gradle updateBuildScript'") -} - -def checkPropertyExsists(String propertyName) { - if (project.hasProperty(propertyName) == false) { - throw new GradleException("This project requires a property \"" + propertyName + "\"! Please add it your \"gradle.properties\". You can find all properties and their description here: https://github.com/SinTh0r4s/ExampleMod1.7.10/blob/main/gradle.properties") - } -} - checkPropertyExsists("modName") checkPropertyExsists("modId") checkPropertyExsists("modGroup") +checkPropertyExsists("autoUpdateBuildScript") checkPropertyExsists("minecraftVersion") checkPropertyExsists("forgeVersion") checkPropertyExsists("replaceGradleTokenInFile") @@ -106,6 +70,59 @@ checkPropertyExsists("containsMixinsAndOrCoreModOnly") checkPropertyExsists("usesShadowedDependencies") checkPropertyExsists("developmentEnvironmentUserName") +if(JavaVersion.current() != JavaVersion.VERSION_1_8) { + throw new GradleException("This project requires Java 8, but it's running on " + JavaVersion.current()) +} + +static String getVersionHash(String buildScriptContent) { + String versionLine = buildScriptContent.find("^//version: [a-z0-9]*") + if(versionLine != null) { + return versionLine.split(": ").last() + } + return "" +} + +static boolean isNewBuildScriptVersionAvailable() { + Map parameters = ["connectTimeout": 2000, "readTimeout": 2000] + + String currentBuildScript = new File("build.gradle").getText() + String currentBuildScriptHash = getVersionHash(currentBuildScript) + + String availableBuildScript = new URL("https://raw.githubusercontent.com/SinTh0r4s/ExampleMod1.7.10/main/build.gradle").newInputStream(parameters).getText() + String availableBuildScriptHash = getVersionHash(availableBuildScript) + + + boolean isUpToDate = currentBuildScriptHash.empty || availableBuildScriptHash.empty || currentBuildScriptHash == availableBuildScriptHash + return !isUpToDate +} + +static boolean updateBuildScript() { + if (isNewBuildScriptVersionAvailable()) { + def builscriptFile = new File("build.gradle") + new URL("https://raw.githubusercontent.com/SinTh0r4s/ExampleMod1.7.10/main/build.gradle") + .withInputStream { i -> builscriptFile.withOutputStream { it << i } } + print("Build script updated. Please REIMPORT the project or RESTART your IDE!") + return true + } + return false +} + +Thread.start { + if (isNewBuildScriptVersionAvailable()) { + if (autoUpdateBuildScript.toBoolean()) { + updateBuildScript() + } else { + println("Build script update available! Run 'gradle updateBuildScript'") + } + } +} + +def checkPropertyExsists(String propertyName) { + if (project.hasProperty(propertyName) == false) { + throw new GradleException("This project requires a property \"" + propertyName + "\"! Please add it your \"gradle.properties\". You can find all properties and their description here: https://github.com/SinTh0r4s/ExampleMod1.7.10/blob/main/gradle.properties") + } +} + String targetPackage = "src/main/java/" + modGroup.toString().replaceAll("\\.", "/") if(new File(targetPackage).exists() == false) { throw new GradleException("Could not resolve \"modGroup\"! Could not find " + targetPackage) @@ -158,11 +175,8 @@ configurations.all { task updateBuildScript { doLast { - if (isNewBuildScriptVersionAvailable()) { - def builscriptFile = new File("build.gradle") - new URL("https://raw.githubusercontent.com/SinTh0r4s/ExampleMod1.7.10/main/build.gradle") - .withInputStream { i -> builscriptFile.withOutputStream { it << i } } - print("Build script updated. Please REIMPORT the project or RESTART your IDE!") + if (updateBuildScript() == false) { + print("Build script already up-to-date!") } } } diff --git a/gradle.properties b/gradle.properties index dd65ba2..ad54993 100644 --- a/gradle.properties +++ b/gradle.properties @@ -9,6 +9,9 @@ modGroup = com.myname.mymodid # The build script relies on git to provide a version via tags. It is super easy and will enable you to always know the # code base or your binary. Check out this tutorial: https://blog.mattclemente.com/2017/10/13/versioning-with-git-tags/ +# Will update your build.gradle automatically whenever an update is available +autoUpdateBuildScript = false + minecraftVersion = 1.7.10 forgeVersion = 10.13.4.1614 From a9493e87829de89fb008613447b684273940e9c9 Mon Sep 17 00:00:00 2001 From: Johann Bernhardt Date: Mon, 15 Nov 2021 20:15:38 +0100 Subject: [PATCH 41/45] Add addon.gradle support to migration tutorial --- docs/migration.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/migration.md b/docs/migration.md index c8c9bd7..b01d544 100644 --- a/docs/migration.md +++ b/docs/migration.md @@ -8,7 +8,7 @@ If they are missing in this document - we will gladly receive your suggestions/c 1. Copy and replace all files from [template](https://github.com/SinTh0r4s/ExampleMod1.7.10/releases/download/latest-migration/migration.zip) to your repository, but `build.gradle` 2. Copy all repositories from your `build.gradle(.kts)` to `repositories.gradle` 3. Copy all dependencies from your `build.gradle(.kts)` to `dependecies.gradle` -4. replace your `build.gradle(.kts)` with `build.gradle` from template. In case you have written some custom tasks/configurations not present in the template - move them to separate file and link it in this, like for example it does this with `dependencies.gradle` +4. replace your `build.gradle(.kts)` with `build.gradle` from template. In case you have written some custom tasks/configurations not present in the template - move them into `addon.gradle`. It will automatically be integrated if present. 5. Adapt `gradle.properties` to your mod 6. Ensure `src/main/resources/mcmod.info` contains `${modId}`, `${modName}`. `${modVersion}` and `${minecraftVersion}` 7. Re-import the project to your IDE (e.g. restart with clean caches in IntelliJ IDEA) From 675d43898b712cfe1f3c1f47d4d59ca0c73894d4 Mon Sep 17 00:00:00 2001 From: Telan <13066272+TheElan@users.noreply.github.com> Date: Mon, 15 Nov 2021 22:16:12 +0200 Subject: [PATCH 42/45] buildscript: move update to the bottom of the script so it is evaluated last; update gradle and forge gradle plugin to use new toolchain feature --- build.gradle | 172 +++++++++++++---------- gradle/wrapper/gradle-wrapper.properties | 2 +- 2 files changed, 95 insertions(+), 79 deletions(-) diff --git a/build.gradle b/build.gradle index 5025472..606cb38 100644 --- a/build.gradle +++ b/build.gradle @@ -27,7 +27,7 @@ buildscript { } } dependencies { - classpath 'com.github.GTNH2:ForgeGradle:FG_1.2-SNAPSHOT' + classpath 'com.github.TheElan:ForgeGradle:8816f1d388' } } @@ -49,75 +49,48 @@ idea { } -checkPropertyExsists("modName") -checkPropertyExsists("modId") -checkPropertyExsists("modGroup") -checkPropertyExsists("autoUpdateBuildScript") -checkPropertyExsists("minecraftVersion") -checkPropertyExsists("forgeVersion") -checkPropertyExsists("replaceGradleTokenInFile") -checkPropertyExsists("gradleTokenModId") -checkPropertyExsists("gradleTokenModName") -checkPropertyExsists("gradleTokenVersion") -checkPropertyExsists("gradleTokenGroupName") -checkPropertyExsists("apiPackage") -checkPropertyExsists("accessTransformersFile") -checkPropertyExsists("usesMixins") -checkPropertyExsists("mixinPlugin") -checkPropertyExsists("mixinsPackage") -checkPropertyExsists("coreModClass") -checkPropertyExsists("containsMixinsAndOrCoreModOnly") -checkPropertyExsists("usesShadowedDependencies") -checkPropertyExsists("developmentEnvironmentUserName") +static boolean checkForUpdate() { + Thread.start { + Map parameters = ["connectTimeout": 2000, "readTimeout": 2000] + + String currentBuildScript = new File("build.gradle").getText() + String currentBuildScriptHash = getVersionHash(currentBuildScript) + + String availableBuildScript = new URL("https://raw.githubusercontent.com/SinTh0r4s/ExampleMod1.7.10/main/build.gradle").newInputStream(parameters).getText() + String availableBuildScriptHash = getVersionHash(availableBuildScript) + + if (currentBuildScriptHash.empty || availableBuildScriptHash.empty || currentBuildScriptHash == availableBuildScriptHash) + return false -if(JavaVersion.current() != JavaVersion.VERSION_1_8) { - throw new GradleException("This project requires Java 8, but it's running on " + JavaVersion.current()) -} - -static String getVersionHash(String buildScriptContent) { - String versionLine = buildScriptContent.find("^//version: [a-z0-9]*") - if(versionLine != null) { - return versionLine.split(": ").last() - } - return "" -} - -static boolean isNewBuildScriptVersionAvailable() { - Map parameters = ["connectTimeout": 2000, "readTimeout": 2000] - - String currentBuildScript = new File("build.gradle").getText() - String currentBuildScriptHash = getVersionHash(currentBuildScript) - - String availableBuildScript = new URL("https://raw.githubusercontent.com/SinTh0r4s/ExampleMod1.7.10/main/build.gradle").newInputStream(parameters).getText() - String availableBuildScriptHash = getVersionHash(availableBuildScript) - - - boolean isUpToDate = currentBuildScriptHash.empty || availableBuildScriptHash.empty || currentBuildScriptHash == availableBuildScriptHash - return !isUpToDate -} - -static boolean updateBuildScript() { - if (isNewBuildScriptVersionAvailable()) { - def builscriptFile = new File("build.gradle") - new URL("https://raw.githubusercontent.com/SinTh0r4s/ExampleMod1.7.10/main/build.gradle") - .withInputStream { i -> builscriptFile.withOutputStream { it << i } } - print("Build script updated. Please REIMPORT the project or RESTART your IDE!") return true } - return false +} +if(checkForUpdate()) { + println("Build script update available! Run 'gradle updateGTNHBuildScript'") } -Thread.start { - if (isNewBuildScriptVersionAvailable()) { - if (autoUpdateBuildScript.toBoolean()) { - updateBuildScript() - } else { - println("Build script update available! Run 'gradle updateBuildScript'") - } - } -} +checkPropertyExists("modName") +checkPropertyExists("modId") +checkPropertyExists("modGroup") +checkPropertyExists("autoUpdateBuildScript") +checkPropertyExists("minecraftVersion") +checkPropertyExists("forgeVersion") +checkPropertyExists("replaceGradleTokenInFile") +checkPropertyExists("gradleTokenModId") +checkPropertyExists("gradleTokenModName") +checkPropertyExists("gradleTokenVersion") +checkPropertyExists("gradleTokenGroupName") +checkPropertyExists("apiPackage") +checkPropertyExists("accessTransformersFile") +checkPropertyExists("usesMixins") +checkPropertyExists("mixinPlugin") +checkPropertyExists("mixinsPackage") +checkPropertyExists("coreModClass") +checkPropertyExists("containsMixinsAndOrCoreModOnly") +checkPropertyExists("usesShadowedDependencies") +checkPropertyExists("developmentEnvironmentUserName") -def checkPropertyExsists(String propertyName) { +def checkPropertyExists(String propertyName) { if (project.hasProperty(propertyName) == false) { throw new GradleException("This project requires a property \"" + propertyName + "\"! Please add it your \"gradle.properties\". You can find all properties and their description here: https://github.com/SinTh0r4s/ExampleMod1.7.10/blob/main/gradle.properties") } @@ -173,19 +146,6 @@ configurations.all { System.setProperty("org.gradle.internal.http.socketTimeout", 120000 as String) } -task updateBuildScript { - doLast { - if (updateBuildScript() == false) { - print("Build script already up-to-date!") - } - } -} - -configure(updateBuildScript) { - group = 'forgegradle' - description = 'Updates the build script to the latest version' -} - // Fix Jenkins' Git: chmod a file should not be detected as a change and append a '.dirty' to the version 'git config core.fileMode false'.execute() // Pulls version from git tag @@ -500,7 +460,6 @@ task apiJar(type: Jar) { getArchiveClassifier().set('api') } - artifacts { archives sourcesJar archives devJar @@ -508,3 +467,60 @@ artifacts { archives apiJar } } + +// Updating +task updateBuildScript { + doLast { + if (updateBuildScript()) return + + print("Build script already up-to-date!") + } +} + +Thread.start { + if (isNewBuildScriptVersionAvailable()) { + if (autoUpdateBuildScript.toBoolean()) { + updateBuildScript() + } else { + println("Build script update available! Run 'gradle updateBuildScript'") + } + } +} + +static boolean updateBuildScript() { + if (isNewBuildScriptVersionAvailable()) { + def buildscriptFile = new File("build.gradle") + new URL("https://raw.githubusercontent.com/SinTh0r4s/ExampleMod1.7.10/main/build.gradle") + .withInputStream { i -> buildscriptFile.withOutputStream { it << i } } + print("Build script updated. Please REIMPORT the project or RESTART your IDE!") + return true + } + return false +} + +static boolean isNewBuildScriptVersionAvailable() { + Map parameters = ["connectTimeout": 2000, "readTimeout": 2000] + + String currentBuildScript = new File("build.gradle").getText() + String currentBuildScriptHash = getVersionHash(currentBuildScript) + + String availableBuildScript = new URL("https://raw.githubusercontent.com/SinTh0r4s/ExampleMod1.7.10/main/build.gradle").newInputStream(parameters).getText() + String availableBuildScriptHash = getVersionHash(availableBuildScript) + + + boolean isUpToDate = currentBuildScriptHash.empty || availableBuildScriptHash.empty || currentBuildScriptHash == availableBuildScriptHash + return !isUpToDate +} + +static String getVersionHash(String buildScriptContent) { + String versionLine = buildScriptContent.find("^//version: [a-z0-9]*") + if(versionLine != null) { + return versionLine.split(": ").last() + } + return "" +} + +configure(updateBuildScript) { + group = 'forgegradle' + description = 'Updates the build script to the latest version' +} diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 5028f28..3ab0b72 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.4-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-6.9.1-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists From b5400c40ac06b975e712f3c564bf531edcef2822 Mon Sep 17 00:00:00 2001 From: Telan <13066272+TheElan@users.noreply.github.com> Date: Mon, 15 Nov 2021 22:19:27 +0200 Subject: [PATCH 43/45] buildscript: remove leftovers after resolving conflicts --- build.gradle | 21 --------------------- 1 file changed, 21 deletions(-) diff --git a/build.gradle b/build.gradle index 606cb38..56458da 100644 --- a/build.gradle +++ b/build.gradle @@ -48,27 +48,6 @@ idea { } } - -static boolean checkForUpdate() { - Thread.start { - Map parameters = ["connectTimeout": 2000, "readTimeout": 2000] - - String currentBuildScript = new File("build.gradle").getText() - String currentBuildScriptHash = getVersionHash(currentBuildScript) - - String availableBuildScript = new URL("https://raw.githubusercontent.com/SinTh0r4s/ExampleMod1.7.10/main/build.gradle").newInputStream(parameters).getText() - String availableBuildScriptHash = getVersionHash(availableBuildScript) - - if (currentBuildScriptHash.empty || availableBuildScriptHash.empty || currentBuildScriptHash == availableBuildScriptHash) - return false - - return true - } -} -if(checkForUpdate()) { - println("Build script update available! Run 'gradle updateGTNHBuildScript'") -} - checkPropertyExists("modName") checkPropertyExists("modId") checkPropertyExists("modGroup") From b9ca6e418244c503579ebb5ced67eb98360546ed Mon Sep 17 00:00:00 2001 From: Telan <13066272+TheElan@users.noreply.github.com> Date: Mon, 15 Nov 2021 22:33:01 +0200 Subject: [PATCH 44/45] buildscript: remove thread from version check to avoid it being killed withouth finishing --- build.gradle | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/build.gradle b/build.gradle index 56458da..8c5f965 100644 --- a/build.gradle +++ b/build.gradle @@ -456,21 +456,22 @@ task updateBuildScript { } } -Thread.start { - if (isNewBuildScriptVersionAvailable()) { - if (autoUpdateBuildScript.toBoolean()) { - updateBuildScript() - } else { - println("Build script update available! Run 'gradle updateBuildScript'") - } +if (isNewBuildScriptVersionAvailable()) { + if (autoUpdateBuildScript.toBoolean()) { + updateBuildScript() + } else { + println("Build script update available! Run 'gradle updateBuildScript'") } } +static URL availableBuildScriptUrl() { + new URL("https://raw.githubusercontent.com/SinTh0r4s/ExampleMod1.7.10/main/build.gradle") +} + static boolean updateBuildScript() { if (isNewBuildScriptVersionAvailable()) { def buildscriptFile = new File("build.gradle") - new URL("https://raw.githubusercontent.com/SinTh0r4s/ExampleMod1.7.10/main/build.gradle") - .withInputStream { i -> buildscriptFile.withOutputStream { it << i } } + availableBuildScriptUrl().withInputStream { i -> buildscriptFile.withOutputStream { it << i } } print("Build script updated. Please REIMPORT the project or RESTART your IDE!") return true } @@ -482,10 +483,10 @@ static boolean isNewBuildScriptVersionAvailable() { String currentBuildScript = new File("build.gradle").getText() String currentBuildScriptHash = getVersionHash(currentBuildScript) - - String availableBuildScript = new URL("https://raw.githubusercontent.com/SinTh0r4s/ExampleMod1.7.10/main/build.gradle").newInputStream(parameters).getText() + println "current: $currentBuildScriptHash" + String availableBuildScript = availableBuildScriptUrl().newInputStream(parameters).getText() String availableBuildScriptHash = getVersionHash(availableBuildScript) - + println "available: $availableBuildScriptHash" boolean isUpToDate = currentBuildScriptHash.empty || availableBuildScriptHash.empty || currentBuildScriptHash == availableBuildScriptHash return !isUpToDate From b247541980e1e6ee4d2e4c5a08a8afd7b6a25be5 Mon Sep 17 00:00:00 2001 From: Johann Bernhardt Date: Mon, 15 Nov 2021 21:59:30 +0100 Subject: [PATCH 45/45] remove debug prints --- build.gradle | 2 -- 1 file changed, 2 deletions(-) diff --git a/build.gradle b/build.gradle index 8c5f965..03a2929 100644 --- a/build.gradle +++ b/build.gradle @@ -483,10 +483,8 @@ static boolean isNewBuildScriptVersionAvailable() { String currentBuildScript = new File("build.gradle").getText() String currentBuildScriptHash = getVersionHash(currentBuildScript) - println "current: $currentBuildScriptHash" String availableBuildScript = availableBuildScriptUrl().newInputStream(parameters).getText() String availableBuildScriptHash = getVersionHash(availableBuildScript) - println "available: $availableBuildScriptHash" boolean isUpToDate = currentBuildScriptHash.empty || availableBuildScriptHash.empty || currentBuildScriptHash == availableBuildScriptHash return !isUpToDate