How to deploy multiple branches to an Azure static web app using GitHub workflow actions?

Jason Frank 31 Reputation points
2021-07-09T23:26:50.133+00:00

Once we connect our Azure static web app to the code on GitHub, staging environments are automatically created when a pull request is issued for the main branch (aka master). That part is working fine.

However, I'd like to create staging environments when a pull request is issued for a different branch. Here's the basic idea of a branching scheme to be used for that workflow:

  • main: production
  • dev: staging / integration environment
  • feature-[XYZ]: new features

So, for example, I want to create a staging environment in my Azure static web app when a pull request is issued for the dev branch.

I have not found an example of how to accomplish this. One thing I tried was to add the dev branch in the list of branches in the workflow action file like this:

   on:  
     push:  
       branches:  
         - main #   
         - dev  # <-- I added this one  
     pull_request:  
       types: [opened, synchronize, reopened, closed]  
       branches:  
         - main #   
         - dev  # <-- I added this one  
     
   jobs:  
     build_and_deploy_job:  
       # (other normal stuff here - removed for brevity)  

While that change did create a deployment to my Azure static web app for the dev branch, it also made my main branch deployment use the dev branch's code.

Screenshot showing the result on Azure environments

The Azure overview page also confirms that it now uses the dev branch for production:

113511-2021-07-07-09-34-32.png

What is the proper way to accomplish my goal?

Azure Static Web Apps
Azure Static Web Apps
An Azure service that provides streamlined full-stack web app development.
851 questions
{count} votes

2 answers

Sort by: Most helpful
  1. ajkuma 24,971 Reputation points Microsoft Employee
    2021-07-13T20:25:30.507+00:00

    @Jason Frank , I received an update from our product team.

    Our product engineering team is working on a feature to push from other branches to a single SWA, however there is no concrete ETA on the release yet.

    Your feedback on this is very much appreciated. Kindly be assured that I have cascaded your feedback with our product team.

    Apologies for any inconvenience with this. Thanks for your patience.

    0 comments No comments

  2. Adam Diment 1 Reputation point
    2021-07-28T08:32:59.637+00:00

    I have the same requirement. I am upgrading one of my applications from a .net core cshtml web app to a blazor app. Currently for the .net core app I have 3 separate app services on azure (dev, staging, prod) versions. I use azure dev ops to push to each when a pr is merged from the three corresponding branches.

    To achieve the same thing with my blazor app, it looks like right now I would have to register 3 separate SWAs each registered to the corresponding dev/stage/prod branch? This basically makes the staging branch PR feature redundant for me though as things stand.

    Any news on when this feature will be available @ajkuma ?