Skip to content
Closed
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
14 changes: 5 additions & 9 deletions .github/workflows/sync_cling.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
name: Sync Cling repo

on:
push:
branches:
- 'master'
pull_request:
paths:
- 'interpreter/cling/**'
- 'core/textinput/src/textinput/**'
workflow_dispatch:

- '.github/workflows/utilities/sync_cling.py'
jobs:
sync-cling-history:
if: github.repository_owner == 'root-project'
if: github.repository_owner == 'devajithvs'
runs-on: ubuntu-latest
steps:
- name: Checkout ROOT
Expand All @@ -23,8 +19,8 @@ jobs:
- name: Checkout Cling
uses: actions/checkout@v4
with:
repository: root-project/cling
token: ${{ secrets.CLING_GIT_TOKEN }}
repository: devajithvs/cling
token: ${{ secrets.CLING_GIT_TOKEN_TESTING }}
path: cling
fetch-depth: 32768

Expand Down
28 changes: 12 additions & 16 deletions .github/workflows/utilities/sync_cling.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
ROOT_REPO_DIR_NAME = 'root'
INTERP_DIR_NAME = 'interpreter/cling'
DEST_INTERP_DIR_NAME = ''
TEXTINPUT_DIR_NAME = 'core/textinput/src/textinput'
DEST_TEXTINPUT_DIR_NAME='lib/UserInterface/textinput'

def printError(msg):
print(f'*** Error: {msg}')
Expand Down Expand Up @@ -47,16 +45,16 @@
return out

def getAllClingTags():
execCommand(f'git fetch --tags', CLING_REPO_DIR_NAME)

Check failure on line 48 in .github/workflows/utilities/sync_cling.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (F541)

.github/workflows/utilities/sync_cling.py:48:17: F541 f-string without any placeholders

def getRootSyncTag():
# We try to get the tags, to get the latest ROOT commit that was synchronized
getAllClingTags()
tagsStr = execCommand(f'git tag', CLING_REPO_DIR_NAME)

Check failure on line 53 in .github/workflows/utilities/sync_cling.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (F541)

.github/workflows/utilities/sync_cling.py:53:27: F541 f-string without any placeholders
tags = tagsStr.split('\n')
if tags == ['']:
printInfo(f'No tags found locally. Looking in the source repository.')

Check failure on line 56 in .github/workflows/utilities/sync_cling.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (F541)

.github/workflows/utilities/sync_cling.py:56:19: F541 f-string without any placeholders
tagsStr = execCommand(f'git ls-remote --tags origin', CLING_REPO_DIR_NAME)

Check failure on line 57 in .github/workflows/utilities/sync_cling.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (F541)

.github/workflows/utilities/sync_cling.py:57:31: F541 f-string without any placeholders
tags = tagsStr.split('\n')
print(tags)
tags = list(map(lambda t: t.split('/')[-1] if '/' in t else t, tags))
Expand Down Expand Up @@ -87,26 +85,21 @@
hashes = [line.split(' ', 1)[0] for line in out.split('\n')]
return hashes

def createPatches(rootHashes, interpHashes, textinputHashes):
def createPatches(rootHashes, interpHashes):
patches = []

# We'll need a few sets to quickly check what to do with ROOT hashes
interpHashesSet = set(interpHashes)
textInputHashesSet = set(textinputHashes)
allHashesSet = interpHashesSet | textInputHashesSet

# We filter the ROOT hashes that we do not want to sync
rootHashesToSync = list(filter(lambda hash: hash in allHashesSet, rootHashes))
rootHashesToSync = list(filter(lambda hash: hash in interpHashesSet, rootHashes))

# We loop on ROOT hashes to sync, from oldest to newest
# to return a list of triples [label, hash, patchAsSting], where label allows us
# to disinguish between textinput and interpreter patches and hash is there
# for debugging purposes.
# One commit can be visible in both directories, ergo 2 patches per hash are possible.
# to return a list of triples [dirInRepo, hash, patchAsSting], where dirInRepo is the
# directory and hash is there for debugging purposes.
for rootHashtoSync in reversed(rootHashesToSync):
keys = []
if rootHashtoSync in interpHashesSet: keys.append(INTERP_DIR_NAME)

Check failure on line 102 in .github/workflows/utilities/sync_cling.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (E701)

.github/workflows/utilities/sync_cling.py:102:45: E701 Multiple statements on one line (colon)
if rootHashtoSync in textInputHashesSet: keys.append(TEXTINPUT_DIR_NAME)
for key in keys:
patchAsStr = execCommand(f"git format-patch -1 {rootHashtoSync} {key} --stdout", ROOT_REPO_DIR_NAME)
patches.append([key, rootHashtoSync, patchAsStr])
Expand All @@ -115,7 +108,7 @@
def applyPatches(patches):
for dirInRepo, hash, patchAsStr in patches:
ignorePathLevel = dirInRepo.count('/') + 2
destDirName = DEST_INTERP_DIR_NAME if dirInRepo == INTERP_DIR_NAME else DEST_TEXTINPUT_DIR_NAME
destDirName = DEST_INTERP_DIR_NAME
directoryOption = f'--directory {destDirName}' if destDirName else ''
printInfo(f'Applying {hash} restricted to {dirInRepo} to repository {CLING_REPO_DIR_NAME}')
execCommand(f'git am -p {ignorePathLevel} {directoryOption}', CLING_REPO_DIR_NAME, patchAsStr)
Expand All @@ -126,8 +119,8 @@
Push the changes and tags upstream.
'''
# We fetch the remote and local tags to make the following operations more resilient
remoteTags = execCommand(f'git ls-remote --tags origin', CLING_REPO_DIR_NAME)

Check failure on line 122 in .github/workflows/utilities/sync_cling.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (F541)

.github/workflows/utilities/sync_cling.py:122:30: F541 f-string without any placeholders
localTags = execCommand(f'git tag', CLING_REPO_DIR_NAME)

Check failure on line 123 in .github/workflows/utilities/sync_cling.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (F541)

.github/workflows/utilities/sync_cling.py:123:29: F541 f-string without any placeholders

# Clean the old tag
printInfo(f'Found a sync tag ({oldSyncTag}): deleting it.')
Expand All @@ -139,7 +132,7 @@
printWarning(f'Tag {oldSyncTag} was not found in the upstream repository.')

# Time to push the sync commits!
execCommand(f'git push', CLING_REPO_DIR_NAME)

Check failure on line 135 in .github/workflows/utilities/sync_cling.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (F541)

.github/workflows/utilities/sync_cling.py:135:17: F541 f-string without any placeholders

# And finally we tag and push the tag
newTag = CLING_TAG_ROOT_HASH_PREFIX+rootSyncHash
Expand All @@ -158,18 +151,17 @@
# to commits in the directories we are interested in for the sync
rootHashes = getHashes(ROOT_REPO_DIR_NAME, startingRootHash)
interpHashes = getHashes(ROOT_REPO_DIR_NAME, startingRootHash, INTERP_DIR_NAME)
textinputHashes = getHashes(ROOT_REPO_DIR_NAME, startingRootHash, TEXTINPUT_DIR_NAME)

# If we have no commits to sync, we quit.
if not interpHashes and not textinputHashes:
if not interpHashes:
# nothing to do, we have no commits to sync
printInfo('No commit to sync. Exiting now.')
return 0

printInfo(f'We found:\n - {len(interpHashes)} patches from the directory {INTERP_DIR_NAME}\n - {len(textinputHashes)} patches from the directory {TEXTINPUT_DIR_NAME}')
printInfo(f'We found:\n - {len(interpHashes)} patches from the directory {INTERP_DIR_NAME}')

# We now create the patches we want to apply to the cling repo
patches = createPatches(rootHashes, interpHashes, textinputHashes)
patches = createPatches(rootHashes, interpHashes)

# We now apply the patches
if not patches:
Expand All @@ -185,6 +177,10 @@

applyPatches(patches)

# Remove text-input directory, revert this after the run.
execCommand(f'git rm lib/UserInterface/textinput -r', CLING_REPO_DIR_NAME)

Check failure on line 181 in .github/workflows/utilities/sync_cling.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (F541)

.github/workflows/utilities/sync_cling.py:181:17: F541 f-string without any placeholders
execCommand(f'git commit -m "Remove `textinput` directory"', CLING_REPO_DIR_NAME)

Check failure on line 182 in .github/workflows/utilities/sync_cling.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (F541)

.github/workflows/utilities/sync_cling.py:182:17: F541 f-string without any placeholders

syncTagAndPush(rootSyncTag, rootHashes[0])

if __name__ == '__main__':
Expand Down
Loading