From d8009a37196e244c29b10b78eb53b92573cd1b3a Mon Sep 17 00:00:00 2001 From: altrisi Date: Thu, 22 Oct 2020 22:04:27 +0200 Subject: [PATCH] Add GitHub Actions (#496) * Add Github actions Using bot's mail looks better in the wiki, since in main page it shows the pusher name but in the revisions tab it shows the bot. Allow failure is to prevent the commit appearing with a cross just because the wiki didn't change. It can probably also be fixed in the command part, but does the same * Rules-to-wiki 1.0 --- .github/workflows/build-on-pr.yml | 35 ++++++++++++++ .github/workflows/devbuild.yml | 35 ++++++++++++++ .github/workflows/merge-docs.yml | 19 ++++++++ .github/workflows/rules-to-wiki.yml | 75 +++++++++++++++++++++++++++++ 4 files changed, 164 insertions(+) create mode 100644 .github/workflows/build-on-pr.yml create mode 100644 .github/workflows/devbuild.yml create mode 100644 .github/workflows/merge-docs.yml create mode 100644 .github/workflows/rules-to-wiki.yml diff --git a/.github/workflows/build-on-pr.yml b/.github/workflows/build-on-pr.yml new file mode 100644 index 00000000..334149db --- /dev/null +++ b/.github/workflows/build-on-pr.yml @@ -0,0 +1,35 @@ +# This workflow will build a Java project with Gradle +# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-gradle + +name: Pull Request Builds + +on: + pull_request: + paths: + - "src/**" + +jobs: + Build: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + - name: Set up JDK 1.8 + uses: actions/setup-java@v1 + with: + java-version: 1.8 + - name: Cache Gradle packages + uses: actions/cache@v2 + with: + path: ~/.gradle/caches + key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle') }} + restore-keys: ${{ runner.os }}-gradle + - name: Grant execute permission to gradlew + run: chmod +x gradlew + - name: Build with Gradle + run: ./gradlew build + - uses: actions/upload-artifact@v2 + with: + name: "Compiled artifacts for Pull Request #${{github.event.number}}" + path: build/libs diff --git a/.github/workflows/devbuild.yml b/.github/workflows/devbuild.yml new file mode 100644 index 00000000..27ada928 --- /dev/null +++ b/.github/workflows/devbuild.yml @@ -0,0 +1,35 @@ +# This workflow will build a Java project with Gradle +# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-gradle + +name: Development Builds + +on: + push: + paths: + - "src/**" + +jobs: + Build: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + - name: Set up JDK 1.8 + uses: actions/setup-java@v1 + with: + java-version: 1.8 + - name: Cache Gradle packages + uses: actions/cache@v2 + with: + path: ~/.gradle/caches + key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle') }} + restore-keys: ${{ runner.os }}-gradle + - name: Grant execute permission to gradlew + run: chmod +x gradlew + - name: Build with Gradle + run: ./gradlew build + - uses: actions/upload-artifact@v2 + with: + name: Compiled artifacts for ${{ github.sha }} + path: build/libs diff --git a/.github/workflows/merge-docs.yml b/.github/workflows/merge-docs.yml new file mode 100644 index 00000000..aad8b6b1 --- /dev/null +++ b/.github/workflows/merge-docs.yml @@ -0,0 +1,19 @@ +name: Merge docs +on: + push: + paths: + - "docs/**" + - "!docs/scarpet/Full.md" +jobs: + Scarpet: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Merge docs + run: ./mergedoc.sh + - name: Commit merged docs + run: | + git config --global user.name 'github-actions[bot]' + git config --global user.email 'github-actions[bot]@users.noreply.github.com' + git commit -am "Merge docs for '${{ github.event.head_commit.message }}'" + git push diff --git a/.github/workflows/rules-to-wiki.yml b/.github/workflows/rules-to-wiki.yml new file mode 100644 index 00000000..84b94361 --- /dev/null +++ b/.github/workflows/rules-to-wiki.yml @@ -0,0 +1,75 @@ +name: Update wiki +on: + push: + branches: + - master + paths: + - "src/main/java/carpet/CarpetSettings.java" +jobs: + Rules: + runs-on: ubuntu-latest + steps: + - name: Checkout Carpet sources + uses: actions/checkout@v2 + - name: Set up JDK 1.8 + uses: actions/setup-java@v1 + with: + java-version: 1.8 + - name: Cache Gradle packages + uses: actions/cache@v2 + with: + path: ~/.gradle/caches + key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle') }} + restore-keys: ${{ runner.os }}-gradle + - name: Generate RulePrinter class + run: | + cd src/main/java/carpet/utils + echo " + package carpet.utils; + import carpet.CarpetServer; + import carpet.settings.SettingsManager; + import net.fabricmc.loader.api.entrypoint.PreLaunchEntrypoint; + import java.lang.System; + public class RulePrinter implements PreLaunchEntrypoint { + @Override + public void onPreLaunch() { + CarpetServer.onGameStarted(); + CarpetServer.settingsManager.printAllRulesToLog(null); + System.exit(0); + } + } + " > RulePrinter.java + cd ../../../../../ + - name: Replace fabric.mod.json + run: | + cd src/main/resources + rm fabric.mod.json + echo ' + { + "schemaVersion": 1, + "id": "carpet", + "version": "1.4.11", + "entrypoints": { + "preLaunch": [ "carpet.utils.RulePrinter" ] + } + }' > fabric.mod.json + cd ../../../ + - name: Run solution + run: | + chmod +x gradlew + ./gradlew runServer > settings-toProccess.txt + - name: Checkout wiki + uses: actions/checkout@v2 + with: + repository: ${{github.repository}}.wiki + path: wiki + - name: Proccess Gradle log into a pretty wiki page + run: from1="# Carpet"; to2="BUILD SUCCESSFUL"; a="$(cat settings-toProccess.txt)"; a="$(echo "${a#*"$from1"}")"; echo "$from1${a%%"$to2"*}" > wiki/Current-Available-Settings.md + - name: Commit updated wiki page + continue-on-error: true + run: | + cd wiki + git config --global user.name '${{ github.event.pusher.name }}' # Looks better than "github-actions-bot" + git config --global user.email 'github-actions[bot]@users.noreply.github.com' + git commit -am "Update wiki for '${{ github.event.head_commit.message }}'" + git push