Skip to content

Commit 1bebe98

Browse files
authored
GitHub actions updates (#42)
* Add a bot for requesting reviews * Use a composite action for pnpm with caching * Share node modules between all CI jobs * Use smarter caching/artifacts * Remove separate setup job as it isn't any faster * Set build job to be the one to update pnpm cache * Remove unnecessary pnpm install in bot/ from workflows * Move all bot workflows to one file * Try deploying Storybook previews for each PR * Move to separate files to avoid showing skipped checks in PRs
1 parent dedb511 commit 1bebe98

File tree

14 files changed

+820
-261
lines changed

14 files changed

+820
-261
lines changed
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
name: 'Setup pnpm with cache'
2+
description: 'Setup Node.js, pnpm, and restore cache'
3+
inputs:
4+
node-version:
5+
description: 'Node.js version to use'
6+
required: false
7+
default: '22.x'
8+
save-cache:
9+
description: 'Whether to save the cache (only on main branch)'
10+
required: false
11+
default: 'false'
12+
registry-url:
13+
description: 'NPM registry URL'
14+
required: false
15+
default: ''
16+
17+
runs:
18+
using: 'composite'
19+
steps:
20+
- uses: actions/setup-node@v4
21+
with:
22+
node-version: ${{ inputs.node-version }}
23+
registry-url: ${{ inputs.registry-url }}
24+
25+
- name: Enable Corepack
26+
shell: bash
27+
run: corepack enable
28+
29+
- name: Get pnpm store directory
30+
id: pnpm-cache
31+
shell: bash
32+
run: echo "pnpm_cache_dir=$(pnpm store path --silent)" >> $GITHUB_OUTPUT
33+
34+
- name: Restore pnpm cache
35+
uses: actions/cache/restore@v4
36+
with:
37+
path: ${{ steps.pnpm-cache.outputs.pnpm_cache_dir }}
38+
key: pnpm-store-${{ runner.os }}-${{ hashFiles('**/pnpm-lock.yaml') }}
39+
restore-keys: |
40+
pnpm-store-${{ runner.os }}-
41+
42+
- name: Install dependencies
43+
shell: bash
44+
run: pnpm install --frozen-lockfile
45+
46+
- name: Save pnpm cache
47+
if: inputs.save-cache == 'true'
48+
uses: actions/cache/save@v4
49+
with:
50+
path: ${{ steps.pnpm-cache.outputs.pnpm_cache_dir }}
51+
key: pnpm-store-${{ runner.os }}-${{ hashFiles('**/pnpm-lock.yaml') }}

.github/workflows/bot.yml

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
name: Changeset Bot
1+
name: Bot
22

33
on:
44
pull_request:
5-
types: [opened, synchronize, reopened]
5+
types: [ opened, ready_for_review, synchronize, reopened ]
66

77
permissions:
88
contents: read
@@ -13,8 +13,31 @@ env:
1313
NODE_VERSION: 22.x
1414

1515
jobs:
16+
assign-reviewer:
17+
name: Assign random reviewer
18+
runs-on: ubuntu-latest
19+
if: ${{ !github.event.pull_request.draft }}
20+
21+
steps:
22+
- name: Checkout
23+
uses: actions/checkout@v5
24+
25+
- name: Setup pnpm
26+
uses: ./.github/actions/setup-pnpm
27+
with:
28+
node-version: ${{ env.NODE_VERSION }}
29+
30+
- name: Assign random reviewer
31+
env:
32+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
33+
run: |
34+
pnpm bot reviewer \
35+
${{ github.repository_owner }} \
36+
${{ github.event.repository.name }} \
37+
${{ github.event.pull_request.number }}
38+
1639
changeset-bot:
17-
name: Changeset Bot
40+
name: Check for changeset
1841
runs-on: ubuntu-latest
1942
if: ${{ !startsWith(github.event.pull_request.head.ref, 'changeset-release') }}
2043

@@ -24,25 +47,16 @@ jobs:
2447
with:
2548
fetch-depth: 0
2649

27-
- uses: actions/setup-node@v4
50+
- name: Setup pnpm
51+
uses: ./.github/actions/setup-pnpm
2852
with:
2953
node-version: ${{ env.NODE_VERSION }}
3054

31-
- name: Enable Corepack
32-
run: corepack enable
33-
34-
- name: Install dependencies
35-
run: pnpm install --frozen-lockfile
36-
37-
- name: Install bot dependencies
38-
run: pnpm install --frozen-lockfile
39-
working-directory: bot
40-
4155
- name: Run changeset bot
4256
env:
4357
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
4458
run: |
45-
pnpm bot \
59+
pnpm bot changeset \
4660
${{ github.repository_owner }} \
4761
${{ github.event.repository.name }} \
4862
${{ github.event.pull_request.number }} \

.github/workflows/ci.yml

Lines changed: 9 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,11 @@ jobs:
1919
- name: Checkout branch
2020
uses: actions/checkout@v5
2121

22-
- uses: actions/setup-node@v4
22+
- name: Setup pnpm
23+
uses: ./.github/actions/setup-pnpm
2324
with:
2425
node-version: ${{ env.NODE_VERSION }}
25-
26-
- name: Enable Corepack
27-
run: corepack enable
28-
29-
- name: Install
30-
run: pnpm install --frozen-lockfile
26+
save-cache: ${{ github.ref == 'refs/heads/main' }}
3127

3228
- name: Build
3329
run: pnpm build
@@ -39,16 +35,11 @@ jobs:
3935
- name: Checkout branch
4036
uses: actions/checkout@v5
4137

42-
- uses: actions/setup-node@v4
38+
- name: Setup pnpm
39+
uses: ./.github/actions/setup-pnpm
4340
with:
4441
node-version: ${{ env.NODE_VERSION }}
4542

46-
- name: Enable Corepack
47-
run: corepack enable
48-
49-
- name: Install
50-
run: pnpm install --frozen-lockfile
51-
5243
- name: Generate theme types
5344
run: pnpm generate-theme
5445

@@ -64,16 +55,11 @@ jobs:
6455
steps:
6556
- uses: actions/checkout@v4
6657

67-
- name: Use Node.js
68-
uses: actions/setup-node@v4
58+
- name: Setup pnpm
59+
uses: ./.github/actions/setup-pnpm
6960
with:
7061
node-version: ${{ env.NODE_VERSION }}
7162

72-
- name: Enable Corepack
73-
run: corepack enable
74-
75-
- run: pnpm install --frozen-lockfile
76-
7763
- run: pnpm generate
7864
- name: Check for Changes
7965
run: |
@@ -92,16 +78,11 @@ jobs:
9278
- name: Checkout branch
9379
uses: actions/checkout@v5
9480

95-
- uses: actions/setup-node@v4
81+
- name: Setup pnpm
82+
uses: ./.github/actions/setup-pnpm
9683
with:
9784
node-version: ${{ env.NODE_VERSION }}
9885

99-
- name: Enable Corepack
100-
run: corepack enable
101-
102-
- name: Install
103-
run: pnpm install --frozen-lockfile
104-
10586
- name: Install Playwright Browsers
10687
run: pnpm exec playwright install
10788

.github/workflows/release.yml

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,12 @@ jobs:
2323
- name: Checkout branch
2424
uses: actions/checkout@v5
2525

26-
- uses: actions/setup-node@v4
26+
- name: Setup pnpm with cache
27+
uses: ./.github/actions/setup-pnpm
2728
with:
2829
node-version: '22.x'
2930
registry-url: 'https://npm.pkg.github.com'
3031

31-
- name: Enable Corepack
32-
run: corepack enable
33-
34-
- name: Install
35-
run: pnpm install --frozen-lockfile
36-
3732
- name: Install Playwright Browsers
3833
run: pnpm exec playwright install
3934

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
name: Storybook
2+
3+
on:
4+
pull_request:
5+
types: [closed]
6+
7+
env:
8+
NODE_VERSION: 22.x
9+
10+
concurrency:
11+
group: storybook-deployment
12+
cancel-in-progress: false
13+
14+
permissions:
15+
contents: read
16+
pages: write
17+
id-token: write
18+
pull-requests: write
19+
issues: write
20+
21+
jobs:
22+
cleanup:
23+
name: Cleanup PR Preview
24+
runs-on: ubuntu-latest
25+
steps:
26+
- name: Restore main storybook from cache
27+
uses: actions/cache/restore@v4
28+
with:
29+
path: ./main-storybook
30+
key: storybook-main-${{ github.sha }}
31+
restore-keys: |
32+
storybook-main-
33+
34+
- name: Restore PR previews from cache
35+
uses: actions/cache/restore@v4
36+
with:
37+
path: ./pr-previews
38+
key: storybook-pr-previews-${{ github.sha }}
39+
restore-keys: |
40+
storybook-pr-previews-
41+
42+
- name: Remove PR preview
43+
run: |
44+
PR_NUMBER=${{ github.event.pull_request.number }}
45+
46+
# Remove the specific PR directory if it exists
47+
if [ -d "./pr-previews/${PR_NUMBER}" ]; then
48+
rm -rf "./pr-previews/${PR_NUMBER}"
49+
echo "Removed PR preview for PR #${PR_NUMBER}"
50+
else
51+
echo "No preview found for PR #${PR_NUMBER}"
52+
fi
53+
54+
- name: Save updated PR previews to cache
55+
uses: actions/cache/save@v4
56+
with:
57+
path: ./pr-previews
58+
key: storybook-pr-previews-${{ github.sha }}
59+
60+
- name: Combine main storybook with remaining PR previews
61+
run: |
62+
mkdir -p ./combined-pages
63+
64+
# Add main storybook if it exists in cache
65+
if [ -d ./main-storybook ]; then
66+
cp -r ./main-storybook/* ./combined-pages/
67+
echo "Added main storybook from cache"
68+
else
69+
echo "Warning: No main storybook found. Main branch needs to be deployed."
70+
fi
71+
72+
# Add remaining PR previews
73+
if [ -d ./pr-previews ] && [ "$(ls -A ./pr-previews)" ]; then
74+
cp -r ./pr-previews ./combined-pages/pr
75+
echo "Added remaining PR previews to combined pages"
76+
else
77+
echo "No PR previews remaining"
78+
fi
79+
80+
- name: Upload updated artifact
81+
uses: actions/upload-pages-artifact@v4
82+
with:
83+
path: './combined-pages'
84+
85+
- name: Deploy to GitHub Pages
86+
id: deployment
87+
uses: actions/deploy-pages@v4

0 commit comments

Comments
 (0)