diff --git a/.github/workflows/nightly-modpack-build.yml b/.github/workflows/nightly-modpack-build.yml index 43539f53..9dc5cad9 100644 --- a/.github/workflows/nightly-modpack-build.yml +++ b/.github/workflows/nightly-modpack-build.yml @@ -72,7 +72,7 @@ jobs: env: GITHUB_TOKEN: ${{ secrets.NIGHTLY_GITHUB_TOKEN }} run: | - poetry run python -m gtnh.cli.generate_nightly --update-available + poetry run python -m gtnh.cli.generate_nightly --id "${{ github.run_number }}" --update-available poetry run python -m gtnh.cli.assemble_nightly - name: Save cached mod zips diff --git a/src/gtnh/cli/assemble_nightly.py b/src/gtnh/cli/assemble_nightly.py index c63f992f..4ee47849 100644 --- a/src/gtnh/cli/assemble_nightly.py +++ b/src/gtnh/cli/assemble_nightly.py @@ -32,7 +32,7 @@ async def assemble_nightly(verbose: bool) -> None: await assembler.assemble_mmc(Side.CLIENT, verbose=verbose) await assembler.assemble_mmc(Side.CLIENT_JAVA9, verbose=verbose) - modpack_manager.set_last_successful_nightly(modpack_manager.get_nightly_count()) + modpack_manager.set_last_successful_nightly_id(modpack_manager.get_nightly_count()) if __name__ == "__main__": diff --git a/src/gtnh/cli/generate_nightly.py b/src/gtnh/cli/generate_nightly.py index 9f0c0216..a1b3b987 100644 --- a/src/gtnh/cli/generate_nightly.py +++ b/src/gtnh/cli/generate_nightly.py @@ -10,11 +10,15 @@ @click.command() @click.option("--update-available", default=False, is_flag=True) -async def generate_nightly(update_available: bool) -> None: +@click.option("--id", "new_id", type=int, help="Set numeric ID for new nightly release") +async def generate_nightly(update_available: bool, new_id: int) -> None: async with httpx.AsyncClient(http2=True) as client: m = GTNHModpackManager(client) existing_release = m.get_release("nightly") - m.increment_nightly_count() # assets need to be uploaded even if the build crashes, it tracks the build id + if new_id: + m.set_nightly_id(new_id) + else: + m.increment_nightly_count() # assets need to be uploaded even if the build crashes, it tracks the build id if not existing_release: raise ReleaseNotFoundException("Nightly release not found") diff --git a/src/gtnh/exceptions.py b/src/gtnh/exceptions.py index 0bb3f2ce..23eb4d86 100644 --- a/src/gtnh/exceptions.py +++ b/src/gtnh/exceptions.py @@ -32,3 +32,7 @@ class InvalidReleaseException(Exception): class ReleaseNotFoundException(Exception): pass + + +class InvalidNightlyIdException(Exception): + pass diff --git a/src/gtnh/modpack_manager.py b/src/gtnh/modpack_manager.py index 5978e69a..618d5acb 100644 --- a/src/gtnh/modpack_manager.py +++ b/src/gtnh/modpack_manager.py @@ -39,7 +39,7 @@ ModSource, Side, ) -from gtnh.exceptions import InvalidReleaseException, RepoNotFoundException +from gtnh.exceptions import InvalidNightlyIdException, InvalidReleaseException, RepoNotFoundException from gtnh.github.uri import latest_release_uri, org_repos_uri, repo_releases_uri, repo_uri from gtnh.gtnh_logger import get_logger from gtnh.models.available_assets import AvailableAssets @@ -640,6 +640,22 @@ def get_nightly_count(self) -> int: """ return self.assets.latest_nightly + def set_nightly_id(self, id: int) -> None: + """ + Set the nightly id to a specific number. Has to be greater than the last nightly id. + + Returns + ------- + None + """ + latest_id = self.assets.latest_nightly + if id > latest_id: + self.assets.latest_nightly = id + else: + raise InvalidNightlyIdException( + f"Cannot set new nightly id to {id}, needs to be greater than latest nightly count {latest_id}" + ) + def increment_nightly_count(self) -> None: """ Increment the nightly count. @@ -651,7 +667,7 @@ def increment_nightly_count(self) -> None: self.assets.latest_nightly += 1 self.save_assets() - def set_last_successful_nightly(self, id: int) -> None: + def set_last_successful_nightly_id(self, id: int) -> None: """ Set the last successful nightly id.