name: Build Web UI
on:
  workflow_call: {}
env:
  SAFE_CHAIN_MINIMUM_PACKAGE_AGE_HOURS: 360  # 15 days
jobs:

  build-webui:
    runs-on: ubuntu-latest

    steps:
      - name: Check out code
        uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
        with:
          fetch-depth: 0

      - name: Setup node
        uses: actions/setup-node@6044e13b5dc448c55e2357c09f80417699197238 # v6.2.0
        with:
          node-version-file: webui/.nvmrc
          cache: yarn
          cache-dependency-path: webui/yarn.lock

      - name: Setup safe-chain
        working-directory: ./webui
        run: |
          npm i -g @aikidosec/safe-chain
          safe-chain setup-ci

      - name: Build webui
        working-directory: ./webui
        run: |
          yarn install --ignore-scripts
          yarn build

      - name: Package webui
        run: |
          tar czvf webui.tar.gz ./webui/static/

      - name: Artifact webui
        uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6.0.0
        with:
          name: webui.tar.gz
          path: webui.tar.gz
          retention-days: 1
