0

I have an Azure Static Web App built using Github actions. I have a staticwebapp.config.json in the root folder of my project. Once github action builds the app using Azure/static-web-apps-deploy@v1, I want to copy the above file and put it inside the output_location before publishing it. Please advice.

Here is my yml:

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 }} # 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: "/" # App source code path
          api_location: "" # Api source code path - optional
          output_location: "storybook-static" # Built app content directory - optional
        env:
          NODE_VERSION: 18.x
          PRE_BUILD_COMMAND: npm install -g pnpm
          CUSTOM_BUILD_COMMAND: pnpm run storybook:build
          ###### 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_HAPPY_BEACH_0AD8A764G }}
          action: "close"
Harshitha
  • 3,784
  • 2
  • 4
  • 9
arunmmanoharan
  • 2,535
  • 2
  • 29
  • 60

1 Answers1

0

In .yml file, before Build And Deploy, we need to write a step to copy the file from root folder.

  • Navigate to the GitHub Repository => .github/workflows folder => Click on your .yml and edit it.

enter image description here

output_location: "storybook-static" # Built app content directory - >optional
  • Before copying the file, make sure the output_location exists.

  • As it is an optional parameter, sometimes we may not provide it.

Add the below steps to copy the file to Output folder.

Thanks @Dillion Megida for the command

- name: Copy a file from root folder to build folder
  run: cp staticwebapp.config.json ${{ secrets.AZURE_STATIC_WEB_APPS_LOCATION }}/filepath
Harshitha
  • 3,784
  • 2
  • 4
  • 9
  • Also refer this [SO Thread](https://stackoverflow.com/questions/73913104/azure-static-web-app-copying-staticwebapp-config-json-to-output-directory) and [MSDoc](https://learn.microsoft.com/en-us/azure/static-web-apps/build-configuration?tabs=github-actions#skip-building-front-end-app) for more details. – Harshitha Feb 20 '23 at 13:26