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