ci: Reuse common build actions and fix turbo outputs (no-changelog) (#15830)

This commit is contained in:
shortstacked
2025-06-03 10:49:36 +01:00
committed by GitHub
parent d00060adad
commit 8201202a54
7 changed files with 106 additions and 133 deletions

View File

@@ -1,22 +1,30 @@
name: 'Setup Environment and Build Project'
description: 'Sets up Node.js with pnpm, installs dependencies, enables Turborepo caching, and builds the project.'
description: 'Sets up Node.js with pnpm, installs dependencies, (optional) enables Turborepo caching, and (optional) builds the project.'
inputs:
node-version:
description: 'Node.js version to use.'
required: false
default: '22.x'
default: '20.x'
enable-caching:
description: Flag to enable/disable all caching (pnpm store, Turborepo, and dist folders).'
description: 'Flag to enable/disable all caching.'
required: false
default: 'true'
cache-suffix:
description: 'Suffix to add to the dist folder cache key.'
description: 'Suffix to add to the cache key.'
required: false
default: 'build'
default: 'base:build'
skip-build:
description: 'Skip the build step, useful when restoring cached artifacts.'
required: false
default: 'false'
cache-paths:
description: 'Paths to cache. Defaults to dist folders.'
required: false
default: './packages/**/dist'
runs:
using: "composite"
using: 'composite'
steps:
- name: Setup pnpm CLI
uses: pnpm/action-setup@a7487c7e89a18df4991f7f222e4898a00d66ddda # v4.1.0
@@ -38,12 +46,13 @@ runs:
uses: useblacksmith/caching-for-turbo@v1
- name: Build packages
if: inputs.skip-build == 'false'
run: pnpm build
shell: bash
- name: Cache 'dist' folders
if: inputs.enable-caching == 'true'
- name: Cache artifacts
if: inputs.enable-caching == 'true' && inputs.skip-build == 'false'
uses: useblacksmith/cache@v5
with:
path: ./packages/**/dist
key: ${{ github.sha }}:${{ inputs.cache-suffix }}
path: ${{ inputs.cache-paths }}
key: ${{ github.sha }}-${{ inputs.cache-suffix }}

View File

@@ -17,23 +17,11 @@ jobs:
with:
ref: refs/pull/${{ github.event.pull_request.number }}/merge
- uses: useblacksmith/setup-node@65c6ca86fdeb0ab3d85e78f57e4f6a7e4780b391 # v5
- name: Setup Environment and Build Project
uses: ./.github/actions/setup-and-build
with:
node-version: 20.x
- name: Setup corepack and pnpm
run: |
npm i -g corepack@0.31
corepack enable
- name: Install dependencies
run: pnpm install --frozen-lockfile
- name: Setup build cache
uses: useblacksmith/caching-for-turbo@bafb57e7ebdbf1185762286ec94d24648cd3938a # v1
- name: Build
run: pnpm build
node-version: '20.x'
enable-caching: true
- name: Run formatcheck
run: pnpm format:check
@@ -41,12 +29,6 @@ jobs:
- name: Run typecheck
run: pnpm typecheck
- name: Cache build artifacts
uses: useblacksmith/cache/save@c5fe29eb0efdf1cf4186b9f7fcbbcbc0cf025662 # v5
with:
path: ./packages/**/dist
key: ${{ github.sha }}-base:build
unit-test:
name: Unit tests
uses: ./.github/workflows/units-tests-reusable.yml

View File

@@ -8,11 +8,16 @@ on:
required: false
type: string
default: master
nodeVersion:
description: Version of node to use.
required: false
type: string
default: 20.x
cacheKey:
description: Cache key for modules and build artifacts.
required: false
default: ''
type: string
default: ''
jobs:
lint:
@@ -23,32 +28,12 @@ jobs:
with:
ref: ${{ inputs.ref }}
- uses: useblacksmith/setup-node@65c6ca86fdeb0ab3d85e78f57e4f6a7e4780b391 # v5
- name: Setup Environment
uses: ./.github/actions/setup-and-build
with:
node-version: 20.x
- name: Setup corepack and pnpm
run: |
npm i -g corepack@0.31
corepack enable
- name: Install dependencies
run: pnpm install --frozen-lockfile
- name: Setup build cache
uses: useblacksmith/caching-for-turbo@bafb57e7ebdbf1185762286ec94d24648cd3938a # v1
- name: Build
if: ${{ inputs.cacheKey == '' }}
run: pnpm build
- name: Restore cached build artifacts
if: ${{ inputs.cacheKey != '' }}
uses: useblacksmith/cache/restore@c5fe29eb0efdf1cf4186b9f7fcbbcbc0cf025662 # v5
with:
path: ./packages/**/dist
key: ${{ inputs.cacheKey }}
fail-on-cache-miss: true
node-version: ${{ inputs.nodeVersion }}
enable-caching: true
skip-build: ${{ inputs.cacheKey != '' }}
- name: Lint Backend
run: pnpm lint:backend

View File

@@ -47,27 +47,13 @@ jobs:
with:
ref: ${{ inputs.ref }}
- name: Use Node.js ${{ inputs.nodeVersion }}
uses: useblacksmith/setup-node@65c6ca86fdeb0ab3d85e78f57e4f6a7e4780b391 # v5.0.4
- name: Setup Environment and Build Project
uses: ./.github/actions/setup-and-build
with:
node-version: ${{ inputs.nodeVersion }}
skip-build: ${{ inputs.cacheKey != '' }}
- name: Setup corepack and pnpm
run: |
npm i -g corepack@0.31
corepack enable
- name: Install dependencies
run: pnpm install --frozen-lockfile
- name: Setup build cache
uses: useblacksmith/caching-for-turbo@bafb57e7ebdbf1185762286ec94d24648cd3938a # v1
- name: Build
if: ${{ inputs.cacheKey == '' }}
run: pnpm build
- name: Restore cached build artifacts
- name: Restore cached build artifacts only
if: ${{ inputs.cacheKey != '' }}
uses: useblacksmith/cache/restore@c5fe29eb0efdf1cf4186b9f7fcbbcbc0cf025662 # v5.0.2
with:
@@ -86,13 +72,12 @@ jobs:
run: pnpm test:frontend
- name: Upload test results to Codecov
if: ${{ !cancelled() }} # Run even if tests fail
if: ${{ !cancelled() }}
uses: codecov/test-results-action@47f89e9acb64b76debcd5ea40642d25a4adced9f # v1.1.1
with:
token: ${{ secrets.CODECOV_TOKEN }}
- name: Upload coverage to Codecov
if: inputs.collectCoverage
uses: codecov/codecov-action@18283e04ce6e62d37312384ff67231eb8fd56d24 # v5.4.3
with:
token: ${{ secrets.CODECOV_TOKEN }}