Skip to content

Commit 537f51e

Browse files
committed
chore(ci): update Node.js CI configuration for improved execution and caching
1 parent de70fa6 commit 537f51e

File tree

2 files changed

+28
-96
lines changed

2 files changed

+28
-96
lines changed

.github/workflows/nodejs.yml

Lines changed: 19 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -1,140 +1,69 @@
11
name: Node.js CI
22
on:
33
push:
4-
branches:
5-
- main
6-
- v4
7-
- v3
8-
- v2
9-
- v1
4+
branches: [main, v4, v3, v2, v1]
105
pull_request:
11-
branches:
12-
- main
13-
- v4
14-
- v3
15-
- v2
16-
- v1
6+
branches: [main, v4, v3, v2, v1]
177

188
env:
19-
NX_CLOUD_DISTRIBUTED_EXECUTION: false
9+
NX_CLOUD_DISTRIBUTED_EXECUTION: true
2010
NX_CLOUD_ACCESS_TOKEN: '${{ secrets.NX_CLOUD_ACCESS_TOKEN }}'
2111
firebaseToken: '${{ secrets.FIREBASE_SERVICE_ACCOUNT_TSPARTICLES }}'
2212

2313
jobs:
24-
main:
14+
build-and-deploy:
2515
runs-on: ubuntu-latest
26-
if: ${{ github.event_name != 'pull_request' }}
2716
steps:
2817
- uses: actions/checkout@v6
29-
name: Checkout [main]
3018
with:
19+
# Gestisce sia push che pull request correttamente
20+
ref: ${{ github.event.pull_request.head.ref || github.ref }}
21+
repository: ${{ github.event.pull_request.head.repo.full_name || github.repository }}
3122
fetch-depth: 0
3223

33-
- name: Derive appropriate SHAs for base and head for `nx affected` commands
24+
- name: Derive SHAs for nx affected
3425
uses: nrwl/nx-set-shas@v4
3526

3627
- uses: actions/setup-node@v6
3728
with:
3829
node-version: '24'
3930

4031
- uses: pnpm/action-setup@v4.2.0
41-
name: Install pnpm
42-
id: pnpm-install
4332
with:
4433
run_install: false
4534

46-
- name: Get pnpm store directory
47-
id: pnpm-cache
48-
run: |
49-
echo "pnpm_cache_dir=$(pnpm store path)" >> $GITHUB_OUTPUT
50-
51-
- uses: actions/cache@v5
52-
name: Setup pnpm cache
35+
- name: Setup pnpm cache
36+
uses: actions/cache@v5
5337
with:
54-
path: ${{ steps.pnpm-cache.outputs.pnpm_cache_dir }}
38+
path: |
39+
~/.pnpm-store
5540
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
56-
restore-keys: |
57-
${{ runner.os }}-pnpm-store-
5841

5942
- name: Install dependencies
60-
run: pnpm install
43+
run: pnpm ci
6144

6245
- name: Prettify README
6346
run: pnpm run prettify:ci:readme
6447

65-
#- name: Initialize Nx Cloud
66-
# run: npx nx-cloud start-ci-run --distribute-on="5 linux-medium-js"
67-
6848
- name: Build packages
6949
run: npx nx affected -t build:ci
7050

71-
- if: env.firebaseToken != '' && github.ref == 'refs/heads/main'
51+
# Deploy Produzione (Solo su push su main)
52+
- if: env.firebaseToken != '' && github.ref == 'refs/heads/main' && github.event_name == 'push'
7253
uses: FirebaseExtended/action-hosting-deploy@v0
7354
with:
7455
repoToken: '${{ secrets.GITHUB_TOKEN }}'
7556
firebaseServiceAccount: '${{ secrets.FIREBASE_SERVICE_ACCOUNT_TSPARTICLES }}'
7657
projectId: tsparticles
7758
channelId: live
7859

79-
- if: env.firebaseToken != '' && github.ref == 'refs/heads/dev'
60+
# Deploy Preview (Solo per PR di matteobruni)
61+
- if: env.firebaseToken != '' && github.event_name == 'pull_request' && github.actor == 'matteobruni'
8062
uses: FirebaseExtended/action-hosting-deploy@v0
8163
with:
8264
repoToken: '${{ secrets.GITHUB_TOKEN }}'
8365
firebaseServiceAccount: '${{ secrets.FIREBASE_SERVICE_ACCOUNT_TSPARTICLES }}'
8466
projectId: tsparticles
85-
channelId: next
86-
87-
pr:
88-
runs-on: ubuntu-latest
89-
if: ${{ github.event_name == 'pull_request' }}
90-
steps:
91-
- uses: actions/checkout@v6
92-
with:
93-
ref: ${{ github.event.pull_request.head.ref }}
94-
repository: ${{ github.event.pull_request.head.repo.full_name }}
95-
fetch-depth: 0
96-
97-
- name: Derive appropriate SHAs for base and head for `nx affected` commands
98-
uses: nrwl/nx-set-shas@v4
99-
100-
- uses: actions/setup-node@v6
101-
with:
102-
node-version: '24'
103-
104-
- uses: pnpm/action-setup@v4.2.0
105-
name: Install pnpm
106-
id: pnpm-install
107-
with:
108-
run_install: false
10967

110-
- name: Get pnpm store directory
111-
id: pnpm-cache
112-
run: |
113-
echo "pnpm_cache_dir=$(pnpm store path)" >> $GITHUB_OUTPUT
114-
115-
- uses: actions/cache@v5
116-
name: Setup pnpm cache
117-
with:
118-
path: ${{ steps.pnpm-cache.outputs.pnpm_cache_dir }}
119-
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
120-
restore-keys: |
121-
${{ runner.os }}-pnpm-store-
122-
123-
- name: Install dependencies
124-
run: pnpm install
125-
126-
- name: Prettify README
127-
run: pnpm run prettify:ci:readme
128-
129-
#- name: Initialize Nx Cloud
130-
# run: npx nx-cloud start-ci-run --distribute-on="5 linux-medium-js"
131-
132-
- name: Build packages
133-
run: npx nx affected -t build:ci
134-
135-
- if: env.firebaseToken != '' && contains(github.ref, 'refs/pull') && github.actor == 'matteobruni'
136-
uses: FirebaseExtended/action-hosting-deploy@v0
137-
with:
138-
repoToken: '${{ secrets.GITHUB_TOKEN }}'
139-
firebaseServiceAccount: '${{ secrets.FIREBASE_SERVICE_ACCOUNT_TSPARTICLES }}'
140-
projectId: tsparticles
68+
- run: npx nx fix-ci
69+
if: always() # IMPORTANT: Always run

.github/workflows/npm-publish.yml

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ permissions:
1010
contents: read
1111

1212
env:
13-
NX_CLOUD_DISTRIBUTED_EXECUTION: false
13+
NX_CLOUD_DISTRIBUTED_EXECUTION: true
1414
NX_CLOUD_ACCESS_TOKEN: '${{ secrets.NX_CLOUD_ACCESS_TOKEN }}'
1515

1616
jobs:
@@ -44,11 +44,11 @@ jobs:
4444
restore-keys: |
4545
${{ runner.os }}-pnpm-store-
4646
47-
- name: Install Dependencies
48-
run: pnpm install
47+
- name: Initialize Nx Cloud
48+
run: npx nx-cloud start-ci-run --distribute-on="5 linux-medium-js"
4949

50-
#- name: Initialize Nx Cloud
51-
# run: npx nx-cloud start-ci-run --distribute-on="5 linux-medium-js"
50+
- name: Install Dependencies
51+
run: pnpm ci
5252

5353
- name: Build All Packages
5454
run: npx lerna run build:ci
@@ -75,4 +75,7 @@ jobs:
7575
$BASE_CMD --dist-tag v3
7676
else
7777
$BASE_CMD
78-
fi
78+
fi
79+
80+
- run: npx nx fix-ci
81+
if: always() # IMPORTANT: Always run

0 commit comments

Comments
 (0)