Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RUMM-1467 Update dogfooding script for recent changes in other repos #529

Merged
Merged
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
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'
Comment on lines +130 to +131
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Two package resolved seem redundant (they are equal), but solving this is beyond the scope of this RUMM-1467.

]
)

# 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