|
| 1 | +# Docs for the Azure Web Apps Deploy action: https://github.com/Azure/webapps-deploy |
| 2 | +# More GitHub Actions for Azure: https://github.com/Azure/actions |
| 3 | + |
| 4 | +name: Build and deploy Node.js app to Azure Web App - webapptest3 |
| 5 | + |
| 6 | +on: |
| 7 | + push: |
| 8 | + branches: |
| 9 | + - main |
| 10 | + workflow_dispatch: |
| 11 | + |
| 12 | +jobs: |
| 13 | + build: |
| 14 | + runs-on: ubuntu-latest |
| 15 | + permissions: |
| 16 | + contents: read |
| 17 | + |
| 18 | + steps: |
| 19 | + - uses: actions/checkout@v4 |
| 20 | + |
| 21 | + - name: Set up Node.js version |
| 22 | + uses: actions/setup-node@v4 |
| 23 | + with: |
| 24 | + node-version: '22.x' # Node 24 is very new; LTS (20 or 22) is highly recommended for Azure stability |
| 25 | + |
| 26 | + # Next.js requires environment variables to be present during the build step |
| 27 | + - name: npm install, build, and test |
| 28 | + env: |
| 29 | + GEMINI_API_KEY: ${{ secrets.GEMINI_API_KEY }} |
| 30 | + MONGODB_URI: ${{ secrets.MONGODB_URI }} |
| 31 | + run: | |
| 32 | + npm install --force |
| 33 | + npm run build --if-present |
| 34 | +
|
| 35 | + # Upload everything, explicitly ensuring hidden folders like .next are included |
| 36 | + - name: Upload artifact for deployment job |
| 37 | + uses: actions/upload-artifact@v4 |
| 38 | + with: |
| 39 | + name: node-app |
| 40 | + path: | |
| 41 | + . |
| 42 | + !.git |
| 43 | + !.github |
| 44 | +
|
| 45 | + deploy: |
| 46 | + runs-on: ubuntu-latest |
| 47 | + needs: build |
| 48 | + permissions: |
| 49 | + id-token: write |
| 50 | + contents: read |
| 51 | + |
| 52 | + steps: |
| 53 | + - name: Download artifact from build job |
| 54 | + uses: actions/download-artifact@v4 |
| 55 | + with: |
| 56 | + name: node-app |
| 57 | + |
| 58 | + - name: Login to Azure |
| 59 | + uses: azure/login@v2 |
| 60 | + with: |
| 61 | + client-id: ${{ secrets.__clientidsecretname__ }} |
| 62 | + tenant-id: ${{ secrets.__tenantidsecretname__ }} |
| 63 | + subscription-id: ${{ secrets.__subscriptionidsecretname__ }} |
| 64 | + |
| 65 | + - name: 'Deploy to Azure Web App' |
| 66 | + id: deploy-to-webapp |
| 67 | + uses: azure/webapps-deploy@v3 |
| 68 | + with: |
| 69 | + app-name: 'webapptest3' |
| 70 | + slot-name: 'Production' |
| 71 | + package: . |
0 commit comments