Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow defining nightly ID from CI #175

Merged
merged 2 commits into from
Nov 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/nightly-modpack-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/gtnh/cli/assemble_nightly.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__":
Expand Down
8 changes: 6 additions & 2 deletions src/gtnh/cli/generate_nightly.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down
4 changes: 4 additions & 0 deletions src/gtnh/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,7 @@ class InvalidReleaseException(Exception):

class ReleaseNotFoundException(Exception):
pass


class InvalidNightlyIdException(Exception):
pass
20 changes: 18 additions & 2 deletions src/gtnh/modpack_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand All @@ -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.

Expand Down