azuredeployment

App_location on deployment of a static webapp


for the first time I am trying to deploy a site on azure as a static web app, for the code I am using a private repository on github. The website is done using astrowind (https://github.com/onwidget/astrowind)

Locally everything works, giving the command npm run build creates a folder called dist inside which are all the files including index.html

The problem I am having is with the github actions, although the logs show that the dist folder is created, the azure action can never find it.

I have tried committing that folder as well, at which point the site is correctly published, but in this way I would have to run npm run build locally each time before committing. Of course I could do it that way but then I wouldn't understand what the problem is ;D

Here is the azure .yml file:

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@v3
        with:
          submodules: true
          lfs: false
      - 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 }}
          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: "dist" # App source code path
          api_location: "" # Api source code path - optional
          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'
    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 }}
          action: "close"

Although I put dist as the value of app_location, it does not work

Any advice?


Solution

  • Update App_location: '/' and output_location: 'dist' in the GitHub workflow(.yml file).

    I have deployed your project to Azure Static Web App from a Private repository on GitHub.

    GitHub Workflow:

    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@v3
            with:
              submodules: true
              lfs: false
          - 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_GRAY_PEBBLE_05B26DA0F }}
              repo_token: ${{ secrets.GITHUB_TOKEN }}
              action: "upload"
              app_location: "/" # App source code path
              api_location: "" # Api source code path - optional
              output_location: "dist" # Built app content directory - optional
    
      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_GRAY_PEBBLE_05B26DA0F }}
              action: "close"
    

    Deployment Status in GitHub:

    enter image description here

    Portal:

    enter image description here

    Output:

    enter image description here