Files
self/.github/workflows/qrcode-sdk-ci.yml
Justin Hernandez 2cc2951b77 Merge pull request #1669 from selfxyz/release/staging-2026-01-29
chore: fix circuits tests in staging
2026-01-28 22:10:55 -08:00

329 lines
11 KiB
YAML

name: QRCode SDK CI
env:
# Build environment versions
# Node version is read from .nvmrc during workflow execution
# Cache versioning - increment these to bust caches when needed
GH_CACHE_VERSION: v1 # Global cache version
GH_YARN_CACHE_VERSION: v1 # Yarn-specific cache version
GH_SDK_CACHE_VERSION: v1 # SDK build cache version
on:
pull_request:
branches:
- dev
- staging
- main
jobs:
check_changes:
runs-on: ubuntu-slim
outputs:
should_run: ${{ steps.filter.outputs.should_run }}
steps:
- uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Check if should run
id: filter
run: |
set -e
if [[ "${{ github.base_ref }}" == "main" ]] || [[ "${{ github.base_ref }}" == "staging" ]]; then
echo "should_run=true" >> $GITHUB_OUTPUT
echo "Running for ${{ github.base_ref }} - no path filter"
else
# For dev branch, check if relevant files changed
# Fetch the base branch to ensure it's available for comparison
git fetch origin ${{ github.base_ref }} --depth=1
CHANGED_FILES=$(git diff --name-only origin/${{ github.base_ref }}...HEAD) || {
echo "Error: Failed to diff against base branch"
exit 1
}
if echo "$CHANGED_FILES" | grep -qE "^(sdk/qrcode/|common/|\.github/workflows/qrcode-sdk-ci\.yml|\.github/actions/)"; then
echo "should_run=true" >> $GITHUB_OUTPUT
echo "Running for dev - relevant files changed"
else
echo "should_run=false" >> $GITHUB_OUTPUT
echo "Skipping for dev - no relevant files changed"
fi
fi
# Build dependencies once and cache for other jobs
build:
needs: check_changes
if: github.event.pull_request.draft == false && needs.check_changes.outputs.should_run == 'true'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- name: Read and sanitize Node.js version
shell: bash
run: |
if [ ! -f .nvmrc ] || [ -z "$(cat .nvmrc)" ]; then
echo "❌ .nvmrc is missing or empty"; exit 1;
fi
VERSION="$(tr -d '\r\n' < .nvmrc)"
VERSION="${VERSION#v}"
if ! [[ "$VERSION" =~ ^[0-9]+(\.[0-9]+){0,2}$ ]]; then
echo "Invalid .nvmrc content: '$VERSION'"; exit 1;
fi
echo "NODE_VERSION=$VERSION" >> "$GITHUB_ENV"
echo "NODE_VERSION_SANITIZED=${VERSION//\//-}" >> "$GITHUB_ENV"
- name: Use Node.js ${{ env.NODE_VERSION }}
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
- name: Enable Corepack
run: corepack enable
- name: Cache Yarn dependencies
id: yarn-cache
uses: ./.github/actions/cache-yarn
with:
path: |
.yarn/cache
node_modules
sdk/qrcode/node_modules
common/node_modules
cache-version: ${{ env.GH_YARN_CACHE_VERSION }}-node-${{ env.NODE_VERSION_SANITIZED }}
- name: Install Dependencies
uses: ./.github/actions/yarn-install
- name: Build dependencies
shell: bash
run: |
yarn workspace @selfxyz/common build
yarn workspace @selfxyz/sdk-common build
yarn workspace @selfxyz/qrcode build
- name: Cache build artifacts
uses: ./.github/actions/cache-sdk-build
with:
mode: save
cache-version: ${{ env.GH_SDK_CACHE_VERSION }}
# Quality checks job
quality-checks:
runs-on: ubuntu-latest
needs: [check_changes, build]
if: github.event.pull_request.draft == false && needs.check_changes.outputs.should_run == 'true'
steps:
- uses: actions/checkout@v6
- name: Read and sanitize Node.js version
shell: bash
run: |
if [ ! -f .nvmrc ] || [ -z "$(cat .nvmrc)" ]; then
echo "❌ .nvmrc is missing or empty"; exit 1;
fi
VERSION="$(tr -d '\r\n' < .nvmrc)"
VERSION="${VERSION#v}"
if ! [[ "$VERSION" =~ ^[0-9]+(\.[0-9]+){0,2}$ ]]; then
echo "Invalid .nvmrc content: '$VERSION'"; exit 1;
fi
echo "NODE_VERSION=$VERSION" >> "$GITHUB_ENV"
echo "NODE_VERSION_SANITIZED=${VERSION//\//-}" >> "$GITHUB_ENV"
- name: Use Node.js ${{ env.NODE_VERSION }}
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
- name: Enable Corepack
run: corepack enable
- name: Cache Yarn dependencies
id: yarn-cache
uses: ./.github/actions/cache-yarn
with:
path: |
.yarn/cache
node_modules
sdk/qrcode/node_modules
common/node_modules
cache-version: ${{ env.GH_YARN_CACHE_VERSION }}-node-${{ env.NODE_VERSION_SANITIZED }}
- name: Install Dependencies
uses: ./.github/actions/yarn-install
- name: Restore build artifacts
id: restore-build
uses: ./.github/actions/cache-sdk-build
with:
mode: restore
cache-version: ${{ env.GH_SDK_CACHE_VERSION }}
fail-on-cache-miss: false
- name: Build dependencies (fallback on cache miss)
if: steps.restore-build.outputs.cache-hit != 'true'
run: |
yarn workspace @selfxyz/common build
yarn workspace @selfxyz/sdk-common build
yarn workspace @selfxyz/qrcode build
- name: Run linter
run: yarn workspace @selfxyz/qrcode lint:imports:check
- name: Check Prettier formatting
run: yarn workspace @selfxyz/qrcode lint
- name: Type checking
run: yarn workspace @selfxyz/qrcode types
- name: Log cache status
run: |
echo "Cache hit results:"
echo "- Yarn cache hit: ${{ steps.yarn-cache.outputs.cache-hit }}"
# Build verification job
build-verification:
runs-on: ubuntu-latest
needs: [check_changes, build]
if: github.event.pull_request.draft == false && needs.check_changes.outputs.should_run == 'true'
steps:
- uses: actions/checkout@v6
- name: Read and sanitize Node.js version
shell: bash
run: |
if [ ! -f .nvmrc ] || [ -z "$(cat .nvmrc)" ]; then
echo "❌ .nvmrc is missing or empty"; exit 1;
fi
VERSION="$(tr -d '\r\n' < .nvmrc)"
VERSION="${VERSION#v}"
if ! [[ "$VERSION" =~ ^[0-9]+(\.[0-9]+){0,2}$ ]]; then
echo "Invalid .nvmrc content: '$VERSION'"; exit 1;
fi
echo "NODE_VERSION=$VERSION" >> "$GITHUB_ENV"
echo "NODE_VERSION_SANITIZED=${VERSION//\//-}" >> "$GITHUB_ENV"
- name: Use Node.js ${{ env.NODE_VERSION }}
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
- name: Enable Corepack
run: corepack enable
- name: Cache Yarn dependencies
id: yarn-cache
uses: ./.github/actions/cache-yarn
with:
path: |
.yarn/cache
node_modules
sdk/qrcode/node_modules
common/node_modules
cache-version: ${{ env.GH_YARN_CACHE_VERSION }}-node-${{ env.NODE_VERSION_SANITIZED }}
- name: Install Dependencies
uses: ./.github/actions/yarn-install
- name: Restore build artifacts
id: restore-build
uses: ./.github/actions/cache-sdk-build
with:
mode: restore
cache-version: ${{ env.GH_SDK_CACHE_VERSION }}
fail-on-cache-miss: false
- name: Build dependencies (fallback on cache miss)
if: steps.restore-build.outputs.cache-hit != 'true'
run: |
yarn workspace @selfxyz/common build
yarn workspace @selfxyz/sdk-common build
yarn workspace @selfxyz/qrcode build
- name: Verify build artifacts
run: |
echo "Verifying build artifacts..."
ls -la common/dist/
ls -la sdk/sdk-common/dist/
ls -la sdk/qrcode/dist/
echo "✅ Build artifacts verified"
# Integration test job
integration-test:
runs-on: ubuntu-latest
needs: [check_changes, build]
if: github.event.pull_request.draft == false && needs.check_changes.outputs.should_run == 'true'
steps:
- uses: actions/checkout@v6
- name: Read and sanitize Node.js version
shell: bash
run: |
if [ ! -f .nvmrc ] || [ -z "$(cat .nvmrc)" ]; then
echo "❌ .nvmrc is missing or empty"; exit 1;
fi
VERSION="$(tr -d '\r\n' < .nvmrc)"
VERSION="${VERSION#v}"
if ! [[ "$VERSION" =~ ^[0-9]+(\.[0-9]+){0,2}$ ]]; then
echo "Invalid .nvmrc content: '$VERSION'"; exit 1;
fi
echo "NODE_VERSION=$VERSION" >> "$GITHUB_ENV"
echo "NODE_VERSION_SANITIZED=${VERSION//\//-}" >> "$GITHUB_ENV"
- name: Use Node.js ${{ env.NODE_VERSION }}
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
- name: Enable Corepack
run: corepack enable
- name: Cache Yarn dependencies
id: yarn-cache
uses: ./.github/actions/cache-yarn
with:
path: |
.yarn/cache
node_modules
sdk/qrcode/node_modules
common/node_modules
cache-version: ${{ env.GH_YARN_CACHE_VERSION }}-node-${{ env.NODE_VERSION_SANITIZED }}
- name: Install Dependencies
uses: ./.github/actions/yarn-install
- name: Restore build artifacts
id: restore-build
uses: ./.github/actions/cache-sdk-build
with:
mode: restore
cache-version: ${{ env.GH_SDK_CACHE_VERSION }}
fail-on-cache-miss: false
- name: Build dependencies (fallback on cache miss)
if: steps.restore-build.outputs.cache-hit != 'true'
run: |
yarn workspace @selfxyz/common build
yarn workspace @selfxyz/sdk-common build
yarn workspace @selfxyz/qrcode build
- name: Check for nested require() in tests
run: |
# Check SDK tests for nested require patterns that cause OOM
if grep -rE "require\(['\"]react(-native)?['\"])" sdk/qrcode/src/ sdk/qrcode/tests/ 2>/dev/null; then
echo "❌ Found nested require() patterns that cause OOM in CI"
exit 1
fi
echo "✅ No nested require() patterns found"
- name: Run tests
run: yarn workspace @selfxyz/qrcode test
- name: Test package import
run: |
echo "Testing package import..."
node -e "
const pkg = require('./sdk/qrcode/dist/cjs/index.cjs');
console.log('✅ Package imported successfully');
console.log('Package exports:', Object.keys(pkg));
"
- name: Log cache status
run: |
echo "Cache hit results:"
echo "- Yarn cache hit: ${{ steps.yarn-cache.outputs.cache-hit }}"