blob: c00e3b9c234a808295122e30d246e877dab8cd1b [file] [log] [blame]
# Copyright 2023 The Dart Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
from recipe_engine import post_process
from PB.recipes.dart.release.release import Release
DEPS = [
'dart',
'depot_tools/bot_update',
'depot_tools/gclient',
'depot_tools/git',
'depot_tools/gsutil',
'recipe_engine/buildbucket',
'recipe_engine/context',
'recipe_engine/path',
'recipe_engine/properties',
'recipe_engine/runtime',
'recipe_engine/step',
]
PROPERTIES = Release
PYTHON_VERSION_COMPATIBILITY = 'PY3'
def RunSteps(api, properties):
version = properties.version
assert version, 'the recipe requires a version'
channel = api.dart.Version(version=version).fields['CHANNEL']
if api.buildbucket.builder_name.endswith('-try'):
api.gclient.c = api.gclient.make_config()
soln = api.gclient.c.solutions.add()
soln.name = 'dart-docker'
soln.url = 'https://dart.googlesource.com/dart-docker'
soln.managed = False
api.bot_update.ensure_checkout()
else:
api.git.checkout(
url='https://dart.googlesource.com/dart-docker', ref='refs/heads/main')
with api.context(cwd=api.path['checkout']):
api.git('config', 'user.name', 'Dart CI', name='configure user.name')
api.git(
'config',
'user.email',
api.buildbucket.swarming_task_service_account,
name='configure user.email')
scripts_dir = api.path['checkout'].join('scripts')
dart = api.dart.download_dart_sdk(
scripts_dir.join('pubspec.yaml'), pubspec_name='scripts/pubspec.yaml')
with api.context(cwd=scripts_dir):
api.step('pub get', [dart, 'pub', 'get'])
api.step('scripts/bin/update.dart', [dart, 'scripts/bin/update.dart'])
result = api.git(
'diff',
'--exit-code',
'--quiet',
name=f'check for changes',
ok_ret=[0, 1],
)
if result.exc_result.retcode == 0:
# The repository is up to date.
return
api.git('commit', '-a', '-m', f'Upgrade dart to {version}')
if (not api.runtime.is_experimental and
not api.buildbucket.builder_name.endswith('-try')):
api.git('push', 'origin', 'HEAD:refs/heads/main')
def GenTests(api):
build = api.buildbucket.ci_build_message(
project='dart-docker',
builder='docker',
git_repo='https://dart.googlesource.com/dart-docker',
git_ref='refs/heads/main',
revision='18df0aae67183931b1b6d5d12cc04d89f7137919')
api.buildbucket.update_backend_service_account(build, 'service@example.com')
try_build = api.buildbucket.ci_build_message(
project='dart-docker',
builder='docker-try',
git_repo='https://dart.googlesource.com/dart-docker',
git_ref='refs/heads/main',
revision='18df0aae67183931b1b6d5d12cc04d89f7137919')
api.buildbucket.update_backend_service_account(try_build,
'service@example.com')
yield api.test(
'update',
api.properties(Release(version='2.19.0')),
api.buildbucket.build(build),
api.step_data('check for changes', retcode=1),
api.post_process(post_process.StatusSuccess),
)
yield api.test(
'try',
api.properties(Release(version='2.19.0')),
api.buildbucket.build(try_build),
api.post_process(post_process.StatusSuccess),
api.post_process(post_process.DropExpectation),
)
yield api.test(
'unchanged',
api.properties(Release(version='2.19.0')),
api.buildbucket.build(build),
api.post_process(post_process.StatusSuccess),
)
yield api.test(
'dry',
api.runtime(is_experimental=True),
api.properties(Release(version='2.19.0')),
api.buildbucket.build(build),
api.post_process(post_process.StatusSuccess),
api.post_process(post_process.DoesNotRunRE, 'git push'),
)