You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Github Actions部署Azure静态Web App前复制staticwebapp.config.json

解决方案:在Azure Static Web Apps部署前复制staticwebapp.config.json到输出目录

要实现构建完成后、发布前将根目录的staticwebapp.config.json复制到output_location(即storybook-static)目录,只需修改Workflow中的构建命令,将复制操作追加到构建命令之后即可:

修改Build And Deploy步骤里的CUSTOM_BUILD_COMMAND环境变量,把构建命令和复制命令用&&串联,确保构建完成后自动执行复制:

name: Azure Static Web Apps CI/CD

on:
  push:
    branches:
      - master
  pull_request:
    types: [opened, synchronize, reopened, closed]
    branches:
      - master

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@v3
        with:
          submodules: true
      - name: Install Node.js
        uses: actions/setup-node@v3
        with:
          node-version: 18

      - uses: pnpm/action-setup@v2.2.4
        name: Install pnpm
        id: pnpm-install
        with:
          version: 7
          run_install: false

      - name: Get pnpm store directory
        id: pnpm-cache
        run: |
          echo "STORE_PATH=$(pnpm store path)" >> $GITHUB_OUTPUT

      - uses: actions/cache@v3
        name: Setup pnpm cache
        with:
          path: ${{ steps.pnpm-cache.outputs.STORE_PATH }}
          key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
          restore-keys: |
            ${{ runner.os }}-pnpm-store-

      - name: Install dependencies
        run: pnpm install

      - 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_HAPPY_BEACH_0AD8A764G  }}
          repo_token: ${{ secrets.GITHUB_TOKEN }}
          action: "upload"
          app_location: "/"
          api_location: ""
          output_location: "storybook-static"
        env:
          NODE_VERSION: 18.x
          PRE_BUILD_COMMAND: npm install -g pnpm
          # 修改此处,追加复制文件命令
          CUSTOM_BUILD_COMMAND: pnpm run storybook:build && cp staticwebapp.config.json storybook-static/

  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_HAPPY_BEACH_0AD8A764G }}
          action: "close"

原理说明

Azure/static-web-apps-deploy@v1会按顺序执行PRE_BUILD_COMMAND、CUSTOM_BUILD_COMMAND,之后将output_location目录下的所有内容上传部署到Azure Static Web Apps。通过在构建命令后追加cp staticwebapp.config.json storybook-static/,能确保配置文件被复制到构建输出目录,最终被一起部署。

内容的提问来源于stack exchange,提问作者arunmmanoharan

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.31 03:09:26