Deploying from release branches #787
-
Is there a way that the static web apps Github action can be used with a github model that uses release branches? I do have a React app successfully deploying to a static web app. I've read the workflow yaml file in detail. Below I've listed the documents I've read - I think it's pretty extensive. From those documents and the "opinionated" approach that static web apps seems to take, it seems like I could get close with the Github action as it's currently implemented; but I don't think that the way we've typically managed releases and deployments is supported. When we have a release candidate, we create a release branch. We tag that branch. Then we do deployments to Test, UAT, and Production environments from that branch / tag. This works extremely well for us. It also means that "main" corresponds to our "Development" environment, not production. The shortest way I can think of to describe what is missing is a I'm comfortable creating workflows to be triggered by Github releases or by workflow dispatches. And those can be on arbitrary branches. But from the documentation, it seems that if the branch that triggers the workflow is "release/1.0", then the Github action would try to make that the URL suffix (which is likely invalid, at least as is). In addition, since "main" for us is for our "development" environment, we'd want to set the If anyone can point me in a direction that can make this work, that would be great. Static web apps really seems like a great solution for a common application architecture. But its "opinionated-ness" about how branches map to environments is a bit inflexible for us at this point. Thanks. Articles I've read: https://docs.microsoft.com/en-us/azure/static-web-apps/preview-environments https://docs.microsoft.com/en-us/azure/static-web-apps/branch-environments https://github.com/Azure/static-web-apps-deploy/blob/v1/action.yml https://docs.microsoft.com/en-us/learn/paths/azure-static-web-apps/ |
Beta Was this translation helpful? Give feedback.
Replies: 7 comments 10 replies
-
I think this might be possible today but need to think about it a bit. Do you have a sample workflow file for how you'd like it to work? Particularly interested in how the workflow is structured to progress the deployment to each environment. |
Beta Was this translation helpful? Give feedback.
-
Thank you very much for the response. We have 3 workflows. Development is triggered by merges to main. Test is triggered by Github releases. And UAT/Production is workflow dispatches. Here's what I think are the relevant portions of the workflows. Development (note the condition within the job)
Test
When we create the Github release, it's from a branch named UAT / Production
For UAT/Production, via a workflow dispatch, we enter the tag (as previously mentioned) and select the target environment. Let me know if this answers your question and/or if you'd like additional information. Thank you again for the courtesy of your reply. |
Beta Was this translation helpful? Give feedback.
-
This is a super interesting workflow @donniehale-awh! You can do this using the new To deploy your main branch to name: Deploy to development
on:
push:
branches:
- main
jobs:
build_and_deploy_job:
runs-on: ubuntu-latest
name: Build and Deploy Job
steps:
- uses: actions/checkout@v2
with:
submodules: true
- name: Build And Deploy
id: builddeploy
uses: Azure/static-web-apps-deploy@v1
with:
azure_static_web_apps_api_token: ${{ secrets.AZURE_STATIC_WEB_APPS_API_TOKEN }}
repo_token: ${{ secrets.GITHUB_TOKEN }}
action: "upload"
app_location: "/" # App source code path
api_location: "" # Api source code path - optional
output_location: "" # Built app content directory - optional
deployment_environment: "development" Deploy published releases to name: Deploy to test
on:
release:
types: [published]
jobs:
build_and_deploy_job:
runs-on: ubuntu-latest
name: Build and Deploy Job
steps:
- uses: actions/checkout@v2
with:
submodules: true
- name: Build And Deploy
id: builddeploy
uses: Azure/static-web-apps-deploy@v1
with:
azure_static_web_apps_api_token: ${{ secrets.AZURE_STATIC_WEB_APPS_API_TOKEN }}
repo_token: ${{ secrets.GITHUB_TOKEN }}
action: "upload"
app_location: "/" # App source code path
api_location: "" # Api source code path - optional
output_location: "" # Built app content directory - optional
deployment_environment: "test" Manually deploy a release to name: Deploy to uat/production
on:
workflow_dispatch:
inputs:
releaseTag:
description: 'Release tag (e.g. ABC-0.1.0)'
required: true
type: string
targetEnvironment:
description: 'Target Environment'
required: true
default: 'uat'
type: choice
options:
- uat
- production
jobs:
build_and_deploy_job:
runs-on: ubuntu-latest
name: Build and Deploy Job
steps:
- uses: actions/checkout@v2
with:
submodules: true
ref: ${{ github.event.inputs.releaseTag }}
- name: Build And Deploy
id: builddeploy
uses: Azure/static-web-apps-deploy@v1
with:
azure_static_web_apps_api_token: ${{ secrets.AZURE_STATIC_WEB_APPS_API_TOKEN }}
repo_token: ${{ secrets.GITHUB_TOKEN }}
action: "upload"
app_location: "/" # App source code path
api_location: "" # Api source code path - optional
output_location: "" # Built app content directory - optional
deployment_environment: "${{ github.event.inputs.targetEnvironment != 'production' && github.event.inputs.targetEnvironment || '' }}" See the workflow runs here: https://github.com/anthonychu/20220420-issue-staticwebapps-787/actions |
Beta Was this translation helpful? Give feedback.
-
@anthonychu This is fantastic! Thank you. Some follow-up questions:
I think that's what you're trying to address with this in the last workflow:
But the Thanks again! |
Beta Was this translation helpful? Give feedback.
-
Since I have your attention, a hopefully quick question: Is there any way to create an Azure Static Web App without being forced into the Github login (or without any up-front connection to a repository)? The Azure portal seems to require it, and the docs for the Azure CLI command seem to imply that it's required: https://docs.microsoft.com/en-us/cli/azure/staticwebapp?view=azure-cli-latest#az-staticwebapp-create Since I'm going to write our own workflows, it would be ideal if I could create the Azure Static Web App without any up-front repository connection, grab the management token, and use it with my workflows. Thanks again. |
Beta Was this translation helpful? Give feedback.
-
@anthonychu I tried using - name: Build and Deploy
id: builddeploy
uses: Azure/static-web-apps-deploy@v1
with:
azure_static_web_apps_api_token: ${{ secrets.AZURE_STATIC_WEB_APPS_API_TOKEN_AGREEABLE_OCEAN_0499C140F }}
repo_token: ${{ secrets.GITHUB_TOKEN }} # Used for Github integrations (i.e. PR comments)
action: "upload"
###### Repository/Build Configurations - These values can be configured to match your app requirements. ######
# For more information regarding Static Web App workflow configurations, please visit: https://aka.ms/swaworkflowconfig
app_location: "/Source/my-web" # App source code path
api_location: "" # Api source code path - optional
output_location: "build" # Built app content directory - optional
###### End of Repository/Build Configurations ######
app_build_command: npm run build:development
deployment_environment: dev I saw the warning you mentioned. The build worked correctly. I'm seeing the "development" version of the app. However, the environment "name" and "suffix" is "3", i.e. not "dev". In the "Environments" section of the Azure portal for the app, the "Name" of the preview deployment is "#3 - Devops/ow 5 web deployment". And the URL suffix is "-3" rather than "-dev". It looks like the "3" comes from the PR#. Is there a way to correct this? Is this what you would expect? From our previous discussions, I was expecting the environment to be named "dev" and the suffix to be "-dev". Thoughts? |
Beta Was this translation helpful? Give feedback.
-
Getting back to you, @anthonychu. Deployments are working to I wouldn't mind an answer to my earlier question about creating a new Azure Static Web App without being forced to immediately connect to a repository. See: #787 (comment) But other than that, the point of my question in this discussion has been answered. Thank you. |
Beta Was this translation helpful? Give feedback.
This is a super interesting workflow @donniehale-awh!
You can do this using the new
deployment_environment
input parameter (so new that we haven't documented it yet!).To deploy your main branch to
development
:https://github.com/anthonychu/20220420-issue-staticwebapps-787/blob/main/.github/workflows/deploy-to-development.yml