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
|
## Usage
|
||||||
|
|
||||||
|
It will setup pnpm and run `pnpm install`.
|
||||||
|
|
||||||
```yml
|
```yml
|
||||||
- name: Setup pnpm and Install
|
- name: Setup pnpm and Install
|
||||||
uses: seepine/actions-setup-pnpm@v1
|
uses: seepine/actions-setup-pnpm@v1
|
||||||
@ -11,8 +13,10 @@
|
|||||||
|
|
||||||
## Input
|
## Input
|
||||||
|
|
||||||
|
|
||||||
| Output Item | Description | Required | Default |
|
| 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 | . |
|
| 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'
|
description: 'Setup pnpm and run pnpm install with cache enabled'
|
||||||
|
|
||||||
inputs:
|
inputs:
|
||||||
run_install:
|
run_install:
|
||||||
description: If specified, run `pnpm install`
|
description: "If specified, run pnpm install."
|
||||||
required: false
|
required: false
|
||||||
default: 'true'
|
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:
|
cwd:
|
||||||
description: "Changes node's process.cwd() if the project is not located on the root. Default to process.cwd()"
|
description: "Changes node's process.cwd() if the project is not located on the root. Default to process.cwd()"
|
||||||
required: false
|
required: false
|
||||||
@ -14,16 +26,20 @@ inputs:
|
|||||||
runs:
|
runs:
|
||||||
using: 'composite'
|
using: 'composite'
|
||||||
steps:
|
steps:
|
||||||
# If you want to set pnpm version, setting the packageManager field in package.json like "packageManager":"pnpm@8.10.2"
|
|
||||||
- name: ⚙️ Enable Corepack
|
- name: ⚙️ Enable Corepack
|
||||||
|
if: ${{ inputs.enable-corepack == 'true' }}
|
||||||
shell: bash
|
shell: bash
|
||||||
working-directory: ${{ inputs.cwd }}
|
working-directory: ${{ inputs.cwd }}
|
||||||
run: |
|
run: |
|
||||||
corepack enable
|
corepack enable
|
||||||
corepack enable npm
|
|
||||||
echo "corepack enabled"
|
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"
|
- name: Expose pnpm config(s) through "$GITHUB_OUTPUT"
|
||||||
id: pnpm-config
|
id: pnpm-config
|
||||||
@ -41,25 +57,33 @@ runs:
|
|||||||
name: Get hash of lock files
|
name: Get hash of lock files
|
||||||
id: get-hash
|
id: get-hash
|
||||||
with:
|
with:
|
||||||
|
# Prevent installing new dependencies without using pnpm
|
||||||
patterns: |
|
patterns: |
|
||||||
|
**/package-lock.json
|
||||||
**/pnpm-lock.yaml
|
**/pnpm-lock.yaml
|
||||||
|
**/yarn.lock
|
||||||
|
|
||||||
- uses: actions/cache@v3
|
- uses: actions/cache@v3
|
||||||
name: Setup pnpm cache
|
name: Setup pnpm cache
|
||||||
|
id: pnpm-cache
|
||||||
with:
|
with:
|
||||||
path: ${{ steps.pnpm-config.outputs.STORE_PATH }}
|
path: ${{ steps.pnpm-config.outputs.STORE_PATH }}
|
||||||
key: ${{ runner.os }}-pnpm-store-cache-${{ steps.cache-rotation.outputs.YEAR_MONTH }}-${{ steps.get-hash.outputs.hash }}
|
key: ${{ runner.os }}-pnpm-store-cache-${{ steps.cache-rotation.outputs.YEAR_MONTH }}-${{ steps.get-hash.outputs.hash }}
|
||||||
restore-keys: |
|
restore-keys: |
|
||||||
${{ runner.os }}-pnpm-store-cache-${{ steps.cache-rotation.outputs.YEAR_MONTH }}-
|
${{ 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
|
- name: Install dependencies
|
||||||
if: ${{ inputs.run_install == 'true' }}
|
if: ${{ steps.pnpm-cache.outputs.cache-hit != 'true' && inputs.run_install == 'true' }}
|
||||||
shell: bash
|
shell: bash
|
||||||
working-directory: ${{ inputs.cwd }}
|
working-directory: ${{ inputs.cwd }}
|
||||||
run: pnpm install --frozen-lockfile --prefer-offline
|
run: ${{ inputs.install_cmd }}
|
||||||
env:
|
env:
|
||||||
HUSKY: '0'
|
# Other environment variables
|
||||||
|
HUSKY: '0' # By default do not run HUSKY install
|
||||||
- run: |
|
|
||||||
echo ""
|
|
||||||
echo "Setup pnpm finish."
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user