From 161e0e7624b0495801f8390fa19fd61c598ed9ad Mon Sep 17 00:00:00 2001 From: "Thomas W. C. Carlson" <72635603+TWCCarlson@users.noreply.github.com> Date: Sat, 27 Jul 2024 15:32:34 -0700 Subject: [PATCH] Implement workflow generating latest tile images There appears to be a bug with making directories, solved using os.makedirs before calling the problematic method --- .github/workflows/buildNewestWikiMaps.yml | 88 +++++++++++++++++++++++ scripts/buildWikiMaps.py | 12 +++- scripts/cache.py | 10 ++- 3 files changed, 106 insertions(+), 4 deletions(-) create mode 100644 .github/workflows/buildNewestWikiMaps.yml diff --git a/.github/workflows/buildNewestWikiMaps.yml b/.github/workflows/buildNewestWikiMaps.yml new file mode 100644 index 0000000..121bec0 --- /dev/null +++ b/.github/workflows/buildNewestWikiMaps.yml @@ -0,0 +1,88 @@ +name: Build Latest MapIDs + +on: [workflow_dispatch] + +jobs: + fetch-cache: + name: Build Latest Wiki Maps + runs-on: ubuntu-22.04 + + steps: + - name: 1. Install Python + uses: actions/setup-python@v5 + with: + python-version: '3.12' + + - name: 2. Checkout + uses: actions/checkout@v4 + + - name: 3. Load Vips Binaries + run: | + sudo apt-get -y update + sudo apt-get -y install libvips-dev --no-install-recommends + + - name: 4. Install Requirements + run: | + pip install -r requirements.txt + pip show pyvips + + - name: 5. Download Latest Cache + run: | + python scripts/buildWikiMaps.py getCache + CACHE_VER=$(cat lastVersion.txt) + echo "CACHE_VER=$CACHE_VER" >> $GITHUB_ENV + + - name: 6. Checkout RuneLite + run: | + git clone https://github.com/runelite/runelite.git RuneLite + + - name: 7. Set up JDK 11 + uses: actions/setup-java@v4 + with: + distribution: temurin + java-version: 11 + + - name: 8. Build RuneLite + run: | + cd RuneLite + mvn install -q -f pom.xml -DskipTests + + - name: 9. Build MapExport + run: | + mvn -q clean package + + - name: 10. Run MapExport + working-directory: ./osrs-wiki-maps + run: | + java -jar target/osrs-wiki-maps-1.10.26-shaded.jar $CACHE_VER + + - name: 11. Generate Base Tiles + run: | + python scripts/buildWikiMaps.py createBaseTiles $CACHE_VER + + - name: 12. Build All MapID Tiles + run: | + python scripts/buildWikiMaps.py buildAllMapIDs $CACHE_VER + + - name: 13. Timestamp Release + id: tag + run: | + echo "::set-output name=release_tag::WikiMapGen_$(date +"%Y.%m.%d_%H-%M")" + echo "::set-output name=release_count::${{github.run_number}}" + + - name: 14. Package + run: | + zip -r -q rendered.zip osrs-wiki-maps/out/mapgen/versions/${{env.CACHE_VER}}/tiles/rendered + + - name: 15. Package and Release + uses: softprops/action-gh-release@v2 + with: + name: ${{env.CACHE_VER}} + tag_name: ${{steps.tag.outputs.release_tag}} + body: | + Release No. ${{steps.tag.outputs.release_count}} + Using openRS2 Cache ${{env.CACHE_VER}} + token: ${{secrets.GITHUB_TOKEN}} + files: | + rendered.zip + make_latest: true \ No newline at end of file diff --git a/scripts/buildWikiMaps.py b/scripts/buildWikiMaps.py index 6bdbaa4..8ad813c 100644 --- a/scripts/buildWikiMaps.py +++ b/scripts/buildWikiMaps.py @@ -5,10 +5,13 @@ BASE_DIRECTORY = "osrs-wiki-maps/out/mapgen/versions" -def getCache(version=None): +def getCache(reqVersion=None): import cache # Fetch the latest, or the version supplied as an argument, game cache - cache.download(f"./osrs-wiki-maps/out/mapgen/versions", version) + foundVersion = cache.download(f"./osrs-wiki-maps/out/mapgen/versions", + reqVersion) + with open("lastVersion.txt", 'w') as out: + out.write(foundVersion) def createBaseTiles(version): # Pyvips import is OS-dependent, use dispatcher file @@ -40,7 +43,10 @@ def createBaseTiles(version): # Load the image and slice planeImage = pv.Image.new_from_file(planeImagePath) - planeImage.dzsave(os.path.join(dzSaveOutPath, f"plane_{planeNum}/2"), + resultDir = os.path.join(dzSaveOutPath, f"plane_{planeNum}/2") + if not os.path.exists(resultDir): + os.makedirs(resultDir) + planeImage.dzsave(resultDir, tile_size= 256, suffix= '.png[Q=100]', depth= 'one', diff --git a/scripts/cache.py b/scripts/cache.py index fb70469..3963fc9 100644 --- a/scripts/cache.py +++ b/scripts/cache.py @@ -14,9 +14,17 @@ def make_output_folder(date_str: str, sub_ver: int, working_dir: str) -> str: + # Determine the name of the output folder version_count = 0 letter = "a" out_folder = os.path.join(working_dir, f"{date_str}_{sub_ver}_{letter}") + + # In a fresh install the out paths may not exist + out_dir = os.path.dirname(out_folder) + if not os.path.exists(out_dir): + os.makedirs(out_dir) + + # If the output folder already exists, increment the letter version while os.path.exists(out_folder): version_count += 1 letter = ascii_lowercase[version_count] @@ -159,7 +167,7 @@ def download(working_dir, version=None): download_xteas(cache_id, out_folder) download_cache(cache_id, out_folder) - return out_folder + return os.path.basename(out_folder) if __name__ == "__main__": download("osrs-wiki-maps/out/mapgen/versions", "2024-05-29_0") \ No newline at end of file