Skip to content

feat(workflows): Add client library sample to create a workflow - #14799

Open
iennae wants to merge 1 commit into
refactor/workflows-cloud-client-packagefrom
feat/workflows-create-workflow
Open

iennae wants to merge 1 commit into
refactor/workflows-cloud-client-packagefrom
feat/workflows-create-workflow

Conversation

@iennae

@iennae iennae commented Nov 14, 2026

Copy link
Copy Markdown
Contributor

Description

Developers deploying workflows through the Python SDK lacked a sample showing how to pass workflow source contents, execution service accounts, call-log levels, labels, and user environment variables.

Adds create_workflow.py (workflows_create_workflow) using workflows_v1.WorkflowsClient.create_workflow and waiting on the returned long-running operation, along with unit and gated live integration tests.

Note: Stacked on #14797 (refactor/workflows-cloud-client-package) so this PR shows only this sample's diff.

Checklist

Testing

  • I have tested this change on a live environment and verified it works as intended. Unit and live integration tests pass on Python 3.13.

Compliance & Style


Post-Approval Actions

  • Please merge this PR for me once it is approved

@iennae
iennae requested review from a team as code owners November 14, 2026 00:19
@product-auto-label product-auto-label Bot added the api: workflows Issues related to the Workflows API. label Nov 14, 2026
@snippet-bot

snippet-bot Bot commented Nov 14, 2026 •

Copy link
Copy Markdown

Here is the summary of changes.

You are about to add 1 region tag.

This comment is generated by snippet-bot.
If you find problems with this result, please file an issue at:
https://github.com/googleapis/repo-automation-bots/issues.
To update this comment, add snippet-bot:force-run label or use the checkbox below:

  • Refresh this comment

@product-auto-label product-auto-label Bot added the samples Issues that are directly related to samples. label Nov 14, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a new sample script, create_workflow.py, which demonstrates how to create a Google Cloud Workflow with logging, labels, and environment variables, along with its corresponding unit and integration tests in create_workflow_test.py. The feedback points out a usability issue in the CLI argument parsing: if a user specifies a custom --project-id but leaves --service-account-email as default, the script uses a hardcoded project ID in the service account email, which will cause the workflow creation to fail. A suggestion is provided to dynamically construct the default service account email using the resolved project ID.

Comment on lines +105 to +120
parser.add_argument(
"--service-account-email",
default=os.environ.get(
"SERVICE_ACCOUNT_EMAIL",
"example-runner@example-project-id.iam.gserviceaccount.com",
),
help="Service account the workflow runs as (default: $SERVICE_ACCOUNT_EMAIL)",
)
args = parser.parse_args()

create_workflow(
project_id=args.project_id,
location_id=args.location_id,
workflow_id=args.workflow_id,
service_account_email=args.service_account_email,
)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

If a user runs this script from the command line and specifies a custom --project-id but does not provide --service-account-email, the default service account email will still use the hardcoded 'example-project-id' instead of the user's specified project ID. This will cause the workflow creation to fail because the service account won't exist in their project.

We should dynamically construct the default service account email using the resolved project_id if --service-account-email is not explicitly provided.

Suggested change
parser.add_argument(
"--service-account-email",
default=os.environ.get(
"SERVICE_ACCOUNT_EMAIL",
"example-runner@example-project-id.iam.gserviceaccount.com",
),
help="Service account the workflow runs as (default: $SERVICE_ACCOUNT_EMAIL)",
)
args = parser.parse_args()
create_workflow(
project_id=args.project_id,
location_id=args.location_id,
workflow_id=args.workflow_id,
service_account_email=args.service_account_email,
)
parser.add_argument(
"--service-account-email",
default=os.environ.get("SERVICE_ACCOUNT_EMAIL"),
help="Service account the workflow runs as (default: $SERVICE_ACCOUNT_EMAIL)",
)
args = parser.parse_args()
service_account_email = args.service_account_email
if not service_account_email:
service_account_email = (
f"example-runner@{args.project_id}.iam.gserviceaccount.com"
)
create_workflow(
project_id=args.project_id,
location_id=args.location_id,
workflow_id=args.workflow_id,
service_account_email=service_account_email,
)

Developers provisioning workflows programmatically from Python lacked a reference showing how to deploy YAML source with a dedicated service account, call-log level, and user environment variables. Adding `workflows_create_workflow` demonstrates waiting on the long-running creation operation and handling `AlreadyExists`.
@iennae
iennae force-pushed the feat/workflows-create-workflow branch from 819b9e4 to b61c2ca Compare November 14, 2026 00:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api: workflows Issues related to the Workflows API. samples Issues that are directly related to samples.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant