diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..4ecd21d --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,58 @@ +name: Build and Test (Vite React) + +on: + push: + branches: [ GitWorkflow ] + pull_request: + branches: [ GitWorkflow ] + +permissions: + contents: read + +jobs: + build: + runs-on: ubuntu-latest + + defaults: + run: + working-directory: ./Esercizi/GithubWorkflow/GitWorkflow + + steps: + # 1️⃣ Checkout repository + - name: Checkout code + uses: actions/checkout@v5 + + # Cache node modules + - name: Cache node modules + uses: actions/cache@v3 + with: + path: ./Esercizi/GithubWorkflow/GitWorkflow/node_modules + key: ${{ runner.os }}-node-${{ hashFiles('Esercizi/GithubWorkflow/GitWorkflow/package-lock.json') }} + restore-keys: | + ${{ runner.os }}-node- + + # 2️⃣ Setup Node.js + - name: Setup Node.js + uses: actions/setup-node@v5 + with: + node-version: '22' + + # 3️⃣ Install dependencies + - name: Install dependencies + run: npm ci + working-directory: ./Esercizi/GithubWorkflow/GitWorkflow + + # 4️⃣ Build project + - name: Build project + run: npm run build + + # 5️⃣ Run tests (solo se presenti) + - name: Run tests + run: npm test --if-present + + # 6️⃣ Upload build artifact (cartella dist) + - name: Upload build output + uses: actions/upload-artifact@v4 + with: + name: vite-dist + path: ./Esercizi/GithubWorkflow/GitWorkflow/dist