Skip to content

Commit bbab4d0

Browse files
authored
[ci] Refactor: Use composite actions to simplify github workflows (#8504)
1 parent e8e5910 commit bbab4d0

18 files changed

Lines changed: 246 additions & 254 deletions
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
name: Get latest release
2+
description: Returns the tag name of the latest non-draft GitHub release for the current repository
3+
outputs:
4+
release:
5+
description: Tag name of the latest non-draft release (e.g. "v0.16.0")
6+
value: ${{ steps.fetch.outputs.result }}
7+
8+
runs:
9+
using: 'composite'
10+
steps:
11+
- id: fetch
12+
uses: actions/github-script@v7
13+
with:
14+
result-encoding: string
15+
script: |
16+
const releases = await github.paginate(github.rest.repos.listReleases, {
17+
...context.repo,
18+
per_page: 100,
19+
});
20+
const latest = releases.find((r) => !r.draft);
21+
if (!latest) throw new Error('No non-draft release found');
22+
return latest.tag_name;
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
name: Setup playground build
2+
description: Set up the playground with prepare-ci, depends on setup-pnpm
3+
inputs:
4+
node-version:
5+
required: true
6+
description: 'Node version, e.g. 24.x'
7+
fail-on-cache-miss:
8+
required: false
9+
description: 'true to fail on cache miss'
10+
prod:
11+
required: false
12+
description: 'true to build prod'
13+
14+
runs:
15+
using: 'composite'
16+
steps:
17+
# setup-pnpm must be completed before this point
18+
- name: Restore build cache
19+
uses: actions/cache/restore@v5
20+
id: build-cache
21+
with:
22+
path: |
23+
packages/lexical-playground/build
24+
packages/*/dist
25+
key: build-${{ inputs.prod == 'true' && 'prod' || 'dev' }}-${{ inputs.node-version }}-${{ runner.os }}-${{ runner.arch }}-${{ github.sha }}
26+
fail-on-cache-miss: ${{ inputs.fail-on-cache-miss == 'true' && 'true' || ''}}
27+
- name: Build
28+
shell: bash
29+
if: steps.build-cache.outputs.cache-hit != 'true'
30+
run: pnpm run ${{ inputs.prod == 'prod' && 'prepare-ci-prod' || 'prepare-ci' }}
31+
- name: Save build cache
32+
if: steps.build-cache.outputs.cache-hit != 'true'
33+
uses: actions/cache/save@v5
34+
with:
35+
path: |
36+
packages/lexical-playground/build
37+
packages/*/dist
38+
key: ${{ steps.build-cache.outputs.cache-primary-key }}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
name: Setup playwright
2+
description: Set up Playwright, depends on setup-pnpm
3+
4+
inputs:
5+
node-version:
6+
required: true
7+
description: 'Node version, e.g. 24.x'
8+
fail-on-cache-miss:
9+
required: false
10+
description: 'true to fail on cache miss'
11+
12+
runs:
13+
using: 'composite'
14+
steps:
15+
- name: Compute path
16+
id: vars
17+
shell: bash
18+
run: echo "cache_playwright_path=${{ runner.os == 'macOS' && '~/Library/Caches/ms-playwright' || runner.os == 'Windows' && 'C:\\Users\\runneradmin\\AppData\\Local\\ms-playwright' || '~/.cache/ms-playwright' }}" >> "$GITHUB_OUTPUT"
19+
- name: Install required ubuntu-latest packages
20+
shell: bash
21+
if: runner.os == 'Linux'
22+
run: |
23+
sudo apt-get update
24+
sudo apt-get install xvfb
25+
# setup-pnpm must be completed before this point
26+
- name: Restore playwright from cache
27+
uses: actions/cache/restore@v5
28+
id: playwright-cache
29+
with:
30+
path: ${{ steps.vars.outputs.cache_playwright_path }}
31+
key: playwright-v2-${{ inputs.node-version }}-${{ runner.os }}-${{ runner.arch }}-${{ hashFiles('pnpm-lock.yaml') }}
32+
fail-on-cache-miss: ${{ inputs.fail-on-cache-miss }}
33+
- name: Install playwright
34+
shell: bash
35+
run: |
36+
pnpm exec playwright install
37+
pnpm exec playwright install --list
38+
- name: Save playwright to cache
39+
if: steps.playwright-cache.outputs.cache-hit != 'true'
40+
uses: actions/cache/save@v5
41+
with:
42+
path: ${{ steps.vars.outputs.cache_playwright_path }}
43+
key: ${{ steps.playwright-cache.outputs.cache-primary-key }}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: Setup node and pnpm
2+
description: Installs node and pnpm and the package.json dependencies, depends on actions/checkout
3+
inputs:
4+
node-version:
5+
required: true
6+
description: 'Node version, e.g. 24.x'
7+
registry-url:
8+
required: false
9+
description: 'actions/setup-node: npm registry to use'
10+
pnpm-install-args:
11+
required: false
12+
default: '--frozen-lockfile'
13+
description: 'arguments for pnpm install, default is --frozen-lockfile'
14+
15+
runs:
16+
using: 'composite'
17+
steps:
18+
- uses: pnpm/action-setup@v6
19+
- name: Use Node.js ${{ inputs.node-version }}
20+
uses: actions/setup-node@v6
21+
with:
22+
cache: 'pnpm'
23+
node-version: ${{ inputs.node-version }}
24+
registry-url: ${{ inputs.registry-url }}
25+
- name: Install dependencies
26+
shell: bash
27+
run: pnpm install ${{ inputs.pnpm-install-args }}

.github/workflows/call-core-tests.yml

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,9 @@ jobs:
1515
CI: true
1616
steps:
1717
- uses: actions/checkout@v6
18-
- name: Use Node.js ${{ matrix.node-version }}
19-
uses: actions/setup-node@v6
18+
- uses: ./.github/actions/setup-pnpm
2019
with:
2120
node-version: ${{ matrix.node-version }}
22-
- uses: pnpm/action-setup@v6
23-
- name: Install dependencies
24-
run: pnpm install --frozen-lockfile
2521
- run: pnpm run ci-check
2622
- run: pnpm run build
2723
- run: pnpm run build-www
@@ -37,17 +33,7 @@ jobs:
3733
CI: true
3834
steps:
3935
- uses: actions/checkout@v6
40-
- name: Use Node.js ${{ matrix.node-version }}
41-
uses: actions/setup-node@v6
36+
- uses: ./.github/actions/setup-pnpm
4237
with:
4338
node-version: ${{ matrix.node-version }}
44-
- uses: pnpm/action-setup@v6
45-
- name: Install dependencies
46-
run: pnpm install --frozen-lockfile
47-
- name: Install React ${{ matrix.override-react-version }}
48-
if: matrix.override-react-version != ''
49-
# This should be safe since we are caching pnpm store and not node_modules
50-
run: |
51-
node ./scripts/override-react.mjs --version=${{ matrix.override-react-version }}
52-
grep version node_modules/{react,react-dom}/package.json
5339
- run: pnpm run test-unit

0 commit comments

Comments
 (0)