GitHub Action
Deploy to Azure Storage
A GitHub Action that deploys a static website to an Azure Storage account.
- A GitHub Actions workflow that builds your static website.
- This action is not a static site generator tool—you need to have already set one up before using this, unless your repo already contains a folder of static files.
- An Azure Storage account with the "static website" feature enabled. (That is, it has a
$web
container.) - A SAS URL for your storage account with a long expiration time and write access to the account. Store this as a Secret in your repo.
Make sure you reference this Action in your workflow after the static site files have been generated. For example, you'll probably have some steps to run npm install
and npm run build
before this action.
Here's an example of how to use the action in your workflow:
uses: actions/deploy-to-azure-storage@v1
with:
source-path: out
sas-url: ${{ secrets.DEPLOY_SAS_URL }}
Then, you'd create a Secret in your repo with the name DEPLOY_SAS_URL
and a value like "https://mystorage.blob.core.windows.net/?sv=2020-...%3D
".
Required. The location of your built site files, relative to the root of the repo.
For example, for a Next.js site exported with next export
, the generated static files are in a folder called "out".
Required. Your SAS URL.
Important: Don't include a SAS URL in your workflow file directly, or anyone who reads your source code could access and change your storage account! Instead, store it in a Secret (see below) and reference it in your workflow.
- Open the Azure Portal and locate the storage account that you want to deploy your website to.
- Choose "Shared access signature" in the navigation bar.
- At minimum, choose:
- Allowed services; Blob
- Allowed resource types: all
- Allowed permissions: all
- Start and expiry date/time: something far in the future, like 10 years from now
- Click "Generate SAS and connection string".
- Copy the SAS URL (the last box in the UI).
- Open your repo in GitHub and go to Settings, then Secrets.
- Click "New secret".
- Name:
DEPLOY_SAS_URL
, or whatever you reference fromsas-url
- Value: (paste the SAS URL from step 5)
- Name:
- Click "Add secret".
When it executes, this action uses the AzCopy tool to sync your built files to your storage account.
It does so in two passes: first, it copies over all new and updated files. (A file is considered updated if its modified date is different.) Then, in the second pass, it removes any existing files that are not in the built source. Using this action will completely replace the contents of your storage account's $web
container.
name: Deploy website
on:
workflow_dispatch:
push:
branches: [ master ]
jobs:
build-and-deploy:
name: Build and deploy
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Install Node.js
uses: actions/setup-node@v1
with:
node-version: 12.x
- name: Build website
run: |
npm install
npm run build
- name: Deploy to Azure
uses: actions/deploy-to-azure-storage@v1
with:
source-path: out
sas-url: ${{ secrets.DEPLOY_SAS_URL }}