We are using "Bring your own functions" for our Azure Static Web app linking to Azure Functions app.
We use a staging slot for the functions so that we can deploy and swap for zero downtime.
We also use the Preview environment feature of Static Web apps so that we can see pre-productions pull request code before it's merged - but this uses the same (default) slot as the production environment.
We would like to be able to use the staging slot for preview environments so that we can preview both the pre-production Static Web app and pre-production functions.
I was hoping to see a "slot" parameter in the GitHub action to build and deploy the Static Web app but there doesn't seem to be one.
Does anyone know if this is possible and how best to achieve it? Thank you!
If I understand correctly, you are trying to change the URL of Azure Function App which your static web app communicates to. i.e. If Production, then use the URL for production azure function deployment and if preview environment then use the URL for azure function deployed in slot.
Github action may not have a built-in way for doing this for static web app deployment. But I believe you can achieve this by replacing the url in your code files dynamically based on the trigger or branch.
Lets say that you have a .js file which has the URL to be used for azure function app. Then you could have an action in your pipeline which will check the run is triggered for which branch/PR, and then change that URL to azure function slot URL and if it is triggered for a release branch, set the URL to production URL of azure function app.
Below is a simple GitHub Actions workflow that demonstrates this idea:
.js
file.Suppose your
.js
file has a placeholder like this:Below GitHub Actions workflow that replaces this placeholder:
In the example above:
main
(production),develop
(staging), andfeature/*
(feature branches).%%AZURE_FUNCTION_URL%%
in all.js
files with the corresponding Azure Function URL usingsed
.This is a basic example to demonstrate the concept.