Skip to content

[pull] main from tsparticles:main #147

[pull] main from tsparticles:main

[pull] main from tsparticles:main #147

Workflow file for this run

name: Node.js CI
on:
push:
branches: [main, v4, v3, v2, v1]
pull_request:
branches: [main, v4, v3, v2, v1]
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
env:
NX_VERBOSE_LOGGING: true
NX_CLOUD_ACCESS_TOKEN: "${{ secrets.NX_CLOUD_ACCESS_TOKEN }}"
firebaseToken: "${{ secrets.FIREBASE_SERVICE_ACCOUNT_TSPARTICLES }}"
jobs:
build-and-deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
with:
ref: ${{ github.event.pull_request.head.ref || github.ref }}
repository: ${{ github.event.pull_request.head.repo.full_name || github.repository }}
fetch-depth: 0
- name: Derive SHAs for nx affected
uses: nrwl/nx-set-shas@v5
- uses: actions/setup-node@v6
with:
node-version: "24"
- uses: pnpm/action-setup@v5.0.0
with:
run_install: false
- name: Get pnpm store directory
id: pnpm-cache
run: |
echo "pnpm_cache_dir=$(pnpm store path)" >> $GITHUB_OUTPUT
- uses: actions/cache@v5
name: Setup pnpm cache
with:
path: ${{ steps.pnpm-cache.outputs.pnpm_cache_dir }}
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-pnpm-store-
- name: Install dependencies
run: pnpm install
- name: Initialize Nx Cloud or fall back to local
run: |
if [ -z "$NX_CLOUD_ACCESS_TOKEN" ]; then
echo "NX Cloud token missing — using local nx execution"
echo "NX_NO_CLOUD=true" >> $GITHUB_ENV
echo "NX_CLOUD_STARTED=false" >> $GITHUB_ENV
exit 0
fi
echo "NX Cloud token present — attempting distributed execution"
npx nx-cloud --version || echo "nx-cloud --version not available"
retries=0
max_retries=3
nx_cloud_started=false
until [ "$retries" -ge "$max_retries" ]; do
output=$(npx nx-cloud start-ci-run --distribute-on="5 linux-medium-js" 2>&1)
exit_code=$?
if echo "$output" | grep -q "401\|sufficient access\|unauthorized\|Unauthorized"; then
echo "NX Cloud auth failed (401) — falling back to local nx immediately"
echo "NX_NO_CLOUD=true" >> $GITHUB_ENV
echo "NX_CLOUD_STARTED=false" >> $GITHUB_ENV
exit 0
fi
if [ "$exit_code" -eq 0 ]; then
nx_cloud_started=true
break
fi
echo "nx-cloud start failed (attempt $((retries + 1))/${max_retries}). Retrying in $((2 ** retries))s..."
sleep $((2 ** retries))
retries=$((retries + 1))
done
if [ "$nx_cloud_started" = true ]; then
echo "NX_CLOUD_DISTRIBUTED_EXECUTION=true" >> $GITHUB_ENV
echo "NX_CLOUD_STARTED=true" >> $GITHUB_ENV
else
echo "nx-cloud start failed after ${max_retries} attempts — falling back to local nx"
echo "NX_NO_CLOUD=true" >> $GITHUB_ENV
echo "NX_CLOUD_STARTED=false" >> $GITHUB_ENV
fi
- name: Prettify README
run: pnpm run prettify:ci:readme
- name: Build packages
run: npx nx affected -t build:ci
- name: Deploy to Firebase (production)
if: env.firebaseToken != '' && github.ref == 'refs/heads/main' && github.event_name == 'push'
uses: FirebaseExtended/action-hosting-deploy@v0
with:
repoToken: "${{ secrets.GITHUB_TOKEN }}"
firebaseServiceAccount: "${{ secrets.FIREBASE_SERVICE_ACCOUNT_TSPARTICLES }}"
projectId: tsparticles
channelId: live
- name: Deploy to Firebase (PR preview)
if: env.firebaseToken != '' && github.event_name == 'pull_request' && github.actor == 'matteobruni'
uses: FirebaseExtended/action-hosting-deploy@v0
with:
repoToken: "${{ secrets.GITHUB_TOKEN }}"
firebaseServiceAccount: "${{ secrets.FIREBASE_SERVICE_ACCOUNT_TSPARTICLES }}"
projectId: tsparticles
- name: Stop Nx Cloud session
if: always() && env.NX_CLOUD_STARTED == 'true'
continue-on-error: true
run: npx nx-cloud stop-all-agents || echo "nx-cloud stop failed — ignoring"