Skip to content

get-latest-version.py: Random suffix for bot branch name #308

@ryonakano

Description

@ryonakano

Problem

The branch name that get-latest-version.py creates is not unique:

new_branch = f"bot/update/{component_name}-{upstream_series_name}"

So, the actions will fail if the previous branch remains for some reason, e.g. closed the PR without deleting the branch or when Automatically delete head branches is not enabled:

Run python3 get-latest-version.py "noble"
  python3 get-latest-version.py "noble"
  shell: sh -e {0}
  env:
    PACKAGES_TO_IMPORT_PATH: /tmp/patched-packages
    GITHUB_TOKEN: ***
    GITHUB_REPOSITORY: os-patches
Traceback (most recent call last):
base-files noble
  File "/__w/os-patches/os-patches/get-latest-version.py", line 168, in <module>
  File "/__w/os-patches/os-patches/get-latest-version.py", line 157, in main
bash noble
distro-info-data noble
dpkg-source: info: extracting distro-info-data in distro-info-data-0.60ubuntu0.2
  File "/usr/lib/python3/dist-packages/git/cmd.py", line 739, in <lambda>
    return lambda *args, **kwargs: self._call_process(name, *args, **kwargs)
                                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/git/cmd.py", line 1315, in _call_process
    return self.execute(call, **exec_kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/git/cmd.py", line 1110, in execute
    raise GitCommandError(redacted_command, status, stderr_value, stdout_value)
git.exc.GitCommandError: Cmd('git') failed due to: exit code(1)
  cmdline: git push origin bot/update/distro-info-data-noble
  stderr: 'To https://github.com/ryonakano/os-patches
 ! [rejected]            bot/update/distro-info-data-noble -> bot/update/distro-info-data-noble (non-fast-forward)
error: failed to push some refs to 'https://github.com/ryonakano/os-patches'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. If you want to integrate the remote changes,
hint: use 'git pull' before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.'
Error: Process completed with exit code 1.

Proposal

Add random string to branch names and make sure the actions won't fail even if the previous branch remains.

Prior Art (Optional)

  • Flatpak External Data Checker puts random suffix, e.g. update-f7b567c:
    Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    Good First IssueSmall, self-contained issue. Good for newcomers, and/or should be an easy fix.Priority: WishlistNew feature or request. Not a priority, but something that might be nice.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions