|
1 |
| -name: Publish documentation |
| 1 | +name: Publish documentation (Azure Blob Storage) |
2 | 2 | #
|
3 |
| -# This workflow publishes the documentation to Netlify |
| 3 | +# This workflow publishes the documentation to Azure blob storage |
4 | 4 | #
|
5 | 5 |
|
6 | 6 | on:
|
7 |
| - workflow_dispatch: |
8 |
| - inputs: |
9 |
| - deploy-message: |
10 |
| - required: false |
11 |
| - type: string |
12 |
| - alias: |
13 |
| - required: false |
14 |
| - type: string |
15 |
| - workflow_call: |
16 |
| - inputs: |
17 |
| - deploy-message: |
18 |
| - required: false |
19 |
| - type: string |
20 |
| - alias: |
21 |
| - required: false |
22 |
| - type: string |
| 7 | + pull_request: |
| 8 | + types: |
| 9 | + - closed |
| 10 | + workflow_dispatch: |
| 11 | + inputs: |
| 12 | + deploy-message: |
| 13 | + required: false |
| 14 | + type: string |
| 15 | + alias: |
| 16 | + required: false |
| 17 | + type: string |
| 18 | + workflow_call: |
| 19 | + inputs: |
| 20 | + deploy-message: |
| 21 | + required: false |
| 22 | + type: string |
| 23 | + alias: |
| 24 | + required: false |
| 25 | + type: string |
23 | 26 |
|
24 | 27 | permissions:
|
25 |
| - contents: read |
26 |
| - pull-requests: write |
| 28 | + contents: read |
| 29 | + pull-requests: write |
27 | 30 |
|
28 | 31 | jobs:
|
29 |
| - # --- PUBLISH TO NETLIFY --- # |
30 |
| - # Publish to netlify by leveraging the previous build and then building the site as well |
31 |
| - # --- # |
32 |
| - publish_site: |
33 |
| - name: Publish |
34 |
| - runs-on: ubuntu-latest |
35 |
| - timeout-minutes: 10 |
36 |
| - steps: |
37 |
| - ## --- SETUP --- ## |
38 |
| - - name: Check out code |
39 |
| - uses: actions/checkout@v4 |
40 |
| - with: |
41 |
| - fetch-depth: 0 |
| 32 | + build_and_deploy_job: |
| 33 | + if: github.event_name == 'pull_request' && github.event.action != 'closed' |
| 34 | + runs-on: ubuntu-latest |
| 35 | + name: Build and Deploy Job |
| 36 | + steps: |
| 37 | + ## --- SETUP --- ## |
| 38 | + - name: Check out code |
| 39 | + uses: actions/checkout@v4 |
| 40 | + with: |
| 41 | + fetch-depth: 0 |
42 | 42 |
|
43 |
| - - name: Use Node LTS version |
44 |
| - uses: actions/setup-node@v4 |
45 |
| - with: |
46 |
| - node-version: 20 |
47 |
| - cache: yarn |
| 43 | + - name: Use Node LTS version |
| 44 | + uses: actions/setup-node@v4 |
| 45 | + with: |
| 46 | + node-version: 20 |
| 47 | + cache: yarn |
48 | 48 |
|
49 |
| - - name: Enable Corepack |
50 |
| - run: corepack enable |
| 49 | + - name: Enable Corepack |
| 50 | + run: corepack enable |
51 | 51 |
|
52 |
| - ## --- YARN CACHE --- ## |
53 |
| - - name: Check for cached dependencies |
54 |
| - continue-on-error: true |
55 |
| - id: cache-dependencies |
56 |
| - uses: actions/cache@v4 |
57 |
| - with: |
58 |
| - path: | |
59 |
| - .cache/yarn |
60 |
| - node_modules |
61 |
| - key: ubuntu-latest-node20-${{ hashFiles('yarn.lock') }} |
| 52 | + - name: Generate PR hash |
| 53 | + id: pr_hash |
| 54 | + run: | |
| 55 | + pr_hash="pr-${{ github.event.pull_request.number }}" |
| 56 | + echo "hash=${pr_hash}" >> $GITHUB_OUTPUT |
| 57 | + echo "Generated PR hash: ${pr_hash}" |
62 | 58 |
|
63 |
| - ## --- INSTALL --- ## |
64 |
| - # note: if cache-hit isn't needed b/c yarn will leverage the cache if it exists |
65 |
| - - name: Install dependencies |
66 |
| - shell: bash |
67 |
| - run: yarn install --immutable |
| 59 | + ## --- YARN CACHE --- ## |
| 60 | + - name: Check for cached dependencies |
| 61 | + continue-on-error: true |
| 62 | + id: cache-dependencies |
| 63 | + uses: actions/cache@v4 |
| 64 | + with: |
| 65 | + path: | |
| 66 | + .cache/yarn |
| 67 | + node_modules |
| 68 | + key: ubuntu-latest-node20-${{ hashFiles('yarn.lock') }} |
68 | 69 |
|
69 |
| - ## --- BUILD --- ## |
70 |
| - - name: Build storybook |
71 |
| - shell: bash |
72 |
| - run: yarn build:docs |
| 70 | + ## --- INSTALL --- ## |
| 71 | + - name: Install dependencies |
| 72 | + shell: bash |
| 73 | + run: yarn install --immutable |
73 | 74 |
|
74 |
| - ## --- DEPLOY WEBSITE TO NETLIFY --- ## |
75 |
| - - name: Deploy |
76 |
| - uses: nwtgck/actions-netlify@v3 |
77 |
| - with: |
78 |
| - publish-dir: dist |
79 |
| - production-branch: main |
80 |
| - production-deploy: false |
81 |
| - netlify-config-path: ./netlify.toml |
82 |
| - github-token: ${{ secrets.GITHUB_TOKEN }} |
83 |
| - deploy-message: ${{ inputs.deploy-message }} |
84 |
| - enable-pull-request-comment: true |
85 |
| - enable-commit-comment: false |
86 |
| - overwrites-pull-request-comment: true |
87 |
| - alias: ${{ inputs.alias }} |
88 |
| - env: |
89 |
| - NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN_GH_ACTIONS_DEPLOY }} |
90 |
| - NETLIFY_SITE_ID: ${{ secrets.NETLIFY_SITE_ID }} |
91 |
| - timeout-minutes: 10 |
| 75 | + ## --- BUILD --- ## |
| 76 | + - name: Build storybook |
| 77 | + shell: bash |
| 78 | + run: BASE_PATH="/${{ steps.pr_hash.outputs.hash }}" yarn build:docs |
| 79 | + |
| 80 | + ## --- DEPLOY TO AZURE BLOB STORAGE --- ## |
| 81 | + - name: Install AzCopy |
| 82 | + run: | |
| 83 | + wget -O azcopy.tar.gz https://aka.ms/downloadazcopy-v10-linux |
| 84 | + tar -xf azcopy.tar.gz --strip-components=1 |
| 85 | + sudo mv azcopy /usr/local/bin/ |
| 86 | + azcopy --version |
| 87 | +
|
| 88 | + - name: Deploy to Azure Blob Storage |
| 89 | + id: deploy |
| 90 | + env: |
| 91 | + AZURE_STORAGE_SAS_TOKEN: ${{ secrets.AZURE_STORAGE_SAS_TOKEN }} |
| 92 | + PR_HASH: ${{ steps.pr_hash.outputs.hash }} |
| 93 | + run: | |
| 94 | + CLEAN_SAS_TOKEN=$(echo "${AZURE_STORAGE_SAS_TOKEN}" | tr -d '\n\r\t ') |
| 95 | + echo "Uploading Storybook to ${PR_HASH}" |
| 96 | + azcopy copy "/home/runner/work/spectrum-css/spectrum-css/dist/*" --log-level=INFO \ |
| 97 | + "https://spectrumcss.blob.core.windows.net/\$web/${PR_HASH}/?${CLEAN_SAS_TOKEN}" \ |
| 98 | + --recursive \ |
| 99 | + --from-to LocalBlob |
| 100 | + docs_url="https://spectrumcss.z13.web.core.windows.net/${PR_HASH}" |
| 101 | + echo "docs_url=${docs_url}" >> $GITHUB_OUTPUT |
| 102 | + echo "Deployed to: ${docs_url}" |
| 103 | + - name: Post Previews Comment |
| 104 | + uses: actions/github-script@v7 |
| 105 | + with: |
| 106 | + script: | |
| 107 | + const { buildPreviewURLComment } = await import('${{ github.workspace }}/.github/scripts/build-preview-urls-comment.js'); |
| 108 | + const { commentOrUpdate } = await import('${{ github.workspace }}/.github/scripts/comment-or-update.js'); |
| 109 | + const prNumber = context.payload.pull_request.number; |
| 110 | + const body = buildPreviewURLComment(prNumber); |
| 111 | + commentOrUpdate(github, context, '## 📚 Branch Preview', body); |
| 112 | +
|
| 113 | + close_pull_request_job: |
| 114 | + if: github.event_name == 'pull_request' && github.event.action == 'closed' |
| 115 | + runs-on: ubuntu-latest |
| 116 | + name: Clean up PR deployment |
| 117 | + steps: |
| 118 | + - name: Generate PR hash |
| 119 | + id: pr_hash |
| 120 | + run: | |
| 121 | + pr_hash="pr-${{ github.event.pull_request.number }}" |
| 122 | + echo "hash=${pr_hash}" >> $GITHUB_OUTPUT |
| 123 | + - name: Install AzCopy |
| 124 | + run: | |
| 125 | + wget -O azcopy.tar.gz https://aka.ms/downloadazcopy-v10-linux |
| 126 | + tar -xf azcopy.tar.gz --strip-components=1 |
| 127 | + sudo mv azcopy /usr/local/bin/ |
| 128 | + - name: Clean up PR deployment |
| 129 | + env: |
| 130 | + AZURE_STORAGE_SAS_TOKEN: ${{ secrets.AZURE_STORAGE_SAS_TOKEN }} |
| 131 | + PR_HASH: ${{ steps.pr_hash.outputs.hash }} |
| 132 | + run: | |
| 133 | + echo "Cleaning up deployment: ${PR_HASH}/" |
| 134 | + azcopy remove "https://spectrumcss.z13.web.core.windows.net/\$web/${PR_HASH}/?${AZURE_STORAGE_SAS_TOKEN}" \ |
| 135 | + --recursive || echo "Cleanup completed (some files may not exist)" |
| 136 | + echo "Cleanup completed for PR deployment: ${PR_HASH}/" |
0 commit comments