Automate branching out to new workspace in Microsoft Fabric with GitHub

This post covers how to automate branching out to new workspace in Microsoft Fabric with GitHub. Based on custom Branch Out to New Workspace scripts for Microsoft Fabric provided by Microsoft. Which you can find in the Fabric Toolbox GitHub repository provided by Microsoft.

Custom Branch Out To New Workspace in the Fabric Toolbox
Custom Branch Out To New Workspace in the Fabric Toolbox

I covered implementing it in Azure DevOps in a previous post. So, I decided to show a GitHub version. Below is a diagram that visualizes how it works.

Custom Branch Out To New Workspace scripts to automate branching out to new workspace in Microsoft Fabric with GitHub
Custom Branch Out To New Workspace scripts process when converted to GitHub

This post has four main purposes:

  • To highlight how GitHub Copilot in Visual Studio Code can quickly create a rich README file for you. Which you can amend as you wish.
  • Show how to do automate branching out to new workspace with GitHub Actions. After a previous posts showed how to get started with the Azure DevOps version.
  • Demonstrate how easy it was to convert a Python script with GitHub Copilot in Visual Studio Code.
  • Show how to make the Python script that runs the post tasks notebook run synchronously with one slight change.

One key point I want to highlight is that the post activity notebook performs a variety of tasks. Including updating default and attached Lakehouses for notebooks and updating Directlake model Lakehouse connections. I highly recommend going through the notebook to discover all of its capabilities.

I created the example GitHub repository GH-branch-out-to-new-workspace. Which you can download and work with as a template. By my own admission I created the README file with GitHub Copilot and amended it where required.

Automate branching out to new workspace in Microsoft Fabric with GitHub

To get started first ensure that your workspace is configured with Microsoft Fabric Git integration. In addition, make sure the specified scripts are added to the repository in GitHub. Like in the below image.

Fabric items and scripts in the Git repository
Fabric items and scripts in the Git repository

Also ensure you add the post activity notebook to a separate Fabric workspace. As per the instructions in the original GitHub repository.

You can then add similar variables into your repository as the ones recommended in the the README for the Azure DevOps version. With the below exceptions:

  • GH_API_URL – API URL, typically https://api.github.com
  • GH_OWNER – Name of repository owner
  • GH_REPO_NAME – name of repository

One key thing to note is that variables cannot start with the term GitHub. Which is why I shortened them to GH.

For this particular workflow I opted to add the Fabric token as a parameter. Feel free to change the logic to get it from Azure Key Vault like the Azure DevOps version.

I also created a Personal Access Token (PAT in GitHub and added GH_PAT_TOKEN as a secret value. Once done, I was ready to create my workflow.

GitHub Actions workflow

I started to create a new GitHub Actions workflow. Once done I changed the name of the file and the name of the workflow. To keep mine consistent I changed them both to branch-out-workspace.

I opted to remove the triggers and keep the workflow_dispatch to run the workflow manually. Along with the inputs(parameters) you can see in the sample workflow file. Which are similar to the ones with the Azure DevOps version.

Once done I added the below job. Which checks out the repository, installs the required libraries and then runs the two Python scripts:

'BranchOut':
  runs-on: windows-latest

  steps:
  - name: Checkout repository
    uses: actions/checkout@v3

  # Install requests libraries
  - name: Install required libraries
    run: |
      pip install requests
      pip install msal

  # Run Branch-Out-To-New-Workspace Script
  - name: Run Branch-Out-To-New-Workspace Script
    run: |        
      python .\scripts\BranchOut-Feature-Workspace-Automation-GitHub.py --GH_OWNER ${{vars.GH_OWNER}} --GH_REPO_NAME ${{vars.GH_REPO_NAME}} --GH_NEW_BRANCH ${{github.event.inputs.gh_new_branch}} --DEVELOPER "${{ github.event.inputs.developer_email }}" --WORKSPACE_NAME "${{ github.event.inputs.target_workspace }}" --CAPACITY_ID "${{ github.event.inputs.capacity_id }}" --GH_API_URL ${{vars.GH_API_URL}} --GH_MAIN_BRANCH "${{ github.event.inputs.gh_branch }}" --GH_GIT_FOLDER "${{ github.event.inputs.gh_git_folder }}" --FABRIC_TOKEN "${{ github.event.inputs.fabrictoken }}"  --GH_PAT_TOKEN "${{ secrets.GH_PAT_TOKEN }}"

  # Run Branch-Out-To-New-Workspace Script
  - name: Invoke Fabric Post Activity Job
    run: |        
      python .\scripts\Run_post_activity.py --FABRIC_TOKEN "${{ github.event.inputs.fabrictoken }}" --NOTEBOOK_WORKSPACE_ID "${{vars.NOTEBOOK_WORKSPACE_ID}}" --NOTEBOOK_ID "${{vars.NOTEBOOK_ID}}" --SOURCE_WORKSPACE "${{ github.event.inputs.source_workspace }}" --TARGET_WORKSPACE "${{ github.event.inputs.target_workspace }}" --TENANT_ID "${{vars.TENANT_ID}}" --COPY_LAKEHOUSE "${{ github.event.inputs.copy_lakehouse_data }}" --COPY_WAREHOUSE "${{ github.event.inputs.copy_warehouse_data }}" --CREATE_SHORTCUTS "${{ github.event.inputs.create_lakehouse_shortcuts }}" --CONNECTIONS_FROM_TO "${{ github.event.inputs.connections_from_to }}"

Next steps were to customize the two Python scripts.

Changing Python scripts to automate branching out to new workspace

First, I had to change the initial “BranchOut-Feature-Workspace-Automation.py” script to create a new branch in a GitHub repository instead of an Azure DevOps one.

I was able to do this with relative ease by creating an amended copy with GitHub Copilot in Visual Studio Code. I say relative ease because it took a couple of iterations to get it to create a new branch in GitHub properly. Admittedly, it utilized the Microsoft Learn MCP Server that I covered in a previous post.

To clarify, I do not take credit for changing the code in this Python script. Because GitHub Copilot did all the work. You are free to customize the generated solution to suit your needs.

However, I do take credit for the change to the “Run_post_activity.py” script to make sure it ran synchronously. Because to get this to work properly I simply added the “InProgress” status to the below is statement:

if status in ["NotStarted", "Running","InProgress"]:
    logging.info(f"The job is still running or is not started")
    time.sleep(retry_after)
else:
    break

Now the workflow waits for the notebook to finish properly before stating it has completed in GitHub.

After making these changes I went to start my workflow. Entering in the required parameters.

Entering parameters when starting the workflow to automate branching out to new workspace in Microsoft Fabric with GitHub
Entering parameters when starting the workflow

Which completed successfully as below.

Completed GitHub Actions workflow
Completed GitHub Actions workflow

As you can see, it now takes longer because it waits for post activities notebook to complete. I checked afterwards that my workspace had been created and that all the items were there.

Fabric items in feature workspace
Fabric items in feature workspace

In addition, I confirmed that the default Lakehouses for my notebook pointed to the Lakehouse in the new workspace.

Final words about automating branching out to new workspace

I hope this example of how to automate branching out to new workspace in Microsoft Fabric with GitHub helps others. Because it can be very powerful when working with GitHub and Microsoft Fabric Git integration.

In addition, I really hope that this post highlights how working with GitHub Copilot in Visual Studio Code can make you more efficient. Especially as we head towards 2026.

Feel free to give the sample GitHub repository a star if it helps.

Leave a Comment