Skip to content

Commit 831c540

Browse files
committed
feat(publish-site-azure.yml): adds workflow to move documentation + PR previews to Azure
1 parent 22a7dcb commit 831c540

File tree

5 files changed

+184
-79
lines changed

5 files changed

+184
-79
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/usr/bin/env node
2+
3+
/**
4+
* Copyright 2025 Adobe. All rights reserved.
5+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License. You may obtain a copy
7+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
8+
* Unless required by applicable law or agreed to in writing, software distributed under
9+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
10+
* OF ANY KIND, either express or implied. See the License for the specific language
11+
* governing permissions and limitations under the License.
12+
*/
13+
14+
export const buildPreviewURLComment = (prNumber) => {
15+
const prHash = `pr-${prNumber}`;
16+
const baseUrl = 'https://spectrumcss.z13.web.core.windows.net';
17+
18+
return `PR #${prNumber} has been deployed to Azure Blob Storage: ${baseUrl}/${prHash}/index.html.`;
19+
};

.github/scripts/comment-or-update.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
Copyright 2025 Adobe. All rights reserved.
3+
This file is licensed to you under the Apache License, Version 2.0 (the "License");
4+
you may not use this file except in compliance with the License. You may obtain a copy
5+
of the License at http://www.apache.org/licenses/LICENSE-2.0
6+
7+
Unless required by applicable law or agreed to in writing, software distributed under
8+
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9+
OF ANY KIND, either express or implied. See the License for the specific language
10+
governing permissions and limitations under the License.
11+
*/
12+
13+
export const commentOrUpdate = (github, context, title, body) => {
14+
github.rest.issues
15+
.listComments({
16+
owner: context.repo.owner,
17+
repo: context.repo.repo,
18+
issue_number: context.issue.number,
19+
})
20+
.then(({ data }) => {
21+
const priorComment = data.find((comment) =>
22+
comment.body.startsWith(title)
23+
);
24+
if (priorComment) {
25+
github.rest.issues.updateComment({
26+
owner: context.repo.owner,
27+
repo: context.repo.repo,
28+
comment_id: priorComment.id,
29+
body,
30+
});
31+
} else {
32+
github.rest.issues.createComment({
33+
owner: context.repo.owner,
34+
repo: context.repo.repo,
35+
issue_number: context.issue.number,
36+
body,
37+
});
38+
}
39+
});
40+
};

.github/workflows/development.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,8 +203,8 @@ jobs:
203203
secrets: inherit
204204

205205
# -------------------------------------------------------------
206-
# PUBLISH TO NETLIFY --- #
207-
# Publish to netlify by leveraging the previous build and then building the site as well
206+
# PUBLISH TO AZURE --- #
207+
# Publish to azure by leveraging the previous build and then building the site as well
208208
# -------------------------------------------------------------
209209
publish_site:
210210
name: Publish

.github/workflows/publish-site.yml

Lines changed: 122 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -1,91 +1,136 @@
1-
name: Publish documentation
1+
name: Publish documentation (Azure Blob Storage)
22
#
3-
# This workflow publishes the documentation to Netlify
3+
# This workflow publishes the documentation to Azure blob storage
44
#
55

66
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
2326

2427
permissions:
25-
contents: read
26-
pull-requests: write
28+
contents: read
29+
pull-requests: write
2730

2831
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
4242

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
4848

49-
- name: Enable Corepack
50-
run: corepack enable
49+
- name: Enable Corepack
50+
run: corepack enable
5151

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}"
6258
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') }}
6869

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
7374

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}/"

.storybook/main.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ export default {
9090
const { mergeConfig } = await import("vite");
9191

9292
return mergeConfig(config, {
93+
base: process.env.BASE_PATH || config.base,
9394
publicDir: "./assets",
9495
// Add dependencies to pre-optimization
9596
optimizeDeps: {

0 commit comments

Comments
 (0)