Skip to content

Commit 50dc271

Browse files
ci(deploy): modernize Azure Static Web Apps workflow
Add concurrency control, Node.js 22 setup, explicit build step with Clarity support, and skip_app_build/skip_api_build flags. Remove OIDC token workflow in favor of prebuilt deployment. Upgrade actions/checkout to v4. Co-Authored-By: Hagicode <noreply@hagicode.com> Signed-off-by: newbe36524 <newbe36524@qq.com>
1 parent 9b63d20 commit 50dc271

1 file changed

Lines changed: 69 additions & 58 deletions

File tree

Lines changed: 69 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,69 @@
1-
name: Azure Static Web Apps CI/CD
2-
3-
on:
4-
push:
5-
branches:
6-
- main
7-
pull_request:
8-
types: [opened, synchronize, reopened, closed]
9-
branches:
10-
- main
11-
12-
jobs:
13-
build_and_deploy_job:
14-
if: github.event_name == 'push' || (github.event_name == 'pull_request' && github.event.action != 'closed')
15-
runs-on: ubuntu-latest
16-
name: Build and Deploy Job
17-
permissions:
18-
id-token: write
19-
contents: read
20-
steps:
21-
- uses: actions/checkout@v3
22-
with:
23-
submodules: true
24-
lfs: false
25-
- name: Install OIDC Client from Core Package
26-
run: npm install @actions/core@1.6.0 @actions/http-client
27-
- name: Get Id Token
28-
uses: actions/github-script@v6
29-
id: idtoken
30-
with:
31-
script: |
32-
const coredemo = require('@actions/core')
33-
return await coredemo.getIDToken()
34-
result-encoding: string
35-
- name: Build And Deploy
36-
id: builddeploy
37-
uses: Azure/static-web-apps-deploy@v1
38-
with:
39-
azure_static_web_apps_api_token: ${{ secrets.AZURE_STATIC_WEB_APPS_API_TOKEN_AGREEABLE_STONE_04924C800 }}
40-
action: "upload"
41-
###### Repository/Build Configurations - These values can be configured to match your app requirements. ######
42-
# For more information regarding Static Web App workflow configurations, please visit: https://aka.ms/swaworkflowconfig
43-
app_location: "/" # App source code path
44-
api_location: "" # Api source code path - optional
45-
output_location: "" # Built app content directory - optional
46-
github_id_token: ${{ steps.idtoken.outputs.result }}
47-
###### End of Repository/Build Configurations ######
48-
49-
close_pull_request_job:
50-
if: github.event_name == 'pull_request' && github.event.action == 'closed'
51-
runs-on: ubuntu-latest
52-
name: Close Pull Request Job
53-
steps:
54-
- name: Close Pull Request
55-
id: closepullrequest
56-
uses: Azure/static-web-apps-deploy@v1
57-
with:
58-
action: "close"
1+
name: Azure Static Web Apps CI/CD
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
types: [opened, synchronize, reopened, closed]
9+
branches:
10+
- main
11+
12+
concurrency:
13+
group: azure-static-web-apps-agreeable-stone-04924c800-${{ github.event.pull_request.number || github.ref }}
14+
cancel-in-progress: true
15+
16+
permissions:
17+
contents: read
18+
pull-requests: write
19+
20+
env:
21+
NODE_VERSION: "22"
22+
23+
jobs:
24+
build_and_deploy_job:
25+
if: github.event.action != 'closed'
26+
runs-on: ubuntu-latest
27+
name: Build and Deploy Job
28+
steps:
29+
- uses: actions/checkout@v4
30+
with:
31+
submodules: true
32+
lfs: false
33+
34+
- name: Setup Node.js
35+
uses: actions/setup-node@v4
36+
with:
37+
node-version: ${{ env.NODE_VERSION }}
38+
cache: npm
39+
40+
- name: Install dependencies
41+
run: npm ci
42+
43+
- name: Build docs
44+
run: npm run build:ci
45+
env:
46+
CLARITY_PROJECT_ID: ${{ secrets.CLARITY_PROJECT_ID }}
47+
48+
- name: Build And Deploy
49+
id: builddeploy
50+
uses: Azure/static-web-apps-deploy@v1
51+
with:
52+
azure_static_web_apps_api_token: ${{ secrets.AZURE_STATIC_WEB_APPS_API_TOKEN_AGREEABLE_STONE_04924C800 }}
53+
repo_token: ${{ secrets.GITHUB_TOKEN }}
54+
action: upload
55+
app_location: dist
56+
skip_app_build: true
57+
skip_api_build: true
58+
59+
close_pull_request_job:
60+
if: github.event_name == 'pull_request' && github.event.action == 'closed'
61+
runs-on: ubuntu-latest
62+
name: Close Pull Request Job
63+
steps:
64+
- name: Close Pull Request
65+
id: closepullrequest
66+
uses: Azure/static-web-apps-deploy@v1
67+
with:
68+
azure_static_web_apps_api_token: ${{ secrets.AZURE_STATIC_WEB_APPS_API_TOKEN_AGREEABLE_STONE_04924C800 }}
69+
action: close

0 commit comments

Comments
 (0)