This guide explains how to use and configure the Azure Static Web Apps CI/CD workflow. This workflow automates the deployment of your website to Azure Static Web Apps.
Prerequisites
- An Azure Static Web Apps instance
- Repository variables including
AZURE_STATIC_WEB_APPS_API_TOKENconfigured in your GitHub repository- This can be found in your Azure Static Web Apps resource
- Add it under repository Settings → Secrets and variables → Actions → Variables
Directory Structure
.
├── .github/
│ └── workflows/
│ └── deploy-app.yml
└── website/ # Source code location
└── public/ # Build output location
Workflow Details
Build and Deploy Job
This job handles the main deployment process:
-
Checkout: Clones your repository with submodules
- uses: actions/checkout@v3 with: submodules: true lfs: false -
Build and Deploy: Uses Azure’s official action
- uses: Azure/static-web-apps-deploy@v1 with: azure_static_web_apps_api_token: ${{ vars.AZURE_STATIC_WEB_APPS_API_TOKEN }} repo_token: ${{ secrets.GITHUB_TOKEN }} action: "upload" app_location: "/website" output_location: "public"
app_location: Points to/websitedirectory containing source codeoutput_location: Points topublicdirectory containing built filesapi_location: Currently not used (empty string)
Close Pull Request Job
The _Close Pull Request job automatically closes the pull request that triggered the build and deployment. When a pull request is opened, the Azure Static Web Apps GitHub Action builds and deploys the app to a staging environment. Afterward, the Close Pull Request job checks if the pull request is still open and closes it with a completion message.
- uses: Azure/static-web-apps-deploy@v1
with:
azure_static_web_apps_api_token: ${{ vars.AZURE_STATIC_WEB_APPS_API_TOKEN }}
action: "close"