Skip to content

Commit 1ec4b5f

Browse files
committed
feat(publish-site-azure.yml): adds workflow to move documentation + PR previews to Azure
1 parent 7afe545 commit 1ec4b5f

File tree

2 files changed

+115
-77
lines changed

2 files changed

+115
-77
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
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+
const docsUrl = `${baseUrl}/${prHash}/docs/`;
18+
const storybookUrl = `${baseUrl}/${prHash}/docs/storybook/`;
19+
20+
return `PR #${prNumber} has been deployed to Azure Blob Storage: ${prHash}.`;
21+
};

.github/workflows/publish-site.yml

Lines changed: 94 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -1,91 +1,108 @@
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: [opened, synchronize, reopened, closed]
239

2410
permissions:
25-
contents: read
26-
pull-requests: write
11+
contents: read
12+
pull-requests: write
2713

2814
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
15+
build_and_deploy_job:
16+
if: github.event_name == 'pull_request' && github.event.action != 'closed'
17+
runs-on: ubuntu-latest
18+
name: Build and Deploy Job
19+
steps:
20+
## --- SETUP --- ##
21+
- name: Check out code
22+
uses: actions/checkout@v4
23+
with:
24+
fetch-depth: 0
4225

43-
- name: Use Node LTS version
44-
uses: actions/setup-node@v4
45-
with:
46-
node-version: 20
47-
cache: yarn
26+
- name: Use Node LTS version
27+
uses: actions/setup-node@v4
28+
with:
29+
node-version: 20
30+
cache: yarn
4831

49-
- name: Enable Corepack
50-
run: corepack enable
32+
- name: Enable Corepack
33+
run: corepack enable
5134

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') }}
35+
- name: Generate PR hash
36+
id: pr_hash
37+
run: |
38+
pr_hash="pr-${{ github.event.pull_request.number }}"
39+
echo "hash=${pr_hash}" >> $GITHUB_OUTPUT
40+
echo "Generated PR hash: ${pr_hash}"
6241
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
42+
## --- YARN CACHE --- ##
43+
- name: Check for cached dependencies
44+
continue-on-error: true
45+
id: cache-dependencies
46+
uses: actions/cache@v4
47+
with:
48+
path: |
49+
.cache/yarn
50+
node_modules
51+
key: ubuntu-latest-node20-${{ hashFiles('yarn.lock') }}
6852

69-
## --- BUILD --- ##
70-
- name: Build storybook
71-
shell: bash
72-
run: yarn build:docs
53+
## --- INSTALL --- ##
54+
- name: Install dependencies
55+
shell: bash
56+
run: yarn install --immutable
7357

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
58+
## --- BUILD --- ##
59+
- name: Build storybook
60+
shell: bash
61+
run: yarn build:docs
62+
63+
## --- DEPLOY TO AZURE BLOB STORAGE --- ##
64+
- name: Install AzCopy
65+
run: |
66+
wget -O azcopy.tar.gz https://aka.ms/downloadazcopy-v10-linux
67+
tar -xf azcopy.tar.gz --strip-components=1
68+
sudo mv azcopy /usr/local/bin/
69+
azcopy --version
70+
- name: Deploy to Azure Blob Storage
71+
id: deploy
72+
env:
73+
AZURE_STORAGE_SAS_TOKEN: ${{ secrets.AZURE_STORAGE_SAS_TOKEN }}
74+
PR_HASH: ${{ steps.pr_hash.outputs.hash }}
75+
run: |
76+
CLEAN_SAS_TOKEN=$(echo "${AZURE_STORAGE_SAS_TOKEN}" | tr -d '\n\r\t ')
77+
echo "Uploading Storybook to ${PR_HASH}"
78+
azcopy copy "dist/*" \
79+
"https://spectrumcss.z13.web.core.windows.net/\$web/${PR_HASH}/?${CLEAN_SAS_TOKEN}" \
80+
--recursive \
81+
--from-to LocalBlob
82+
docs_url="https://spectrumcss.z13.web.core.windows.net/${PR_HASH}"
83+
echo "docs_url=${docs_url}" >> $GITHUB_OUTPUT
84+
echo "Deployed to: ${docs_url}"
85+
close_pull_request_job:
86+
if: github.event_name == 'pull_request' && github.event.action == 'closed'
87+
runs-on: ubuntu-latest
88+
name: Clean up PR deployment
89+
steps:
90+
- name: Generate PR hash
91+
id: pr_hash
92+
run: |
93+
pr_hash="pr-${{ github.event.pull_request.number }}"
94+
echo "hash=${pr_hash}" >> $GITHUB_OUTPUT
95+
- name: Install AzCopy
96+
run: |
97+
wget -O azcopy.tar.gz https://aka.ms/downloadazcopy-v10-linux
98+
tar -xf azcopy.tar.gz --strip-components=1
99+
sudo mv azcopy /usr/local/bin/
100+
- name: Clean up PR deployment
101+
env:
102+
AZURE_STORAGE_SAS_TOKEN: ${{ secrets.AZURE_STORAGE_SAS_TOKEN }}
103+
PR_HASH: ${{ steps.pr_hash.outputs.hash }}
104+
run: |
105+
echo "Cleaning up deployment: ${PR_HASH}/"
106+
azcopy remove "https://spectrumcss.z13.web.core.windows.net/\$web/${PR_HASH}/?${AZURE_STORAGE_SAS_TOKEN}" \
107+
--recursive || echo "Cleanup completed (some files may not exist)"
108+
echo "Cleanup completed for PR deployment: ${PR_HASH}/"

0 commit comments

Comments
 (0)