|
| 1 | +name: Publish documentation (Azure) |
| 2 | +# |
| 3 | +# This workflow publishes the documentation to Azure static web apps |
| 4 | +# |
| 5 | + |
| 6 | +on: |
| 7 | + pull_request: |
| 8 | + types: [opened, synchronize, reopened, closed] |
| 9 | + branches: |
| 10 | + - "**" |
| 11 | + |
| 12 | +permissions: |
| 13 | + contents: read |
| 14 | + pull-requests: write |
| 15 | + |
| 16 | +jobs: |
| 17 | + build_and_deploy_job: |
| 18 | + if: github.event_name == 'push' || (github.event_name == 'pull_request' && github.event.action != 'closed') |
| 19 | + runs-on: ubuntu-latest |
| 20 | + name: Build and Deploy Job |
| 21 | + steps: |
| 22 | + ## --- SETUP --- ## |
| 23 | + - name: Check out code |
| 24 | + uses: actions/checkout@v4 |
| 25 | + with: |
| 26 | + fetch-depth: 0 |
| 27 | + |
| 28 | + - name: Use Node LTS version |
| 29 | + uses: actions/setup-node@v4 |
| 30 | + with: |
| 31 | + node-version: 20 |
| 32 | + cache: yarn |
| 33 | + |
| 34 | + - name: Enable Corepack |
| 35 | + run: corepack enable |
| 36 | + |
| 37 | + - name: Clean up comments from previous Azure deploys |
| 38 | + if: github.event_name == 'pull_request' |
| 39 | + shell: bash |
| 40 | + env: |
| 41 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 42 | + run: | |
| 43 | + pr=${{ github.event.pull_request.number }} |
| 44 | + comments=$(gh api repos/${{ github.repository }}/issues/$pr/comments) |
| 45 | + echo "$comments" | jq -c '.[]' | while read -r comment; do |
| 46 | + body=$(echo "$comment" | jq -r '.body') |
| 47 | + id=$(echo "$comment" | jq -r '.id') |
| 48 | + if [[ "$body" == Azure\ Static\ Web\ Apps:* ]]; then |
| 49 | + echo "Deleting comment $id" |
| 50 | + gh api repos/${{ github.repository }}/issues/comments/$id -X DELETE |
| 51 | + fi |
| 52 | + done |
| 53 | +
|
| 54 | + ## --- YARN CACHE --- ## |
| 55 | + - name: Check for cached dependencies |
| 56 | + continue-on-error: true |
| 57 | + id: cache-dependencies |
| 58 | + uses: actions/cache@v4 |
| 59 | + with: |
| 60 | + path: | |
| 61 | + .cache/yarn |
| 62 | + node_modules |
| 63 | + key: ubuntu-latest-node20-${{ hashFiles('yarn.lock') }} |
| 64 | + |
| 65 | + ## --- INSTALL --- ## |
| 66 | + # note: if cache-hit isn't needed b/c yarn will leverage the cache if it exists |
| 67 | + - name: Install dependencies |
| 68 | + shell: bash |
| 69 | + run: yarn install --immutable |
| 70 | + |
| 71 | + - name: Deploy |
| 72 | + id: builddeploy |
| 73 | + uses: Azure/static-web-apps-deploy@v1 |
| 74 | + with: |
| 75 | + azure_static_web_apps_api_token: ${{ secrets.AZURE_STATIC_WEB_APPS_API_TOKEN_POLITE_CLIFF_0173AA90F }} |
| 76 | + repo_token: ${{ secrets.GITHUB_TOKEN }} |
| 77 | + action: "upload" |
| 78 | + app_location: "/" |
| 79 | + api_location: "" |
| 80 | + output_location: "dist" |
| 81 | + app_build_command: "yarn build:docs" |
| 82 | + timeout-minutes: 10 |
| 83 | + close_pull_request_job: |
| 84 | + if: github.event.action == 'closed' |
| 85 | + runs-on: ubuntu-latest |
| 86 | + name: Clean up PR environment |
| 87 | + steps: |
| 88 | + - name: Remove PR environment |
| 89 | + id: closepullrequest |
| 90 | + uses: Azure/static-web-apps-deploy@v1 |
| 91 | + with: |
| 92 | + azure_static_web_apps_api_token: ${{ secrets.AZURE_STATIC_WEB_APPS_API_TOKEN_POLITE_CLIFF_0173AA90F }} |
| 93 | + action: "close" |
0 commit comments