Skip to content
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
34 changes: 28 additions & 6 deletions taskboot/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from taskboot.cargo import cargo_publish
from taskboot.git import git_push
from taskboot.github import github_release
from taskboot.github import github_repository_dispatch
from taskboot.push import heroku_release
from taskboot.push import push_artifacts
from taskboot.pypi import publish_pypi
Expand Down Expand Up @@ -301,26 +302,26 @@ def main() -> None:
git_push_cmd.set_defaults(func=git_push)

# Deploy as a github release
github_release_cmd = commands.add_parser(
github_repository_dispatch_cmd = commands.add_parser(
"github-release", help="Create a GitHub release and publish assets"
)
github_release_cmd.add_argument(
github_repository_dispatch_cmd.add_argument(
"repository",
type=str,
help="Github repository name to use (example: mozilla/task-boot)",
)
github_release_cmd.add_argument(
github_repository_dispatch_cmd.add_argument(
"version",
type=str,
help="Release version tag to create or update on github",
)
github_release_cmd.add_argument(
github_repository_dispatch_cmd.add_argument(
"--task-id",
type=str,
default=os.environ.get("TASK_ID"),
help="Taskcluster task group to analyse",
)
group = github_release_cmd.add_mutually_exclusive_group()
group = github_repository_dispatch_cmd.add_mutually_exclusive_group()
group.add_argument(
"--local-asset",
nargs="+",
Expand All @@ -333,7 +334,28 @@ def main() -> None:
type=str,
help="Asset to upload on the release, retrieved from previously created artifacts. Format is asset-name:path/to/artifact",
)
github_release_cmd.set_defaults(func=github_release)
github_repository_dispatch_cmd.set_defaults(func=github_release)

# Trigger a repository dispatch event
github_repository_dispatch_cmd = commands.add_parser(
"github-repository-dispatch", help="Trigger a repository dispatch event"
)
github_repository_dispatch_cmd.add_argument(
"repository",
type=str,
help="Github repository name to use (example: mozilla/task-boot)",
)
github_repository_dispatch_cmd.add_argument(
"event_type",
type=str,
help="Custom webhook event name",
)
github_repository_dispatch_cmd.add_argument(
"client_payload",
type=str,
help="JSON payload with extra information about the webhook event that the action or workflow may use",
)
github_repository_dispatch_cmd.set_defaults(func=github_repository_dispatch)

# Publish on crates.io
cargo_publish_cmd = commands.add_parser(
Expand Down
23 changes: 23 additions & 0 deletions taskboot/github.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,3 +136,26 @@ def github_release(target: Target, args: argparse.Namespace) -> None:
release.upload_asset(name=asset_name, path=artifact_path, label=asset_name)

logger.info(f"Release available as {release.html_url}")


def github_repository_dispatch(target: Target, args: argparse.Namespace) -> None:
"""
Push all artifacts from dependent tasks
"""
assert args.task_id is not None, "Missing task id"

# Load config from file/secret
config = Configuration(args)
assert config.has_git_auth(), "Missing Github authentication"

# Setup GitHub API client and load repository
github = Github(config.git["token"])
try:
repository = github.get_repo(args.repository)
logger.info(f"Loaded Github repository {repository.full_name} #{repository.id}")
except UnknownObjectException:
raise Exception(f"Repository {args.repository} is not available")

repository.create_repository_dispatch(args.event_type, args.client_payload)

logger.info("Repository dispatch triggered")