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