Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions .github/workflows/frontend-deploy-workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -678,7 +678,7 @@ jobs:
run: |
git config --global user.name "${{ github.actor }}"
git config --global user.email "${{ github.actor }}@users.noreply.github.com"

- name: Setup Node with Cache
uses: Typeform/.github/shared-actions/setup-node-with-cache@v1
with:
Expand All @@ -688,7 +688,8 @@ jobs:
disable-restore-keys: ${{ inputs.disable-restore-keys }}
GH_TOKEN: ${{ secrets.GH_TOKEN }}
package-manager: ${{ inputs.package-manager }}

force-install: true # Deploy jobs need tooling dependencies (e.g., @datadog/datadog-ci)

- name: Download Build Artifacts
uses: Typeform/.github/shared-actions/download-build-artifacts@v1
with:
Expand Down
5 changes: 3 additions & 2 deletions .github/workflows/frontend-pr-workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,7 @@ jobs:
steps:
- name: Check out Git repository
uses: actions/checkout@v6

- name: Setup Node with Cache
uses: Typeform/.github/shared-actions/setup-node-with-cache@v1
with:
Expand All @@ -519,7 +519,8 @@ jobs:
disable-restore-keys: ${{ inputs.disable-restore-keys }}
GH_TOKEN: ${{ secrets.GH_TOKEN }}
package-manager: ${{ inputs.package-manager }}

force-install: true # Deploy jobs need tooling dependencies (e.g., @datadog/datadog-ci)

- name: Download Build Artifacts
uses: Typeform/.github/shared-actions/download-build-artifacts@v1
with:
Expand Down
11 changes: 11 additions & 0 deletions shared-actions/setup-node-with-cache/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ Standardized Node.js setup with enhanced yarn/pnpm caching and GitHub packages r
| `enable-yarn-cache` | Enable yarn global cache (~/.cache/yarn) | No | `'true'` |
| `cache-mode` | Cache strategy: `full`, `node_modules-only`, `yarn-cache-only`, or `pnpm-store-only` | No | `'full'` |
| `disable-restore-keys` | Disable restore-keys to avoid restoring stale caches | No | `'false'` |
| `force-install` | Force install even on cache hit (required for deploy jobs that need tooling dependencies) | No | `'false'` |

**📖 Need help choosing the right cache mode?** See the [Cache Strategy Guide](./CACHE-STRATEGY-GUIDE.md) for detailed recommendations.

Expand All @@ -63,6 +64,7 @@ None
8. **Logs cache status** with detailed debug information
9. **Installs dependencies** automatically on cache miss or verification failure
10. **Smart install detection** on cache hit (after verification):
- **force-install=true**: ALWAYS runs install (needed for deploy jobs with tooling dependencies)
- **Workspaces**: ALWAYS runs install (needs workspace symlink creation)
- **Lerna monorepos**: Runs install (needs lerna bootstrap)
- **Postinstall hooks**: Runs install (needs hook execution)
Expand Down Expand Up @@ -219,6 +221,15 @@ act pull_request -j build
```
**Use when**: You want to avoid restoring large stale caches. Only exact cache key matches will be restored.

### Force Install (Deploy Jobs)
```yaml
- uses: Typeform/.github/shared-actions/setup-node-with-cache@main
with:
GH_TOKEN: ${{ secrets.GH_TOKEN }}
force-install: true # Always run install, needed for deploy jobs with tooling dependencies
```
**Use when**: Your job runs deployment commands that depend on tooling packages (e.g., `@datadog/datadog-ci` for sourcemap uploads). Deploy jobs in shared workflows automatically set this to `true`.

### Disable Yarn Global Cache
```yaml
- uses: Typeform/.github/shared-actions/setup-node-with-cache@main
Expand Down
15 changes: 13 additions & 2 deletions shared-actions/setup-node-with-cache/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ inputs:
description: 'Package manager to use: "yarn" or "pnpm"'
required: false
default: "yarn"
force-install:
description: 'Force install even on cache hit (required for deploy jobs that need tooling dependencies)'
required: false
default: 'false'

runs:
using: 'composite'
Expand Down Expand Up @@ -307,20 +311,27 @@ runs:
shell: bash
run: |
set +e # Don't exit on error - we want to check all conditions

# Determine if we need to run install even when cache hits.
#
# Why this matters:
# - Cache restores node_modules, but doesn't run postinstall hooks
# - Monorepos need workspace linking even with cached node_modules
# - Some projects have critical postinstall scripts (e.g., building native modules)
# - Cached node_modules might be incomplete or corrupted
# - Deploy jobs need tooling dependencies (e.g., @datadog/datadog-ci) to be available
#
# We detect scenarios that require yarn install on cache hit:

PM="${{ inputs.package-manager }}"
NEEDS_INSTALL=false

# Force install if explicitly requested (deploy jobs, etc.)
if [ "${{ inputs.force-install }}" == "true" ]; then
echo "🔄 force-install=true - install will run even on cache hit"
NEEDS_INSTALL=true
fi

if [ "$PM" == "pnpm" ]; then
CACHE_HIT="${{ steps.pnpm-cache.outputs.cache-hit }}"
INTEGRITY_FILE="node_modules/.modules.yaml"
Expand Down