Skip to content

Commit

Permalink
deal with existing branches correctly
Browse files Browse the repository at this point in the history
if the branch already exists checkout -b fails and BAD THINGS happen
this fixes it, although with a nasty push --force
  • Loading branch information
github-actions[bot] committed Feb 28, 2025
1 parent 4a1feb9 commit 26d400f
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions scripts/check_changes.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@
import sys
import json
import subprocess
import datetime

import requests
import read_argfile

ARGSFILE="argfile.conf"
MATRIX_JSON_FILE = "data/combined_output.json"
TOKEN = os.getenv("TOKEN", "test token")
ARTIFACT_TOKEN = os.getenv("ARTIFACT_TOKEN", "gitlab token")
Expand All @@ -29,7 +32,7 @@ def call_git(*args, **kwargs):
*args: one or more strings to be arguements to the git command
"""
if not DEBUG:
subprocess.run(["git"] + args, check=True)
subprocess.run(["git"] + list(args), check=True)
else:
print(f"git {' '.join(args)}")

Expand All @@ -56,6 +59,7 @@ def update_files(config, driver_version, kernel_version):

dtk_reg = config['DTK_IMAGE'].split(":")[0]
with open(ARGSFILE, "w") as f:
f.write(f"TIMESTAMP={datetime.datetime.now()}\n")
for k,v in config.items():
if k == "DRIVER_VERSION":
f.write(f"DRIVER_VERSION={driver_version}\n")
Expand All @@ -75,7 +79,7 @@ def create_branch_and_pr(config, driver_version, kernel_version):
"""
branch_name = driver_version + "-" + kernel_version

call_git("checkout", "-b", branch_name, check=True)
call_git("checkout", "-B", branch_name, check=True)

# Config git identity
call_git("config", "user.name", "github-actions[bot]")
Expand All @@ -90,7 +94,7 @@ def create_branch_and_pr(config, driver_version, kernel_version):
f"Update DRIVER_PUBLISHED status and KERNEL_VERSION for {driver_version}-{kernel_version}")

# Push branch
call_git("push", "origin", branch_name)
call_git("push", "--force", "origin", branch_name)

# Create the PR for each commit
headers = {
Expand Down Expand Up @@ -177,7 +181,7 @@ def call_gitlab(repo_url, page=False):

# Main script
if __name__ == "__main__":
config_dict = read_argfile.read_key_value_file()
config_dict = read_argfile.read_key_value_file(ARGSFILE)

# Load current combined JSON data
with open(MATRIX_JSON_FILE, "r") as matrix_fh:
Expand Down

0 comments on commit 26d400f

Please sign in to comment.