Azure / Azure/static-web-apps-cli
swa-cli fails to copy `staticwebapp.config.json` into the `build` folder when running on a ci build (GitHub actions or Azure DevOps)
- Dominant language
- TypeScript
- Stars
- 668
- Forks
- 156
- PR merge metrics
- No merged PRs in 30d
Description
Before filing this issue, please ensure you're using the latest CLI by running `swa --version` and comparing to the latest version on [npm](https://www.npmjs.com/package/@azure/static-web-apps-cli).
> Issue verified on version `1.1.1` and `1.0.6`
**Are you accessing the CLI from the default port `:4280` ?**
- [ ] No, I am using a different port number (`--port`) and accessing the CLI from that port
- [X ] Yes, I am accessing the CLI from port `:4280`
> Make sure you are accessing the URL printed in the console when running `swa start`!
**ℹ️ NOTE: Make sure to enable debug logs when running any `swa` commands using `--verbose=silly`**
**Describe the bug**
swa-cli fails to copy `staticwebapp.config.json` into the `build` folder when running on a ci build (GitHub actions or Azure DevOps).
This is as part of `swa-cli deploy` and then the application has been previously built.
**To Reproduce**
Steps to reproduce the behavior:
- For a web-static app (I tried a python+flask+freezer and also a ReactNodejs app), create a `staticwebapp.config.json`.
- Make sure the `staticwebapp.config.json` is at the root path of the app-source. For example, for a React Node app structure:

- Build the application and produce the output folder that contains the static web app. It doesn't matter if you use `swa-cli deploy + swa-cli.config.json` to define how to build the app, or if you just have a script which generates the app. For the previous example, the `package.json` has a definition for the `build` script as `"build": "react-scripts build",`. So `rect-scripts` is taking care of creating a `build` folder with the contents of the static web app.
- After generation the `build` folder, run the `swa-cli deploy`. This is how I am calling it:
> Note the use of `npx` to invoke the `swa-cli`. I didn't try it installing the swa-cli globally and calling it directly*
```
npx -y @azure/static-web-apps-cli@1.1.1 deploy --tenant-id *** --subscription-id *** --resource-group *** --app-name *** --app-location ./src --output-location build --env default --no-use-keychain --deployment-token *** --verbose=silly
```
- When running this command locally (Windows/Linux/WSL2/Codespaces), the command works fine with the output:
```
Run exec: 'npx -y @azure/static-web-apps-cli@1.1.1 deploy --tenant-id **** --subscription-id **** --resource-group *** --app-name **** --app-location ./src/web --output-location build --env default --no-use-keychain --deployment-token --verbose=silly'
Welcome to Azure Static Web Apps CLI (1.1.1)
Getting config file options from swa-cli.config.json...
Config file does not exist at /home/vivazqu/workspace/build/swatest/swa-cli.config.json
Deploying front-end files from folder:
/home/vivazqu/workspace/build/swatest/src/web/build
Deployment token provided via flag
- --deployment-token:
Deploying to environment: default
Trying to read workflow config with values:
- appLocation: /home/vivazqu/workspace/build/swatest/src/web
- outputLocation: /home/vivazqu/workspace/build/swatest/src/web/build
- apiLocation:
- dataApiLocation:
No workflow config folder found at /home/vivazqu/workspace/build/swatest/src/web/.github/workflows
Validating user workflow config (BEFORE):
- appLocation: /home/vivazqu/workspace/build/swatest/src/web
- outputLocation: /home/vivazqu/workspace/build/swatest/src/web/build
- apiLocation:
- dataApiLocation:
Validating user workflow config (AFTER):
- appLocation: /home/vivazqu/workspace/build/swatest/src/web
- apiLocation:
- outputLocation: /home/vivazqu/workspace/build/swatest/src/web/build
- dataApiLocation:
Loading staticwebapp.config.json schema...
Schema loaded successfully from https://json.schemastore.org/staticwebapp.config.json
Compiling schema...
Reading content from staticwebapp.config.json...
Parsing staticwebapp.config.json...
Validating staticwebapp.config.json...
File validated successfully. Continuing with configuration!
Content parsed successfully
Found configuration file:
/home/vivazqu/workspace/build/swatest/src/web/staticwebapp.config.json
Deploying project to Azure Static Web Apps...
Fetching release metadata for version: stable. Please wait...
- version: stable
- buildId: 1.0.022851
- publishDate: 2023-04-04T18:55:18.5999465Z
- files:
- linux-x64:
- url: https://swalocaldeploy.azureedge.net/downloads/1.0.022851/linux/StaticSitesClient
- sha: dbbf2785549d2e002f69057c54d4df378c1e52e5e564d484f6871440ef336689
- win-x64:
- url: https://swalocaldeploy.azureedge.net/downloads/1.0.022851/windows/StaticSitesClient.exe
- sha: a3d37f5793ce433ba8cd7743285d9e6f9c0174c2d09c530483a6a50f8a448637
- osx-x64:
- url: https://swalocaldeploy.azureedge.net/downloads/1.0.022851/macOS/StaticSitesClient
- sha: 9de09ad2b000c6943a8103c323e95a0fb8fea1a3c2bd406859cc59b4b6cec548
Local client binary is up to date. Skipping download.
Deploying using /home/vivazqu/.swa/deploy/1.0.022851/StaticSitesClient@1.0.022851
Deploying using the following options:
- env:
- SWA_CLI_DEBUG: silly
- SWA_RUNTIME_WORKFLOW_LOCATION:
- SWA_RUNTIME_CONFIG_LOCATION: /home/vivazqu/workspace/build/swatest/src/web
- SWA_RUNTIME_CONFIG: /home/vivazqu/workspace/build/swatest/src/web/staticwebapp.config.json
- SWA_CLI_VERSION: 1.1.1
- SWA_CLI_DEPLOY_DRY_RUN: false
- SWA_CLI_DEPLOY_BINARY: /home/vivazqu/.swa/deploy/1.0.022851/StaticSitesClient@1.0.022851
- DEPLOYMENT_ACTION: upload
- DEPLOYMENT_PROVIDER: SwaCli
- REPOSITORY_BASE: /home/vivazqu/workspace/build/swatest/src/web
- SKIP_APP_BUILD: true
- SKIP_API_BUILD: true
- DEPLOYMENT_TOKEN:
- APP_LOCATION: /home/vivazqu/workspace/build/swatest/src/web/build
- API_LOCATION:
- DATA_API_LOCATION:
- CONFIG_FILE_LOCATION: /home/vivazqu/workspace/build/swatest/src/web
- VERBOSE: true
- DEPLOYMENT_ENVIRONMENT: default
- Preparing deployment. Please wait...
ℹ DeploymentId: f5755579-8d67-4aef-af47-d5d36603f1cb
ℹ Preparing deployment. Please wait...
ℹ Verbose logging enabled
ℹ Build timeout not specified, defaulting to 15 minutes
ℹ App Directory Location: '/home/vivazqu/workspace/build/swatest/src/web/build' was found.
ℹ config_file_location: config file '/home/vivazqu/workspace/build/swatest/src/web/staticwebapp.config.json' was found.
ℹ Looking for event info
ℹ Event info parsed from action options.
ℹ Could not get repository branch. Proceeding
ℹ Could not get repository url. Proceeding
ℹ Skipping step to build /home/vivazqu/workspace/build/swatest/src/web/build with Oryx
ℹ Didn't find Oryx manifest file under location: /home/vivazqu/workspace/build/swatest/f5755579-8d67-4aef-af47-d5d36603f1cb-swa-oryx/app-manifest/oryx-manifest.toml
ℹ Determined default file to be: index.html
ℹ Using 'staticwebapp.config.json' file for configuration information, 'routes.json' will be ignored.
ℹ Copying 'staticwebapp.config.json' to build output
ℹ No Api directory specified. Azure Functions will not be created.
ℹ Either no Api directory was specified, or the specified directory was not found. Azure Functions will not be created.
ℹ Zipping App Artifacts
ℹ App Zip will be created from directory: /home/vivazqu/workspace/build/swatest/src/web/build
ℹ Done Zipping App Artifacts
ℹ Uploading build artifacts.
ℹ Skipping function upload as functions are identical to last successful deployment.
ℹ Finished Upload. Polling on deployment.
ℹ Status: InProgress. Time: 0.2184483(s)
ℹ Status: Succeeded. Time: 15.3757374(s)
ℹ Deployment Complete :)
ℹ Thanks for using Azure Static Web Apps!
```
- But when the command runs from a CI pipeline, the command fails with the next output
```
2023/04/20 01:52:35 command_runner.go:94: Run exec: 'npx -y @azure/static-web-apps-cli@1.1.1 deploy --tenant-id *** --subscription-id *** --resource-group rg-*** --app-name **** --app-location ./src/web --output-location build --env default --no-use-keychain --deployment-token --verbose=silly'
Welcome to Azure Static Web Apps CLI (1.1.1)
Getting config file options from swa-cli.config.json...
Config file does not exist at /__w/swatest/swatest/swa-cli.config.json
Deploying front-end files from folder:
/__w/swatest/swatest/src/web/build
Deployment token provided via flag
- --deployment-token:
Deploying to environment: default
Trying to read workflow config with values:
- appLocation: /__w/swatest/swatest/src/web
- outputLocation: /__w/swatest/swatest/src/web/build
- apiLocation:
- dataApiLocation:
No workflow config folder found at /__w/swatest/swatest/src/web/.github/workflows
Validating user workflow config (BEFORE):
- appLocation: /__w/swatest/swatest/src/web
- outputLocation: /__w/swatest/swatest/src/web/build
- apiLocation:
- dataApiLocation:
Validating user workflow config (AFTER):
- appLocation: /__w/swatest/swatest/src/web
- apiLocation:
- outputLocation: /__w/swatest/swatest/src/web/build
- dataApiLocation:
Loading staticwebapp.config.json schema...
Schema loaded successfully from https://json.schemastore.org/staticwebapp.config.json
Compiling schema...
Reading content from staticwebapp.config.json...
Parsing staticwebapp.config.json...
Validating staticwebapp.config.json...
File validated successfully. Continuing with configuration!
Content parsed successfully
Found configuration file:
/__w/swatest/swatest/src/web/staticwebapp.config.json
Deploying project to Azure Static Web Apps...
Could not find StaticSitesClient local binary
Fetching release metadata for version: stable. Please wait...
- version: stable
- buildId: 1.0.022851
- publishDate: 2023-04-04T18:55:18.5999465Z
- files:
- linux-x64:
- url: https://swalocaldeploy.azureedge.net/downloads/1.0.022851/linux/StaticSitesClient
- sha: dbbf2785549d2e002f69057c54d4df378c1e52e5e564d484f6871440ef33[668](https://github.com/vhvb1989/swatest/actions/runs/4749392959/jobs/8436613183#step:7:669)9
- win-x64:
- url: https://swalocaldeploy.azureedge.net/downloads/1.0.022851/windows/StaticSitesClient.exe
- sha: a3d37f5793ce433ba8cd7743285d9e6f9c0174c2d09c530483a6a50f8a448637
- osx-x64:
- url: https://swalocaldeploy.azureedge.net/downloads/1.0.022851/macOS/StaticSitesClient
- sha: 9de09ad2b000c6943a8103c323e95a0fb8fea1a3c2bd40[685](https://github.com/vhvb1989/swatest/actions/runs/4749392959/jobs/8436613183#step:7:686)9cc59b4b6cec548
Checksum match: dbbf2785549d2e002f69057c54d4df378c1e52e5e564d484f[687](https://github.com/vhvb1989/swatest/actions/runs/4749392959/jobs/8436613183#step:7:688)1440ef336[689](https://github.com/vhvb1989/swatest/actions/runs/4749392959/jobs/8436613183#step:7:690)
Saved binary to /github/home/.swa/deploy/1.0.022851/StaticSitesClient
Saved metadata to /github/home/.swa/deploy/StaticSitesClient.json
Deploying using /github/home/.swa/deploy/1.0.022851/StaticSitesClient@1.0.022851
Deploying using the following options:
- env:
- SWA_CLI_DEBUG: silly
- SWA_RUNTIME_WORKFLOW_LOCATION:
- SWA_RUNTIME_CONFIG_LOCATION: /__w/swatest/swatest/src/web
- SWA_RUNTIME_CONFIG: /__w/swatest/swatest/src/web/staticwebapp.config.json
- SWA_CLI_VERSION: 1.1.1
- SWA_CLI_DEPLOY_DRY_RUN: false
- SWA_CLI_DEPLOY_BINARY: /github/home/.swa/deploy/1.0.022851/StaticSitesClient@1.0.022851
- DEPLOYMENT_ACTION: upload
- DEPLOYMENT_PROVIDER: SwaCli
- REPOSITORY_BASE: /__w/swatest/swatest/src/web
- SKIP_APP_BUILD: true
- SKIP_API_BUILD: true
- DEPLOYMENT_TOKEN:
- APP_LOCATION: /__w/swatest/swatest/src/web/build
- API_LOCATION:
- DATA_API_LOCATION:
- CONFIG_FILE_LOCATION: /__w/swatest/swatest/src/web
- VERBOSE: true
- DEPLOYMENT_ENVIRONMENT: default
- Downloading https://swalocaldeploy.azureedge.net/downloads/1.0.022851/linux/StaticSitesClient@1.0.022851
[swa] ✔ Downloading https://swalocaldeploy.azureedge.net/downloads/1.0.022851/linux/StaticSitesClient@1.0.022851
- Preparing deployment. Please wait...
ℹ DeploymentId: d197b[751](https://github.com/vhvb1989/swatest/actions/runs/4749392959/jobs/8436613183#step:7:752)-65f6-4481-b555-1c3009bb407d
ℹ Preparing deployment. Please wait...
ℹ Verbose logging enabled
ℹ Build timeout not specified, defaulting to 15 minutes
ℹ App Directory Location: '/__w/swatest/swatest/src/web/build' was found.
ℹ config_file_location: config file '/__w/swatest/swatest/src/web/staticwebapp.config.json' was found.
ℹ Looking for event info
ℹ Event info parsed from action options.
ℹ Could not get repository branch. Proceeding
ℹ Could not get repository url. Proceeding
ℹ Skipping step to build /__w/swatest/swatest/src/web/build with Oryx
ℹ Didn't find Oryx manifest file under location: /__w/swatest/swatest/d197b751-65f6-4481-b555-1c3009bb407d-swa-oryx/app-manifest/oryx-manifest.toml
ℹ Determined default file to be: index.html
ℹ Using 'staticwebapp.config.json' file for configuration information, 'routes.json' will be ignored.
✖ An unknown exception has occurred
ℹ
ℹ For further information, please visit the Azure Static Web Apps documentation at https://docs.microsoft.com/en-us/azure/static-web-apps/
ℹ If you believe this behavior is unexpected, please raise a GitHub issue at https://github.com/azure/static-web-apps/issues/
```
> Note: Comparing both outputs, the CI pipeline is failing on the step that should copy the `staticwebapp.config.json` into the build folder...
**Expected behavior**
swa-cli deploy should work the same locally as running inside a Github action or Azure devops pipeline.
**Additional context**
Notes:
- Updating the `build` script to manually copy the `staticwebapp.config.json` to the build folder before calling `swa-cli` deploy works !!!
That is currently my workaround, but I need to manually handle this for every app.
I updated the `build` script to call `cp staticwebapp.config.json build/staticwebapp.config.json` after creating the build.
Contributor guide
Assessment
This issue has not been assessed yet.