|
| 1 | +name: Test if React UI builds |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: ["main"] |
| 6 | + |
| 7 | + workflow_dispatch: |
| 8 | + |
| 9 | +jobs: |
| 10 | + build: |
| 11 | + runs-on: ubuntu-latest |
| 12 | + steps: |
| 13 | + - name: Checkout |
| 14 | + uses: actions/checkout@v4 |
| 15 | + - name: Detect package manager |
| 16 | + id: detect-package-manager |
| 17 | + working-directory: react-ui |
| 18 | + run: | |
| 19 | + if [ -f "${{ github.workspace }}/yarn.lock" ]; then |
| 20 | + echo "manager=yarn" >> $GITHUB_OUTPUT |
| 21 | + echo "command=install" >> $GITHUB_OUTPUT |
| 22 | + echo "runner=yarn" >> $GITHUB_OUTPUT |
| 23 | + exit 0 |
| 24 | + elif [ -f "${{ github.workspace }}/package.json" ]; then |
| 25 | + echo "manager=npm" >> $GITHUB_OUTPUT |
| 26 | + echo "command=ci" >> $GITHUB_OUTPUT |
| 27 | + echo "runner=npx --no-install" >> $GITHUB_OUTPUT |
| 28 | + exit 0 |
| 29 | + else |
| 30 | + echo "Unable to determine package manager" |
| 31 | + exit 1 |
| 32 | + fi |
| 33 | + - name: Setup Node |
| 34 | + uses: actions/setup-node@v3 |
| 35 | + with: |
| 36 | + node-version: "22" |
| 37 | + cache: ${{ steps.detect-package-manager.outputs.manager }} |
| 38 | + - name: Restore cache |
| 39 | + uses: actions/cache@v3 |
| 40 | + with: |
| 41 | + path: | |
| 42 | + .next/cache |
| 43 | + # Generate a new cache whenever packages or source files change. |
| 44 | + key: ${{ runner.os }}-nextjs-${{ hashFiles('**/package-lock.json', '**/yarn.lock') }}-${{ hashFiles('**.[jt]s', '**.[jt]sx') }} |
| 45 | + # If source files changed but packages didn't, rebuild from a prior cache. |
| 46 | + restore-keys: | |
| 47 | + ${{ runner.os }}-nextjs-${{ hashFiles('**/package-lock.json', '**/yarn.lock') }}- |
| 48 | + - name: Install dependencies |
| 49 | + working-directory: react-ui |
| 50 | + run: ${{ steps.detect-package-manager.outputs.manager }} ${{ steps.detect-package-manager.outputs.command }} |
| 51 | + - name: Build with Next.js |
| 52 | + working-directory: react-ui |
| 53 | + run: ${{ steps.detect-package-manager.outputs.runner }} next build |
| 54 | + - name: Static HTML export with Next.js |
| 55 | + working-directory: react-ui |
| 56 | + run: ${{ steps.detect-package-manager.outputs.runner }} next export |
0 commit comments