Marvin
10/11/2024, 7:38 PMprefect.yaml
configuration file. Please stay tuned for a moment.
It seems there was an error in conducting the search because the query wasn't provided. Let's refine the query to properly locate the relevant documentation on crafting a deployment script for fetching the latest Git branch in Prefect 2.x and 3.x. We'll focus on the use of shell script steps and git clone configurations within prefect.yaml
.
I'll proceed to search for this information again with specific queries. Please hold on.
Based on the documentation for both Prefect 2.x and 3.x, I found relevant information on how to configure the prefect.yaml
file to execute shell scripts and perform Git operations, such as cloning a repository.
Here is a summary for each version:
Prefect 2.x:
- You can use prefect.deployments.steps.run_shell_script
to execute shell commands. Make sure to set expand_env_vars: true
if you want to expand environment variables within the script.
- Use the prefect.deployments.steps.git_clone
to clone your repository and specify the branch dynamically using the output from the shell script.
Prefect 3.x:
- Similarly, you can use prefect.deployments.steps.run_shell_script
with options like stream_output
to control the script output.
- The Git clone operation is done using prefect.deployments.steps.git_clone
, where you can specify credentials and dynamically choose the branch based on script output.
Here's a simplified example for a deployment configuration based on your use case:
yaml
pull:
- prefect.deployments.steps.run_shell_script:
id: get_latest_branch
script: |
bash -c '
cd [MY REPO NAME HERE] && \
git fetch --all && \
LATEST_BRANCH=$(git for-each-ref --sort=-committerdate refs/remotes/origin/ --format="%(refname:short)" | grep -vE "^origin/(master|main)$" | head -n1 | sed "s#^origin/##") && \
echo $LATEST_BRANCH
'
stream_output: true
- prefect.deployments.steps.git_clone:
repository: [LINK TO MY REPO]
branch: "{{ get_latest_branch.stdout }}"
Make sure to replace [MY REPO NAME HERE]
and [LINK TO MY REPO]
with your actual repository details. The above script finds the most recently updated branch that is neither master
nor main
, assuming such branches exist in your workflow.
Reference links:
- Prefect 2.x Deployment Guide
- Prefect 3.x Deployment Guide
Let me know if you need further clarification or help!