|
| 1 | +name: Build templates |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + pull_request: |
| 6 | + types: [opened, reopened, synchronize] |
| 7 | + |
| 8 | +jobs: |
| 9 | + setup: |
| 10 | + runs-on: ubuntu-latest |
| 11 | + steps: |
| 12 | + - name: Checkout repository |
| 13 | + uses: actions/checkout@v4 |
| 14 | + |
| 15 | + - name: Get examples from directories |
| 16 | + id: get-matrix |
| 17 | + env: |
| 18 | + DIRS: '["templates"]' # Add more dirs here if needed |
| 19 | + run: | |
| 20 | + # Get examples from each directory |
| 21 | + all_examples=$(for dir in $(echo $DIRS | jq -r '.[]'); do |
| 22 | + for example in $(ls ./$dir/); do |
| 23 | + echo "{\"example\": \"$example\", \"path\": \"$dir\"}" |
| 24 | + done |
| 25 | + done | jq -s -c '.') |
| 26 | +
|
| 27 | + echo "matrix=$all_examples" >> $GITHUB_OUTPUT |
| 28 | +
|
| 29 | + outputs: |
| 30 | + matrix: ${{ steps.get-matrix.outputs.matrix }} |
| 31 | + |
| 32 | + build: |
| 33 | + needs: [setup] |
| 34 | + runs-on: ubuntu-latest |
| 35 | + strategy: |
| 36 | + max-parallel: 4 |
| 37 | + fail-fast: true |
| 38 | + matrix: |
| 39 | + include: ${{fromJson(needs.setup.outputs.matrix)}} |
| 40 | + env: |
| 41 | + EXAMPLE_DIR: ${{ github.workspace }}/dest/${{ matrix.example }} |
| 42 | + YARN_ENABLE_IMMUTABLE_INSTALLS: false |
| 43 | + |
| 44 | + steps: |
| 45 | + - name: Checkout repository |
| 46 | + uses: actions/checkout@v4 |
| 47 | + |
| 48 | + - name: Set up Node.js |
| 49 | + uses: actions/setup-node@v4 |
| 50 | + with: |
| 51 | + node-version: 20 |
| 52 | + |
| 53 | + - name: Set up Yarn |
| 54 | + |
| 55 | + |
| 56 | + - name: Cache dependencies |
| 57 | + uses: actions/cache@v4 |
| 58 | + with: |
| 59 | + path: | |
| 60 | + ${{ env.EXAMPLE_DIR }}/node_modules |
| 61 | + key: ${{ runner.os }}-modules-${{ matrix.example }}-${{ hashFiles('**/yarn.lock') }} |
| 62 | + restore-keys: | |
| 63 | + ${{ runner.os }}-modules-${{ matrix.example }}- |
| 64 | +
|
| 65 | + - name: Cache NextJS |
| 66 | + uses: actions/cache@v4 |
| 67 | + with: |
| 68 | + path: | |
| 69 | + ${{ env.EXAMPLE_DIR }}/.next/cache |
| 70 | + key: ${{ runner.os }}-nextjs-${{ matrix.example }}-${{ hashFiles( |
| 71 | + '${{ env.EXAMPLE_DIR }}/**/*.{js,jsx,ts,tsx}', |
| 72 | + '!${{ env.EXAMPLE_DIR }}/node_modules/**', |
| 73 | + '!${{ env.EXAMPLE_DIR }}/.next/**', |
| 74 | + '!${{ env.EXAMPLE_DIR }}/.yarn/**' |
| 75 | + ) }} |
| 76 | + restore-keys: | |
| 77 | + ${{ runner.os }}-nextjs-${{ matrix.example }}- |
| 78 | +
|
| 79 | + - name: Build example |
| 80 | + run: | |
| 81 | + echo "Building example: ${{ matrix.example }} from /${{ matrix.path }}" |
| 82 | +
|
| 83 | + mkdir -p ${{ env.EXAMPLE_DIR }} |
| 84 | + cp -r ./${{ matrix.path }}/${{ matrix.example }}/* ${{ env.EXAMPLE_DIR }}/ |
| 85 | + cd ${{ env.EXAMPLE_DIR }} |
| 86 | + ls -la |
| 87 | +
|
| 88 | + yarn install |
| 89 | + yarn build |
0 commit comments