Skip to content

Commit 4c65f31

Browse files
committed
ci: create pr preview and e2e workflow
1 parent 8d915a1 commit 4c65f31

2 files changed

Lines changed: 158 additions & 1 deletion

File tree

.github/workflows/e2e.yml

Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
name: E2E and Preview
2+
on:
3+
push:
4+
branches:
5+
- master
6+
- '[0-9]+.x.x'
7+
pull_request:
8+
branches:
9+
- master
10+
- '[0-9]+.x.x'
11+
12+
permissions:
13+
actions: read
14+
contents: read
15+
id-token: write
16+
pages: write
17+
18+
concurrency:
19+
group: ${{ github.workflow }}-${{ github.event_name == 'push' && github.run_number || github.head_ref || github.ref_name || github.event.ref }}
20+
cancel-in-progress: true
21+
22+
jobs:
23+
e2e:
24+
if: ${{ github.event_name == 'pull_request' }}
25+
runs-on: ubuntu-latest
26+
steps:
27+
- name: Checkout skyux-icons
28+
uses: actions/checkout@v5
29+
with:
30+
path: '${{ github.workspace }}/skyux-icons'
31+
fetch-depth: '0'
32+
token: '${{ secrets.GH_PERSONAL_ACCESS_TOKEN }}'
33+
- name: Checkout skyux
34+
uses: actions/checkout@v5
35+
with:
36+
repository: 'blackbaud/skyux'
37+
# TODO: change back to main after testing
38+
ref: 'icons-e2e'
39+
path: '${{ github.workspace }}/skyux'
40+
token: '${{ secrets.GH_PERSONAL_ACCESS_TOKEN }}'
41+
- name: Setup Node.js environment
42+
uses: actions/setup-node@v5
43+
with:
44+
node-version-file: 'skyux-icons/.nvmrc'
45+
- name: Install and build skyux-icons
46+
run: |
47+
set -euxo pipefail
48+
npm ci
49+
npm run build
50+
cp -R dist ../skyux/dist/skyux-icons
51+
working-directory: '${{ github.workspace }}/skyux-icons'
52+
- name: Review affected icons
53+
id: affected
54+
if: ${{ github.event_name == 'pull_request' }}
55+
run: |
56+
HAS_RENAMES_OR_DELETES=$(git diff --name-status origin/${{ github.base_ref }} | grep -E '^(D|R)' || echo '')
57+
NOT_JUST_CUSTOM_ICONS=$(git diff --name-only origin/${{ github.base_ref }} | grep -v '^src/svg/' || echo '')
58+
if [ -n "$HAS_RENAMES_OR_DELETES" ] || [ -n "$NOT_JUST_CUSTOM_ICONS" ]; then
59+
# Everything.
60+
AFFECTED="tag:icons-e2e"
61+
else
62+
# Specific icons plus icon-storybook-e2e.
63+
AFFECTED="$((git diff --name-only origin/${{ github.base_ref }} | grep '^src/svg/' || echo '') | xargs basename | sed -E 's~-[0-9]+-[a-z]+.svg$~~' | sort -u | sed 's~^~tag:icon:~' | tr '\n' ,)icon-storybook-e2e"
64+
fi
65+
echo "AFFECTED=$AFFECTED"
66+
echo "affected=${AFFECTED}" >> $GITHUB_OUTPUT
67+
working-directory: '${{ github.workspace }}/skyux-icons'
68+
# TODO: run e2e tests and push to Percy
69+
70+
preview:
71+
if: ${{ github.event_name == 'pull_request' }}
72+
runs-on: ubuntu-latest
73+
environment:
74+
name: 'github-pages'
75+
url: steps.deployment.outputs.page_url
76+
steps:
77+
- name: Checkout skyux-icons
78+
uses: actions/checkout@v5
79+
with:
80+
path: '${{ github.workspace }}/skyux-icons'
81+
- name: Checkout skyux
82+
uses: actions/checkout@v5
83+
with:
84+
repository: 'blackbaud/skyux'
85+
ref: 'main'
86+
path: '${{ github.workspace }}/skyux'
87+
- name: Setup Node.js environment
88+
uses: actions/setup-node@v5
89+
with:
90+
node-version-file: 'skyux/.nvmrc'
91+
- name: Install
92+
run: npm ci
93+
- name: Install and build skyux-icons
94+
run: |
95+
set -euxo pipefail
96+
npm ci
97+
npm run build
98+
cp -R dist ../skyux/dist/skyux-icons
99+
working-directory: '${{ github.workspace }}/skyux-icons'
100+
- name: Install skyux
101+
run: npm ci
102+
working-directory: '${{ github.workspace }}/skyux'
103+
- name: Build Storybooks
104+
run: npx nx run-many -t build-storybook --projects=tag:component-e2e --skip-nx-cache
105+
working-directory: '${{ github.workspace }}/skyux'
106+
- name: Build playground
107+
run: |
108+
cat dist/skyux-icons/assets/svg/skyux-icons.svg >> apps/playground/src/index.html
109+
npx nx run playground:build
110+
mkdir -pv dist/preview-pages
111+
working-directory: '${{ github.workspace }}/skyux'
112+
- name: Retrieve other preview sites
113+
uses: actions/download-artifact@v5
114+
with:
115+
pattern: 'pr-*'
116+
path: skyux/dist/preview-pages/
117+
- name: Create preview site for PR ${{ github.event.number }}
118+
run: |
119+
rm -rfv dist/preview-pages/pr-${{ github.event.number }}
120+
mkdir -pv dist/preview-pages/pr-${{ github.event.number }}/storybooks
121+
mv -v dist/apps/* dist/preview-pages/pr-${{ github.event.number }}/
122+
mv -v dist/storybook/* dist/preview-pages/pr-${{ github.event.number }}/storybooks/
123+
npx nx g @skyux-sdk/e2e-schematics:pr-comment --pr=pr-${{ github.event.number }} \
124+
--url="https://${{ github.repository_owner }}.github.io/skyux-icons" \
125+
--repoUrl="https://github.com/${{ github.repository }}" \
126+
--apps="$(ls dist/preview-pages/pr-${{ github.event.number }} | fgrep -v storybooks | tr '\n' ,)" \
127+
--storybooks="$(ls dist/preview-pages/pr-${{ github.event.number }}/storybooks | tr '\n' ,)" \
128+
--skipCompositeStorybook
129+
mv -v dist/pr_index.html dist/preview-pages/pr-${{ github.event.number }}/index.html
130+
working-directory: '${{ github.workspace }}/skyux'
131+
- name: Save PR ${{ github.event.number }} Preview
132+
uses: actions/upload-artifact@v4
133+
with:
134+
name: pr-${{ github.event.number }}
135+
path: skyux/dist/preview-pages/pr-${{ github.event.number }}
136+
if-no-files-found: 'error'
137+
overwrite: 'true'
138+
retention-days: 14
139+
- name: Setup Pages
140+
uses: actions/configure-pages@v5
141+
- name: Upload GitHub Pages artifact
142+
uses: actions/upload-pages-artifact@v3
143+
with:
144+
path: dist/bark-back/browser
145+
- name: Deploy to GitHub Pages
146+
id: deployment
147+
uses: actions/deploy-pages@v4
148+
- name: Comment
149+
run: |
150+
COMMENT_ID=$(gh pr view ${{ github.event.number }} -R ${{ github.repository }} --json comments -q '.comments | map(select(.body | contains("Component Storybooks:"))) | .[0].id // empty')
151+
if [ -n "$COMMENT_ID" ]; then
152+
gh api --method PATCH -H "Accept: application/vnd.github+json" -H "X-GitHub-Api-Version: 2022-11-28" \
153+
/repos/${{ github.repository }}/pulls/comments/${COMMENT_ID} \
154+
-f 'body=@skyux/dist/pr_comment.md'
155+
else
156+
gh pr comment ${{ github.event.number }} -R ${{ github.repository }} -F skyux/dist/pr_comment.md
157+
fi

.nvmrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
20.11.1
1+
20.19.5

0 commit comments

Comments
 (0)