Skip to content

Commit

Permalink
Merge pull request #529 from DataDog/ncreated/RUMM-1467-update-dogfoo…
Browse files Browse the repository at this point in the history
…ding-script-with-new-path

RUMM-1467 Update dogfooding script for recent changes in other repos
  • Loading branch information
ncreated authored Jul 5, 2021
2 parents b8f34bb + f9e5460 commit 8673c7a
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 36 deletions.
72 changes: 39 additions & 33 deletions tools/dogfooding/dogfood.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def remember_cwd():
os.chdir(previous)


def dogfood(dry_run: bool, repository_url: str, repository_name: str, repository_package_resolved_path: str) -> int:
def dogfood(dry_run: bool, repository_url: str, repository_name: str, repository_package_resolved_paths: [str]) -> int:
print(f'🐶 Dogfooding: {repository_name}...')

# Read commit information:
Expand All @@ -41,7 +41,7 @@ def dogfood(dry_run: bool, repository_url: str, repository_name: str, repository
os.system(f'swift package --package-path {dd_sdk_package_path} resolve')
dd_sdk_ios_package = PackageResolvedFile(path=f'{dd_sdk_package_path}/Package.resolved')

# Clone dependant repo to temporary location and update its `Package.resolved` so it points
# Clone dependant repo to temporary location and update its `Package.resolved` (one or many) so it points
# to the current `dd-sdk-ios` commit. After that, push changes to dependant repo and create dogfooding PR.
with TemporaryDirectory() as temp_dir:
with remember_cwd():
Expand All @@ -52,39 +52,40 @@ def dogfood(dry_run: bool, repository_url: str, repository_name: str, repository
)
repository.create_branch(f'dogfooding-{dd_sdk_ios_commit.hash_short}')

package = PackageResolvedFile(
path=repository_package_resolved_path
packages: [PackageResolvedFile] = list(
map(lambda path: PackageResolvedFile(path=path), repository_package_resolved_paths)
)

# Update version of `dd-sdk-ios`:
package.update_dependency(
package_name='DatadogSDK',
new_branch='dogfooding',
new_revision=dd_sdk_ios_commit.hash,
new_version=None
)
for package in packages:
package.update_dependency(
package_name='DatadogSDK',
new_branch='dogfooding',
new_revision=dd_sdk_ios_commit.hash,
new_version=None
)

# Add or update `dd-sdk-ios` dependencies
for dependency_name in dd_sdk_ios_package.read_dependency_names():
dependency = dd_sdk_ios_package.read_dependency(package_name=dependency_name)

if package.has_dependency(package_name=dependency_name):
package.update_dependency(
package_name=dependency_name,
new_branch=dependency['state']['branch'],
new_revision=dependency['state']['revision'],
new_version=dependency['state']['version'],
)
else:
package.add_dependency(
package_name=dependency_name,
repository_url=dependency['repositoryURL'],
branch=dependency['state']['branch'],
revision=dependency['state']['revision'],
version=dependency['state']['version']
)

package.save()
# Add or update `dd-sdk-ios` dependencies
for dependency_name in dd_sdk_ios_package.read_dependency_names():
dependency = dd_sdk_ios_package.read_dependency(package_name=dependency_name)

if package.has_dependency(package_name=dependency_name):
package.update_dependency(
package_name=dependency_name,
new_branch=dependency['state']['branch'],
new_revision=dependency['state']['revision'],
new_version=dependency['state']['version'],
)
else:
package.add_dependency(
package_name=dependency_name,
repository_url=dependency['repositoryURL'],
branch=dependency['state']['branch'],
revision=dependency['state']['revision'],
version=dependency['state']['version']
)

package.save()

# Push changes to dependant repo:
repository.commit(
Expand Down Expand Up @@ -125,7 +126,10 @@ def dogfood(dry_run: bool, repository_url: str, repository_name: str, repository
dry_run=dry_run,
repository_url='git@github.com:DataDog/datadog-ios.git',
repository_name='datadog-ios',
repository_package_resolved_path='Datadog.xcworkspace/xcshareddata/swiftpm/Package.resolved'
repository_package_resolved_paths=[
'.package.resolved',
'DatadogApp.xcworkspace/xcshareddata/swiftpm/Package.resolved'
]
)

# Dogfood in Shopist iOS
Expand All @@ -134,7 +138,9 @@ def dogfood(dry_run: bool, repository_url: str, repository_name: str, repository
dry_run=dry_run,
repository_url='git@github.com:DataDog/shopist-ios.git',
repository_name='shopist-ios',
repository_package_resolved_path='Shopist/Shopist.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved'
repository_package_resolved_paths=[
'Shopist/Shopist.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved'
]
)

except Exception as error:
Expand Down
6 changes: 3 additions & 3 deletions tools/dogfooding/src/package_resolved.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,11 @@ def update_dependency(self, package_name: str, new_branch: str, new_revision: st
diff = old_state.items() ^ new_state.items()

if len(diff) > 0:
print(f'✏️️ Updated "{package_name}":')
print(f'✏️️ Updated "{package_name}" in {self.path}:')
print(f' → old: {old_state}')
print(f' → new: {new_state}')
else:
print(f'✏️️ "{package_name}" is up-to-date')
print(f'✏️️ "{package_name}" is up-to-date in {self.path}')

def add_dependency(self, package_name: str, repository_url: str, branch: str, revision: str, version):
"""
Expand Down Expand Up @@ -105,7 +105,7 @@ def add_dependency(self, package_name: str, repository_url: str, branch: str, re

pins.insert(index, new_pin)

print(f'✏️️ Added "{package_name}" at index {index}:')
print(f'✏️️ Added "{package_name}" at index {index} in {self.path}:')
print(f' → branch: {branch}')
print(f' → revision: {revision}')
print(f' → version: {version}')
Expand Down

0 comments on commit 8673c7a

Please sign in to comment.