From ba64366c7076ef6034cb5984964436af95674a6d Mon Sep 17 00:00:00 2001 From: FrostBird347 <39435218+FrostBird347@users.noreply.github.com> Date: Sat, 31 Jan 2026 16:08:54 +0800 Subject: [PATCH 1/8] Add dynamic project renaming Code based on https://github.com/rochacbruno/python-project-template --- .github/rename_project.sh | 46 ++++++++++++++++++++++ .github/template.yml | 1 + .github/workflows/rename_project.yml | 57 ++++++++++++++++++++++++++++ README.md | 4 +- mod/modinfo.json | 2 +- 5 files changed, 108 insertions(+), 2 deletions(-) create mode 100755 .github/rename_project.sh create mode 100644 .github/template.yml create mode 100755 .github/workflows/rename_project.yml diff --git a/.github/rename_project.sh b/.github/rename_project.sh new file mode 100755 index 0000000..f261173 --- /dev/null +++ b/.github/rename_project.sh @@ -0,0 +1,46 @@ +#!/usr/bin/env bash +while getopts a:n:u:d: flag +do + case "${flag}" in + a) author=${OPTARG};; + n) display_name=${OPTARG};; + u) urlname=${OPTARG};; + d) description=${OPTARG};; + esac +done + +code_name="$(echo "$display_name" | sed -r 's/.*/\L&/;s/(^| )([a-z])/\U\2/g')" +mod_id="$(echo "com.${author}.${code_name}" | sed -r 's/.*/\L&/')" + +echo "Author: $author"; +echo "Display Name: $display_name"; +echo "Description: $description"; +echo "Code Name: $code_name"; +echo "Mod ID: $mod_id"; + +echo "Renaming project..." + +original_author="Author" +original_code_name="TestMod" +original_mod_id="com.author.testmod" +original_display_name="Test Mod" +original_description="Put a neat description here" + +for filename in $(git ls-files) +do + if [[ "$filename" != lib/* && "$filename" != .github/* ]] + then + sed -i "s/$original_author/$author/g" $filename + sed -i "s/$original_code_name/$code_name/g" $filename + sed -i "s/$original_mod_id/$mod_id/g" $filename + sed -i "s/$original_display_name/$display_name/g" $filename + sed -i "s/$original_description/$description/g" $filename + sed -i "s/ / /g" $filename + echo "Renamed $filename" + fi +done + +mv src/TestMod.csproj "src/${code_name}.csproj" + +# This command runs only once on GHA! +rm -f .github/template.yml diff --git a/.github/template.yml b/.github/template.yml new file mode 100644 index 0000000..ff1c08e --- /dev/null +++ b/.github/template.yml @@ -0,0 +1 @@ +author: FrostBird347 diff --git a/.github/workflows/rename_project.yml b/.github/workflows/rename_project.yml new file mode 100755 index 0000000..b33b292 --- /dev/null +++ b/.github/workflows/rename_project.yml @@ -0,0 +1,57 @@ +name: Rename the project from template + +on: [push] + +permissions: write-all + +jobs: + rename-project: + if: ${{ !contains (github.repository, '/RWModTemplate') }} + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + with: + # by default, it uses a depth of 1 + # this fetches all history so that we can read each commit + fetch-depth: 0 + ref: ${{ github.head_ref }} + + - run: echo "REPOSITORY_NAME=$(echo '${{ github.repository }}' | awk -F '/' '{print $2}' | tr '-' ' ')" >> $GITHUB_ENV + shell: bash + + - run: echo "REPOSITORY_URLNAME=$(echo '${{ github.repository }}' | awk -F '/' '{print $2}')" >> $GITHUB_ENV + shell: bash + + - run: echo "REPOSITORY_OWNER=$(echo '${{ github.repository }}' | awk -F '/' '{print $1}')" >> $GITHUB_ENV + shell: bash + + - name: Get repository description + uses: actions/github-script@v6 + id: get_description + with: + script: | + const response = await github.rest.repos.get({ + owner: context.repo.owner, + repo: context.repo.repo, + }); + return response.data.description; + result-encoding: string + + - run: echo "REPOSITORY_DESCRIPTION=$(echo '${{ steps.get_description.outputs.result }}')" >> $GITHUB_ENV + shell: bash + + - name: Is this still a template + id: is_template + run: echo "::set-output name=is_template::$(ls .github/template.yml &> /dev/null && echo true || echo false)" + + - name: Rename the project + if: steps.is_template.outputs.is_template == 'true' + run: | + echo "Renaming the project with -a(author) ${{ env.REPOSITORY_OWNER }} -n(name) ${{ env.REPOSITORY_NAME }} -u(urlname) ${{ env.REPOSITORY_URLNAME }}" + .github/rename_project.sh -a ${{ env.REPOSITORY_OWNER }} -n "${{ env.REPOSITORY_NAME }}" -u ${{ env.REPOSITORY_URLNAME }} -d "${{ env.REPOSITORY_DESCRIPTION }}" + + - uses: stefanzweifel/git-auto-commit-action@v4 + with: + commit_message: "Applied template changes." + # commit_options: '--amend --no-edit' + push_options: --force diff --git a/README.md b/README.md index 8d6f4aa..6ac825e 100644 --- a/README.md +++ b/README.md @@ -3,6 +3,8 @@ ## Usage Use this template on GitHub or just [download the code](https://github.com/alduris/TemplateMod/archive/refs/heads/master.zip), whichever is easiest. +If you chose the latter it's recommended you delete `.github/template.yml`. + Rename `src/TestMod.csproj`, then edit `mod/modinfo.json` and `src/Plugin.cs` to customize your mod. See [the modding wiki](https://rainworldmodding.miraheze.org/wiki/Mod_Directories) for `modinfo.json` documentation. @@ -21,4 +23,4 @@ In a nutshell, this means: You do not have to license your code under CC0 though! (Though it would be cool if you did.) Feel free to license your code however you wish, or not at all. -**DISCLAIMER**: Any and all reference .dll files included (in the `lib` folder) are NOT covered under CC0! They are protected by copyright under their original owners. The actual code in the .dll files has been stripped so they serve no purpose other than for compiler reference (hopefully alleviating most legal issues this would otherwise cause), but this is expected to be upheld by you, the person using this template! Any reference .dlls you may add should be stripped before pushing to any public repository! And if it is possible to get code from Nuget instead, I recommend you do that instead of adding the dll here. \ No newline at end of file +**DISCLAIMER**: Any and all reference .dll files included (in the `lib` folder) are NOT covered under CC0! They are protected by copyright under their original owners. The actual code in the .dll files has been stripped so they serve no purpose other than for compiler reference (hopefully alleviating most legal issues this would otherwise cause), but this is expected to be upheld by you, the person using this template! Any reference .dlls you may add should be stripped before pushing to any public repository! And if it is possible to get code from Nuget instead, I recommend you do that instead of adding the dll here. diff --git a/mod/modinfo.json b/mod/modinfo.json index cef04f1..80959e9 100644 --- a/mod/modinfo.json +++ b/mod/modinfo.json @@ -1,5 +1,5 @@ { - "id": "testmod", + "id": "com.author.testmod", "name": "Test Mod", "version": "0.1.0", "authors": "Author", From 7195b0fc717a05ffa0cafa5ee6a26411dc55f6e9 Mon Sep 17 00:00:00 2001 From: FrostBird347 <39435218+FrostBird347@users.noreply.github.com> Date: Sat, 31 Jan 2026 17:22:57 +0800 Subject: [PATCH 2/8] Final pull request preparations --- .github/rename_project.sh | 2 +- .github/template.yml | 2 +- .github/workflows/rename_project.yml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/rename_project.sh b/.github/rename_project.sh index f261173..aeed17c 100755 --- a/.github/rename_project.sh +++ b/.github/rename_project.sh @@ -35,7 +35,7 @@ do sed -i "s/$original_mod_id/$mod_id/g" $filename sed -i "s/$original_display_name/$display_name/g" $filename sed -i "s/$original_description/$description/g" $filename - sed -i "s/ / /g" $filename + #sed -i "s/ / /g" $filename echo "Renamed $filename" fi done diff --git a/.github/template.yml b/.github/template.yml index ff1c08e..8c4a167 100644 --- a/.github/template.yml +++ b/.github/template.yml @@ -1 +1 @@ -author: FrostBird347 +author: alduris diff --git a/.github/workflows/rename_project.yml b/.github/workflows/rename_project.yml index b33b292..f22054f 100755 --- a/.github/workflows/rename_project.yml +++ b/.github/workflows/rename_project.yml @@ -6,7 +6,7 @@ permissions: write-all jobs: rename-project: - if: ${{ !contains (github.repository, '/RWModTemplate') }} + if: ${{ !contains (github.repository, '/TemplateMod') }} runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 From 99caea0b9ff7bed081786c1ad3f71e3a28e33679 Mon Sep 17 00:00:00 2001 From: FrostBird347 <39435218+FrostBird347@users.noreply.github.com> Date: Sat, 31 Jan 2026 17:27:50 +0800 Subject: [PATCH 3/8] Fix typo --- .github/workflows/rename_project.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/rename_project.yml b/.github/workflows/rename_project.yml index f22054f..9dadf2c 100755 --- a/.github/workflows/rename_project.yml +++ b/.github/workflows/rename_project.yml @@ -37,7 +37,7 @@ jobs: return response.data.description; result-encoding: string - - run: echo "REPOSITORY_DESCRIPTION=$(echo '${{ steps.get_description.outputs.result }}')" >> $GITHUB_ENV + - run: echo "REPOSITORY_DESCRIPTION=$(echo "${{steps.get_description.outputs.result}}")" >> $GITHUB_ENV shell: bash - name: Is this still a template From 4774a13b3dcf6b150d114c13ca6e106b597edf09 Mon Sep 17 00:00:00 2001 From: FrostBird347 <39435218+FrostBird347@users.noreply.github.com> Date: Sat, 31 Jan 2026 17:42:48 +0800 Subject: [PATCH 4/8] Attempt to prevent action from being run on forks --- .github/workflows/rename_project.yml | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/.github/workflows/rename_project.yml b/.github/workflows/rename_project.yml index 9dadf2c..ff064bc 100755 --- a/.github/workflows/rename_project.yml +++ b/.github/workflows/rename_project.yml @@ -15,7 +15,7 @@ jobs: # this fetches all history so that we can read each commit fetch-depth: 0 ref: ${{ github.head_ref }} - + - run: echo "REPOSITORY_NAME=$(echo '${{ github.repository }}' | awk -F '/' '{print $2}' | tr '-' ' ')" >> $GITHUB_ENV shell: bash @@ -25,31 +25,31 @@ jobs: - run: echo "REPOSITORY_OWNER=$(echo '${{ github.repository }}' | awk -F '/' '{print $1}')" >> $GITHUB_ENV shell: bash - - name: Get repository description + - name: Get repository description and fork status uses: actions/github-script@v6 - id: get_description + id: get_info with: script: | const response = await github.rest.repos.get({ owner: context.repo.owner, repo: context.repo.repo, }); - return response.data.description; - result-encoding: string + return {"description": response.data.description, "isFork": response.data.fork}; + result-encoding: json - - run: echo "REPOSITORY_DESCRIPTION=$(echo "${{steps.get_description.outputs.result}}")" >> $GITHUB_ENV + - run: echo "REPOSITORY_DESCRIPTION=$(echo "${{fromJson(steps.get_info.outputs.result).description}}")" >> $GITHUB_ENV shell: bash - + - name: Is this still a template id: is_template run: echo "::set-output name=is_template::$(ls .github/template.yml &> /dev/null && echo true || echo false)" - name: Rename the project - if: steps.is_template.outputs.is_template == 'true' + if: steps.is_template.outputs.is_template == 'true' && !fromJson(steps.get_info.outputs.result).isFork run: | echo "Renaming the project with -a(author) ${{ env.REPOSITORY_OWNER }} -n(name) ${{ env.REPOSITORY_NAME }} -u(urlname) ${{ env.REPOSITORY_URLNAME }}" .github/rename_project.sh -a ${{ env.REPOSITORY_OWNER }} -n "${{ env.REPOSITORY_NAME }}" -u ${{ env.REPOSITORY_URLNAME }} -d "${{ env.REPOSITORY_DESCRIPTION }}" - + - uses: stefanzweifel/git-auto-commit-action@v4 with: commit_message: "Applied template changes." From d9e5bf572e557258fd34a722481d49433f189bf2 Mon Sep 17 00:00:00 2001 From: FrostBird347 <39435218+FrostBird347@users.noreply.github.com> Date: Sat, 31 Jan 2026 18:16:17 +0800 Subject: [PATCH 5/8] Turns out running it on repo creation isn't reliable So we just delete the entire action once it's done --- .github/rename_project.sh | 2 +- .github/workflows/rename_project.yml | 6 +----- README.md | 2 +- 3 files changed, 3 insertions(+), 7 deletions(-) diff --git a/.github/rename_project.sh b/.github/rename_project.sh index aeed17c..9bfdb10 100755 --- a/.github/rename_project.sh +++ b/.github/rename_project.sh @@ -43,4 +43,4 @@ done mv src/TestMod.csproj "src/${code_name}.csproj" # This command runs only once on GHA! -rm -f .github/template.yml +rm -r .github/ diff --git a/.github/workflows/rename_project.yml b/.github/workflows/rename_project.yml index ff064bc..d8d6ee9 100755 --- a/.github/workflows/rename_project.yml +++ b/.github/workflows/rename_project.yml @@ -40,12 +40,8 @@ jobs: - run: echo "REPOSITORY_DESCRIPTION=$(echo "${{fromJson(steps.get_info.outputs.result).description}}")" >> $GITHUB_ENV shell: bash - - name: Is this still a template - id: is_template - run: echo "::set-output name=is_template::$(ls .github/template.yml &> /dev/null && echo true || echo false)" - - name: Rename the project - if: steps.is_template.outputs.is_template == 'true' && !fromJson(steps.get_info.outputs.result).isFork + if: !fromJson(steps.get_info.outputs.result).isFork run: | echo "Renaming the project with -a(author) ${{ env.REPOSITORY_OWNER }} -n(name) ${{ env.REPOSITORY_NAME }} -u(urlname) ${{ env.REPOSITORY_URLNAME }}" .github/rename_project.sh -a ${{ env.REPOSITORY_OWNER }} -n "${{ env.REPOSITORY_NAME }}" -u ${{ env.REPOSITORY_URLNAME }} -d "${{ env.REPOSITORY_DESCRIPTION }}" diff --git a/README.md b/README.md index 6ac825e..ef7d344 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ ## Usage Use this template on GitHub or just [download the code](https://github.com/alduris/TemplateMod/archive/refs/heads/master.zip), whichever is easiest. -If you chose the latter it's recommended you delete `.github/template.yml`. +If you chose the latter it's recommended you delete the hidden `.github` folder before uploading to github. Rename `src/TestMod.csproj`, then edit `mod/modinfo.json` and `src/Plugin.cs` to customize your mod. From 894602fe98dc47ceaa27cde9e4c2299f1e777d22 Mon Sep 17 00:00:00 2001 From: FrostBird347 <39435218+FrostBird347@users.noreply.github.com> Date: Sat, 31 Jan 2026 18:43:45 +0800 Subject: [PATCH 6/8] Fix syntax --- .github/workflows/rename_project.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/rename_project.yml b/.github/workflows/rename_project.yml index d8d6ee9..62aae78 100755 --- a/.github/workflows/rename_project.yml +++ b/.github/workflows/rename_project.yml @@ -41,7 +41,7 @@ jobs: shell: bash - name: Rename the project - if: !fromJson(steps.get_info.outputs.result).isFork + if: fromJson(steps.get_info.outputs.result).isFork != true run: | echo "Renaming the project with -a(author) ${{ env.REPOSITORY_OWNER }} -n(name) ${{ env.REPOSITORY_NAME }} -u(urlname) ${{ env.REPOSITORY_URLNAME }}" .github/rename_project.sh -a ${{ env.REPOSITORY_OWNER }} -n "${{ env.REPOSITORY_NAME }}" -u ${{ env.REPOSITORY_URLNAME }} -d "${{ env.REPOSITORY_DESCRIPTION }}" From 29e6d7e3d902a3933c72e08e9df19f386d677ead Mon Sep 17 00:00:00 2001 From: FrostBird347 <39435218+FrostBird347@users.noreply.github.com> Date: Sat, 31 Jan 2026 21:40:24 +0800 Subject: [PATCH 7/8] Remove unnecessary file --- .github/template.yml | 1 - 1 file changed, 1 deletion(-) delete mode 100644 .github/template.yml diff --git a/.github/template.yml b/.github/template.yml deleted file mode 100644 index 8c4a167..0000000 --- a/.github/template.yml +++ /dev/null @@ -1 +0,0 @@ -author: alduris From 03cbbdf11c9a62b329623c4a6c822d68e46d6cd9 Mon Sep 17 00:00:00 2001 From: FrostBird347 <39435218+FrostBird347@users.noreply.github.com> Date: Mon, 2 Feb 2026 01:10:44 +0800 Subject: [PATCH 8/8] Invert previous ID formatting decision --- .github/rename_project.sh | 4 ++-- mod/modinfo.json | 2 +- src/Plugin.cs | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/rename_project.sh b/.github/rename_project.sh index 9bfdb10..f989a1c 100755 --- a/.github/rename_project.sh +++ b/.github/rename_project.sh @@ -10,7 +10,7 @@ do done code_name="$(echo "$display_name" | sed -r 's/.*/\L&/;s/(^| )([a-z])/\U\2/g')" -mod_id="$(echo "com.${author}.${code_name}" | sed -r 's/.*/\L&/')" +mod_id="$(echo "${author}.${code_name}" | sed -r 's/.*/\L&/')" echo "Author: $author"; echo "Display Name: $display_name"; @@ -22,7 +22,7 @@ echo "Renaming project..." original_author="Author" original_code_name="TestMod" -original_mod_id="com.author.testmod" +original_mod_id="author.testmod" original_display_name="Test Mod" original_description="Put a neat description here" diff --git a/mod/modinfo.json b/mod/modinfo.json index 80959e9..85aec3c 100644 --- a/mod/modinfo.json +++ b/mod/modinfo.json @@ -1,5 +1,5 @@ { - "id": "com.author.testmod", + "id": "author.testmod", "name": "Test Mod", "version": "0.1.0", "authors": "Author", diff --git a/src/Plugin.cs b/src/Plugin.cs index e8c8862..cc2f903 100644 --- a/src/Plugin.cs +++ b/src/Plugin.cs @@ -9,7 +9,7 @@ namespace TestMod; -[BepInPlugin("com.author.testmod", "Test Mod", "0.1.0")] +[BepInPlugin("author.testmod", "Test Mod", "0.1.0")] sealed class Plugin : BaseUnityPlugin { public static new ManualLogSource Logger;