Azure / static-web-apps-cli

Azure Static Web Apps CLI ✨
https://aka.ms/swa/cli-local-development
MIT License
585 stars 112 forks source link

swa-cli fails to copy `staticwebapp.config.json` into the `build` folder when running on a ci build (GitHub actions or Azure DevOps) #688

Open vhvb1989 opened 1 year ago

vhvb1989 commented 1 year ago

Before filing this issue, please ensure you're using the latest CLI by running swa --version and comparing to the latest version on npm.

Issue verified on version 1.1.1 and 1.0.6

Are you accessing the CLI from the default 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:

image

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
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 <redacted> --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: <hidden>

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: <undefined>
 - dataApiLocation: <undefined>
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: <undefined>
 - dataApiLocation: <undefined>
Validating user workflow config (AFTER):
 - appLocation: /home/vivazqu/workspace/build/swatest/src/web
 - apiLocation: <undefined>
 - outputLocation: /home/vivazqu/workspace/build/swatest/src/web/build
 - dataApiLocation: <undefined>
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: <undefined>
  - 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: <hidden>
  - APP_LOCATION: /home/vivazqu/workspace/build/swatest/src/web/build
  - API_LOCATION: <undefined>
  - DATA_API_LOCATION: <undefined>
  - 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!
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 <redacted> --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: <hidden>

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: <undefined>
 - dataApiLocation: <undefined>
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: <undefined>
 - dataApiLocation: <undefined>
Validating user workflow config (AFTER):
 - appLocation: /__w/swatest/swatest/src/web
 - apiLocation: <undefined>
 - outputLocation: /__w/swatest/swatest/src/web/build
 - dataApiLocation: <undefined>
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: <undefined>
  - 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: <hidden>
  - APP_LOCATION: /__w/swatest/swatest/src/web/build
  - API_LOCATION: <undefined>
  - DATA_API_LOCATION: <undefined>
  - 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:

rajeshkamal5050 commented 1 year ago

Any updates on this @Reshmi-Sriram ?

Reshmi-Sriram commented 1 year ago

Apologies, and Thanks for reporting this issue @vhvb1989 ! While the team works on this solution, we recommend to stick to the workaround you suggested by manually adding the staticwebapp.config.json into the build folder. cc// @thomasgauvin

rajeshkamal5050 commented 10 months ago

@Reshmi-Sriram Do you have any updates/ETA on the fix?

rajeshkamal5050 commented 4 months ago

@Reshmi-Sriram Do you have any updates/ETA on the fix?