|  | 
| 9 | 9 | jobs: | 
| 10 | 10 |   build: | 
| 11 | 11 |     runs-on: ubuntu-latest | 
| 12 |  | -    permissions: | 
| 13 |  | -      contents: read | 
| 14 |  | - | 
| 15 | 12 |     steps: | 
| 16 | 13 |       - uses: actions/checkout@v4 | 
| 17 |  | - | 
|  | 14 | +       | 
| 18 | 15 |       - name: Setup Node.js | 
| 19 | 16 |         uses: actions/setup-node@v4 | 
| 20 | 17 |         with: | 
| 21 |  | -          node-version: '20.x' | 
|  | 18 | +          node-version: '18.x'  # Match Azure App Service Node version | 
| 22 | 19 |           cache: 'npm' | 
| 23 |  | - | 
| 24 |  | -      - name: Clean npm cache | 
| 25 |  | -        run: npm cache clean --force | 
| 26 |  | - | 
| 27 |  | -      - name: Delete lock file and reinstall | 
|  | 20 | +       | 
|  | 21 | +      - name: Install dependencies and build | 
| 28 | 22 |         run: | | 
| 29 |  | -          rm -f package-lock.json | 
| 30 |  | -          npm install | 
| 31 |  | -
 | 
| 32 |  | -      - name: Build application | 
| 33 |  | -        run: npm run build | 
| 34 |  | - | 
| 35 |  | -      - name: Create production package.json | 
|  | 23 | +          npm ci | 
|  | 24 | +          npm run build | 
|  | 25 | +       | 
|  | 26 | +      - name: Create production package.json for Azure | 
| 36 | 27 |         run: | | 
| 37 | 28 |           cat > dist/package.json << 'EOF' | 
| 38 | 29 |           { | 
| 39 | 30 |             "name": "porfolio-production", | 
| 40 | 31 |             "version": "1.0.0", | 
| 41 | 32 |             "engines": { | 
| 42 |  | -              "node": "20.x", | 
| 43 |  | -              "npm": "10.x" | 
|  | 33 | +              "node": "18.x", | 
|  | 34 | +              "npm": "9.x" | 
| 44 | 35 |             }, | 
| 45 | 36 |             "scripts": { | 
| 46 |  | -              "start": "serve -s . -p ${PORT:-8080}" | 
|  | 37 | +              "start": "serve -s . -p $PORT" | 
| 47 | 38 |             }, | 
| 48 | 39 |             "dependencies": { | 
| 49 | 40 |               "serve": "^14.2.4" | 
| 50 | 41 |             } | 
| 51 | 42 |           } | 
| 52 | 43 |           EOF | 
| 53 |  | -
 | 
| 54 |  | -      - name: Install serve in dist directory | 
|  | 44 | +       | 
|  | 45 | +      - name: Install production dependencies | 
| 55 | 46 |         run: | | 
| 56 | 47 |           cd dist | 
| 57 | 48 |           npm install --only=production | 
| 58 |  | -
 | 
|  | 49 | +           | 
|  | 50 | +          # Verify installation works like in SSH | 
|  | 51 | +          echo "Verifying serve installation:" | 
|  | 52 | +          npx serve --version | 
|  | 53 | +          echo "Testing serve command syntax:" | 
|  | 54 | +          timeout 5s npm start || echo "Serve test completed successfully" | 
|  | 55 | +       | 
| 59 | 56 |       - name: Upload artifact | 
| 60 | 57 |         uses: actions/upload-artifact@v4 | 
| 61 | 58 |         with: | 
| 62 |  | -          name: node-app | 
|  | 59 | +          name: webapp | 
| 63 | 60 |           path: dist | 
| 64 | 61 | 
 | 
| 65 | 62 |   deploy: | 
| 66 | 63 |     runs-on: ubuntu-latest | 
| 67 | 64 |     needs: build | 
| 68 |  | -    permissions: | 
| 69 |  | -      id-token: write | 
| 70 |  | -      contents: read | 
| 71 |  | - | 
| 72 | 65 |     steps: | 
| 73 |  | -      - name: Download artifact | 
| 74 |  | -        uses: actions/download-artifact@v4 | 
|  | 66 | +      - uses: actions/download-artifact@v4 | 
| 75 | 67 |         with: | 
| 76 |  | -          name: node-app | 
| 77 |  | - | 
| 78 |  | -      - name: Login to Azure | 
| 79 |  | -        uses: azure/login@v2 | 
|  | 68 | +          name: webapp | 
|  | 69 | +       | 
|  | 70 | +      - uses: azure/login@v2 | 
| 80 | 71 |         with: | 
| 81 | 72 |           client-id: ${{ secrets.AZUREAPPSERVICE_CLIENTID_646B290AC1724693B164CD3D4947B353 }} | 
| 82 | 73 |           tenant-id: ${{ secrets.AZUREAPPSERVICE_TENANTID_BD250A8452F0421B94ECF3BD50BFDC47 }} | 
| 83 | 74 |           subscription-id: ${{ secrets.AZUREAPPSERVICE_SUBSCRIPTIONID_A0A3E69559D143F8A11E4E6CD7432251 }} | 
| 84 | 75 | 
 | 
| 85 |  | -      - name: Deploy to Azure | 
| 86 |  | -        uses: azure/webapps-deploy@v3 | 
|  | 76 | +      - uses: azure/webapps-deploy@v3 | 
| 87 | 77 |         with: | 
| 88 | 78 |           app-name: 'albertoruiz' | 
| 89 |  | -          slot-name: 'Production' | 
| 90 | 79 |           package: . | 
0 commit comments