Skip to content

Commit

Permalink
update-nixpkgs: allow force running the action even if no changes are…
Browse files Browse the repository at this point in the history
… detected

This is required for the SOP to rebase the branch locally.
  • Loading branch information
leona-ya committed Dec 9, 2024
1 parent 0e3a236 commit 6e4d710
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/update-nixpkgs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
6 changes: 6 additions & 0 deletions src/update_nixpkgs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
9 changes: 7 additions & 2 deletions src/update_nixpkgs/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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."
)
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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}'"
Expand Down

0 comments on commit 6e4d710

Please sign in to comment.