From 38ce16269a56d2ad9ef6b1a7f46b7c865aac83e6 Mon Sep 17 00:00:00 2001 From: seepine Date: Sun, 21 Apr 2024 13:20:33 +0800 Subject: [PATCH] fix: skip install if cache hit --- README.md | 8 ++++++-- action.yml | 50 +++++++++++++++++++++++++++++++++++++------------- 2 files changed, 43 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index 1246e29..7e39555 100644 --- a/README.md +++ b/README.md @@ -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 | 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 | . | diff --git a/action.yml b/action.yml index c99ad21..7305202 100644 --- a/action.yml +++ b/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 " + 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