name: Azure Static Web Apps CI/CD on: push: branches: - main pull_request: types: [opened, synchronize, reopened, closed] branches: - main jobs: build_and_deploy_job: if: github.event_name == 'push' || (github.event_name == 'pull_request' && github.event.action != 'closed') runs-on: ubuntu-latest name: Build and Deploy Job permissions: id-token: write contents: read steps: - uses: actions/checkout@v5 with: submodules: true - name: Setup pnpm uses: pnpm/action-setup@v4 with: version: 10 - name: Setup Node.js uses: actions/setup-node@v4 with: node-version: 20 - name: Install dependencies run: pnpm install --no-frozen-lockfile - name: Install OIDC Client run: pnpm add @actions/core@latest @actions/http-client --save-dev - name: Get Id Token uses: actions/github-script@v6 id: idtoken with: script: | const coredemo = require('@actions/core') return await coredemo.getIDToken() result-encoding: string - name: Build and Deploy id: builddeploy uses: Azure/static-web-apps-deploy@v1 with: azure_static_web_apps_api_token: ${{ secrets.AZURE_STATIC_WEB_APPS_API_TOKEN_xxx }} action: "upload" app_location: "/" # App source code path api_location: "" # Api source code path - optional output_location: "" github_id_token: ${{ steps.idtoken.outputs.result }} app_build_command: 'pnpm run build' close_pull_request_job: if: github.event_name == 'pull_request' && github.event.action == 'closed' runs-on: ubuntu-latest name: Close Pull Request Job steps: - name: Close Pull Request id: closepullrequest uses: Azure/static-web-apps-deploy@v1 with: app_location: "/" azure_static_web_apps_api_token: ${{ secrets.AZURE_STATIC_WEB_APPS_API_TOKEN_xxx }} action: "close"