Skip to content

Instantly share code, notes, and snippets.

@justinyoo
Last active November 30, 2021 06:28
Show Gist options
  • Save justinyoo/3f8de0ebaff5bdd7e41c961ed37b5b53 to your computer and use it in GitHub Desktop.
Save justinyoo/3f8de0ebaff5bdd7e41c961ed37b5b53 to your computer and use it in GitHub Desktop.
Refactoring GitHub Actions Workflow for Azure Static WebApps
### original workflow: azure-static-web-apps-xxxx-xxxx-xxxx.yml ###
name: Azure Static Web Apps CI/CD
on:
push:
branches:
- main
pull_request:
types: [opened, synchronize, reopened, closed]
branches:
- main
jobs:
build_and_deploy_job:
if: github.event_name == 'push' || (github.event_name == 'pull_request' && github.event.action != 'closed')
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_XXXX_XXXX_XXXX }}
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: "webapp" # App source code path
api_location: "apiapp" # Api source code path - optional
output_location: "wwwroot" # Built app content directory - optional
###### End of Repository/Build Configurations ######
close_pull_request_job:
if: github.event_name == 'pull_request' && github.event.action == 'closed'
runs-on: ubuntu-latest
name: Close Pull Request Job
steps:
- name: Close Pull Request
id: closepullrequest
uses: Azure/static-web-apps-deploy@v1
with:
azure_static_web_apps_api_token: ${{ secrets.AZURE_STATIC_WEB_APPS_API_TOKEN_XXXX_XXXX_XXXX }}
action: "close"
### reusable workflow: build-aswa.yaml ###
name: Azure Static Web Apps
jobs:
build_and_deploy_job:
if: github.event_name == 'push' || (github.event_name == 'pull_request' && github.event.action != 'closed')
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_XXXX_XXXX_XXXX }}
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: "webapp" # App source code path
api_location: "apiapp" # Api source code path - optional
output_location: "dist" # Built app content directory - optional
###### End of Repository/Build Configurations ######
close_pull_request_job:
if: github.event_name == 'pull_request' && github.event.action == 'closed'
runs-on: ubuntu-latest
name: Close Pull Request Job
steps:
- name: Close Pull Request
id: closepullrequest
uses: Azure/static-web-apps-deploy@v1
with:
azure_static_web_apps_api_token: ${{ secrets.AZURE_STATIC_WEB_APPS_API_TOKEN_XXXX_XXXX_XXXX }}
action: "close"
### reusable workflow: build-aswa.yaml ###
name: Azure Static Web Apps
jobs:
build_and_deploy_job:
# if: github.event_name == 'push' || (github.event_name == 'pull_request' && github.event.action != 'closed')
if: inputs.event_name == 'push' || (inputs.event_name == 'pull_request' && inputs.event_action != 'closed')
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_XXXX_XXXX_XXXX }}
azure_static_web_apps_api_token: ${{ secrets.aswa_token }}
# repo_token: ${{ secrets.GITHUB_TOKEN }} # Used for Github integrations (i.e. PR comments)
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: "webapp" # App source code path
app_location: ${{ inputs.app_location }} # App source code path
# api_location: "apiapp" # Api source code path - optional
api_location: ${{ inputs.api_location }} # Api source code path - optional
# output_location: "dist" # Built app content directory - optional
output_location: ${{ inputs.output_location }} # Built app content directory - optional
###### End of Repository/Build Configurations ######
close_pull_request_job:
# if: github.event_name == 'pull_request' && github.event.action == 'closed'
if: inputs.event_name == 'pull_request' && inputs.event_action == 'closed'
runs-on: ubuntu-latest
name: Close Pull Request Job
steps:
- name: Close Pull Request
id: closepullrequest
uses: Azure/static-web-apps-deploy@v1
with:
# azure_static_web_apps_api_token: ${{ secrets.AZURE_STATIC_WEB_APPS_API_TOKEN_XXXX_XXXX_XXXX }}
azure_static_web_apps_api_token: ${{ secrets.aswa_token }}
action: "close"
### reusable workflow: build-aswa.yaml ###
name: Azure Static Web Apps
on:
workflow_call:
inputs:
event_name:
required: true
type: string
event_action:
required: true
type: string
app_location:
required: true
type: string
api_location:
required: true
type: string
output_location:
required: true
type: string
secrets:
github_token:
required: true
aswa_token:
required: true
jobs:
...
### caller workflow: azure-static-web-apps-xxxx-xxxx-xxxx.yml ###
name: Azure Static Web Apps CI/CD
on:
push:
branches:
- main
pull_request:
types: [opened, synchronize, reopened, closed]
branches:
- main
jobs:
call_aswa_flow:
uses: <org_name>/<repo_name>/.github/workflows/build-aswa.yaml@main
with:
event_name: ${{ github.event_name }}
event_action: ${{ github.event.action }}
app_location: "webapp"
api_location: "apiapp"
output_location: "dist"
secrets:
github_token: ${{ secrets.GITHUB_TOKEN }}
aswa_token: ${{ secrets.AZURE_STATIC_WEB_APPS_API_TOKEN_XXXX_XXXX_XXXX }}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment