mirror of
https://github.com/seepine/action-setup-pnpm.git
synced 2025-02-23 15:50:13 +08:00
fix: skip install if cache hit
This commit is contained in:
parent
0b86b95ff8
commit
38ce16269a
@ -4,6 +4,8 @@
|
||||
|
||||
## Usage
|
||||
|
||||
It will setup pnpm and run `pnpm install`.
|
||||
|
||||
```yml
|
||||
- name: Setup pnpm and Install
|
||||
uses: seepine/actions-setup-pnpm@v1
|
||||
@ -11,8 +13,10 @@
|
||||
|
||||
## Input
|
||||
|
||||
|
||||
| Output Item | Description | Required | Default |
|
||||
| ------------ | ------------------------------------------------------------------------------------------------------ | -------- | ------- |
|
||||
| run_instasll | The working dir for the action | false | true |
|
||||
| run_install | If specified, run pnpm install. | false | true |
|
||||
| install_cmd | Default install cmd is <pnpm install --frozen-lockfile --prefer-offline> | false | - |
|
||||
| enable-corepack | Enable corepack, not use pnpm/action-setup action | false | true |
|
||||
| verison | Only enable-corepack false, If you're not setting the packageManager field in package.json, set the version here | false | 8 |
|
||||
| cwd | Changes node's process.cwd() if the project is not located on the root. Default to process.cwd() files | false | . |
|
||||
|
50
action.yml
50
action.yml
@ -1,11 +1,23 @@
|
||||
name: 'PNPM install'
|
||||
name: 'Pnpm Setup and Install'
|
||||
description: 'Setup pnpm and run pnpm install with cache enabled'
|
||||
|
||||
inputs:
|
||||
run_install:
|
||||
description: If specified, run `pnpm install`
|
||||
description: "If specified, run pnpm install."
|
||||
required: false
|
||||
default: 'true'
|
||||
install_cmd:
|
||||
description: "Default install cmd is <pnpm install --frozen-lockfile --prefer-offline>"
|
||||
required: false
|
||||
default: 'pnpm install --frozen-lockfile --prefer-offline'
|
||||
enable-corepack:
|
||||
description: "Enable corepack"
|
||||
required: false
|
||||
default: 'true'
|
||||
verison:
|
||||
description: "Only enable-corepack false, If you're not setting the packageManager field in package.json, add the version here"
|
||||
required: false
|
||||
default: '8'
|
||||
cwd:
|
||||
description: "Changes node's process.cwd() if the project is not located on the root. Default to process.cwd()"
|
||||
required: false
|
||||
@ -14,16 +26,20 @@ inputs:
|
||||
runs:
|
||||
using: 'composite'
|
||||
steps:
|
||||
# If you want to set pnpm version, setting the packageManager field in package.json like "packageManager":"pnpm@8.10.2"
|
||||
- name: ⚙️ Enable Corepack
|
||||
if: ${{ inputs.enable-corepack == 'true' }}
|
||||
shell: bash
|
||||
working-directory: ${{ inputs.cwd }}
|
||||
run: |
|
||||
corepack enable
|
||||
corepack enable npm
|
||||
echo "corepack enabled"
|
||||
echo "pnpm version : $(pnpm -v)"
|
||||
echo "pnpm store path : $(pnpm store path)"
|
||||
|
||||
- uses: pnpm/action-setup@v2.2.4
|
||||
if: ${{ inputs.enable-corepack == 'false' }}
|
||||
with:
|
||||
run_install: false
|
||||
# If you're not setting the packageManager field in package.json, add the version here
|
||||
version: ${{ inputs.verison }}
|
||||
|
||||
- name: Expose pnpm config(s) through "$GITHUB_OUTPUT"
|
||||
id: pnpm-config
|
||||
@ -41,25 +57,33 @@ runs:
|
||||
name: Get hash of lock files
|
||||
id: get-hash
|
||||
with:
|
||||
# Prevent installing new dependencies without using pnpm
|
||||
patterns: |
|
||||
**/package-lock.json
|
||||
**/pnpm-lock.yaml
|
||||
**/yarn.lock
|
||||
|
||||
- uses: actions/cache@v3
|
||||
name: Setup pnpm cache
|
||||
id: pnpm-cache
|
||||
with:
|
||||
path: ${{ steps.pnpm-config.outputs.STORE_PATH }}
|
||||
key: ${{ runner.os }}-pnpm-store-cache-${{ steps.cache-rotation.outputs.YEAR_MONTH }}-${{ steps.get-hash.outputs.hash }}
|
||||
restore-keys: |
|
||||
${{ runner.os }}-pnpm-store-cache-${{ steps.cache-rotation.outputs.YEAR_MONTH }}-
|
||||
|
||||
# Prevent store to grow over time (not needed with yarn)
|
||||
# Note: not perfect as it prune too much in monorepos so the idea
|
||||
# is to use cache-rotation as above. In the future this might work better.
|
||||
#- name: Prune pnpm store
|
||||
# shell: bash
|
||||
# run: pnpm prune store
|
||||
|
||||
- name: Install dependencies
|
||||
if: ${{ inputs.run_install == 'true' }}
|
||||
if: ${{ steps.pnpm-cache.outputs.cache-hit != 'true' && inputs.run_install == 'true' }}
|
||||
shell: bash
|
||||
working-directory: ${{ inputs.cwd }}
|
||||
run: pnpm install --frozen-lockfile --prefer-offline
|
||||
run: ${{ inputs.install_cmd }}
|
||||
env:
|
||||
HUSKY: '0'
|
||||
|
||||
- run: |
|
||||
echo ""
|
||||
echo "Setup pnpm finish."
|
||||
# Other environment variables
|
||||
HUSKY: '0' # By default do not run HUSKY install
|
||||
|
Loading…
x
Reference in New Issue
Block a user