From 6e4d7101e41bb0a684a6e2dcca361c8d7b812d13 Mon Sep 17 00:00:00 2001 From: Leona Maroni Date: Mon, 9 Dec 2024 09:59:00 +0100 Subject: [PATCH] update-nixpkgs: allow force running the action even if no changes are detected This is required for the SOP to rebase the branch locally. --- .github/workflows/update-nixpkgs.yaml | 2 +- src/update_nixpkgs/__init__.py | 6 ++++++ src/update_nixpkgs/update.py | 9 +++++++-- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/.github/workflows/update-nixpkgs.yaml b/.github/workflows/update-nixpkgs.yaml index 62b7f2d..4d8e56d 100644 --- a/.github/workflows/update-nixpkgs.yaml +++ b/.github/workflows/update-nixpkgs.yaml @@ -48,6 +48,6 @@ jobs: --nixpkgs-dir nixpkgs \ --nixpkgs-upstream-url https://github.com/NixOS/nixpkgs \ --nixpkgs-origin-url https://x-access-token:${{steps.app-token.outputs.token}}@github.com/flyingcircusio/nixpkgs.git \ - --platform-versions 24.05 + --platform-versions 24.05 ${{ github.event_name == 'workflow_dispatch' && '--force' || '' }} env: GH_TOKEN: ${{ steps.app-token.outputs.token }} diff --git a/src/update_nixpkgs/__init__.py b/src/update_nixpkgs/__init__.py index a7ef064..21f26f7 100644 --- a/src/update_nixpkgs/__init__.py +++ b/src/update_nixpkgs/__init__.py @@ -50,6 +50,12 @@ def main(): required=True, nargs="+", ) + parser_update.add_argument( + "--force", + help="Create new PR, even if no changes are detected", + action=argparse.BooleanOptionalAction, + default=False + ) parser_update.set_defaults(func=update_nixpkgs.update.run) parser_cleanup = subparsers.add_parser( diff --git a/src/update_nixpkgs/update.py b/src/update_nixpkgs/update.py index 2823c95..a235c38 100644 --- a/src/update_nixpkgs/update.py +++ b/src/update_nixpkgs/update.py @@ -92,17 +92,20 @@ def rebase_nixpkgs( branch_to_rebase: str, integration_branch: str, last_day_integration_branch: str, + force: bool ) -> NixpkgsRebaseResult | None: logging.info("Trying to rebase nixpkgs repository.") if nixpkgs_repo.is_dirty(): raise Exception("Repository is dirty!") - if not any(integration_branch == head.name for head in nixpkgs_repo.heads): + if not any(f"origin/{integration_branch}" == ref.name for ref in nixpkgs_repo.refs): + logging.info("Creating new integration branch") tracking_branch = nixpkgs_repo.create_head( integration_branch, f"origin/{branch_to_rebase}" ) tracking_branch.checkout() else: + logging.info("Checking out existing integration branch") nixpkgs_repo.git.checkout(integration_branch) latest_upstream = nixpkgs_repo.refs[f"upstream/{branch_to_rebase}"].commit @@ -112,7 +115,7 @@ def rebase_nixpkgs( if all( latest_upstream.hexsha != commit.hexsha for commit in common_grounds - ): + ) or force: logging.info( f"Latest commit of {branch_to_rebase} is '{latest_upstream.hexsha}' which is not part of our fork, rebasing." ) @@ -243,6 +246,7 @@ def run( nixpkgs_origin_url: str, fc_nixos_dir: str, nixpkgs_dir: str, + force: bool, github_access_token: str, ): today = datetime.date.today().isoformat() @@ -272,6 +276,7 @@ def run( nixpkgs_target_branch, integration_branch, last_day_integration_branch, + force ): logging.info( f"Updated 'nixpkgs' to '{result.fork_after_rebase.hexsha}'"