name: Podcast Web CICD on: push: branches: [main] paths: - "src/Web/**" - ".github/workflows/podcast-web.yml" - "deploy/Web/web.bicep" pull_request: branches: [main] paths: - "src/Web/**" - ".github/workflows/podcast-web.yml" - "deploy/Web/web.bicep" workflow_dispatch: jobs: build: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - name: Set up .NET Core uses: actions/setup-dotnet@v3 with: dotnet-version: "7.0.x" - name: Install wasm-tools run: dotnet workload install wasm-tools - uses: azure/login@v1 with: creds: ${{ secrets.AZURE_CREDENTIALS }} - name: Build run: dotnet build src/Web/Server --configuration Release - name: Publish run: dotnet publish --configuration Release src/Web/Server --output web - uses: actions/upload-artifact@master with: name: drop path: web deployStaging: name: 'Deploy PR to Staging environment' needs: build environment: name: staging if: "!startsWith(github.ref, 'refs/heads/main')" runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - uses: azure/login@v1 with: creds: ${{ secrets.AZURE_CREDENTIALS }} - name: Deploy Bicep template uses: azure/powershell@v1 with: azPSVersion: "3.1.0" inlineScript: | az deployment group create -n ghaction -g ${{ secrets.AZURE_RESOURCE_GROUP_NAME }} --template-file deploy/Web/web.bicep --parameters webAppName=${{secrets.WEBAPP_NAME}} servicePlanName=${{secrets.SERVICE_PLAN_NAME}} servicePlanSku=${{secrets.SERVICE_PLAN_SKU}} apiContainerAppName=${{ secrets.API_RESOURCE_NAME }} hubWebAppName=${{secrets.HUB_WEBAPP_NAME}} - name: Download web artifacts uses: actions/download-artifact@master with: name: drop path: web - name: Azure WebApp uses: Azure/webapps-deploy@v2 with: app-name: ${{ secrets.WEBAPP_NAME }} package: web deployProd: name: 'Deploy main branch commit to Production environment' needs: build environment: name: prod if: startsWith(github.ref, 'refs/heads/main') runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - uses: azure/login@v1 with: creds: ${{ secrets.AZURE_CREDENTIALS }} - name: Deploy Bicep template uses: azure/powershell@v1 with: azPSVersion: "3.1.0" inlineScript: | az deployment group create -n ghaction -g ${{ secrets.AZURE_RESOURCE_GROUP_NAME }} --template-file deploy/Web/web.bicep --parameters webAppName=${{secrets.WEBAPP_NAME}} servicePlanName=${{secrets.SERVICE_PLAN_NAME}} servicePlanSku=${{secrets.SERVICE_PLAN_SKU}} apiContainerAppName=${{ secrets.API_RESOURCE_NAME }} hubWebAppName=${{secrets.HUB_WEBAPP_NAME}} - name: Download web artifacts uses: actions/download-artifact@master with: name: drop path: web - name: Azure WebApp uses: Azure/webapps-deploy@v2 with: app-name: ${{ secrets.WEBAPP_NAME }} package: web test: needs: [deployStaging, deployProd] if: ${{ always() }} timeout-minutes: 60 runs-on: ubuntu-latest container: mcr.microsoft.com/playwright:v1.27.1-focal env: BASEURL: https://${{secrets.WEBAPP_NAME}}.azurewebsites.net # sets value for URL to test defaults: run: working-directory: src/Web/E2E steps: - uses: actions/checkout@v3 - uses: actions/setup-node@v2 with: node-version: "14.x" - name: Install dependencies run: npm ci - name: Run Playwright tests run: | HOME=/root npx playwright test - name: Create test summary uses: test-summary/action@dist if: always() with: paths: src/Web/E2E/test-results/junit.xml - name: Upload HTML report uses: actions/upload-artifact@v2 if: always() with: name: playwright-report path: src/Web/E2E/playwright-report/ retention-days: 30