mirror of
https://github.com/pnpm/action-setup.git
synced 2026-07-08 17:43:45 +08:00
Compare commits
10 Commits
0bc9da32cd
...
v5
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
fc06bc1257 | ||
|
|
b906affcce | ||
|
|
9b5745cdf0 | ||
|
|
1e1c8eafbd | ||
|
|
b9e1dbc72f | ||
|
|
61bc82c7df | ||
|
|
e94b270858 | ||
|
|
ee7b8711bd | ||
|
|
3a0024f066 | ||
|
|
72f04517b7 |
12
.github/workflows/test.yaml
vendored
12
.github/workflows/test.yaml
vendored
@@ -22,7 +22,7 @@ jobs:
|
||||
- windows-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1
|
||||
|
||||
- name: Run the action
|
||||
uses: ./
|
||||
@@ -51,7 +51,7 @@ jobs:
|
||||
- windows-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1
|
||||
|
||||
- name: Run the action
|
||||
uses: ./
|
||||
@@ -74,8 +74,8 @@ jobs:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
os:
|
||||
# macos is excluded from this test because node 12 is no longer available on this platform
|
||||
- ubuntu-latest
|
||||
- macos-latest
|
||||
- windows-latest
|
||||
|
||||
standalone:
|
||||
@@ -83,7 +83,7 @@ jobs:
|
||||
- false
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1
|
||||
|
||||
- name: Run the action
|
||||
uses: ./
|
||||
@@ -92,7 +92,7 @@ jobs:
|
||||
standalone: ${{ matrix.standalone }}
|
||||
|
||||
- name: install Node.js
|
||||
uses: actions/setup-node@v4
|
||||
uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0
|
||||
with:
|
||||
# pnpm@7.0.0 is not compatible with Node.js 12
|
||||
node-version: 12.22.12
|
||||
@@ -160,7 +160,7 @@ jobs:
|
||||
- yarn
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1
|
||||
|
||||
- name: Run the action
|
||||
uses: ./
|
||||
|
||||
@@ -125,7 +125,7 @@ jobs:
|
||||
- uses: pnpm/action-setup@v4
|
||||
with:
|
||||
version: 10
|
||||
run_install:
|
||||
run_install: |
|
||||
- recursive: true
|
||||
args: [--strict-peer-dependencies]
|
||||
- args: [--global, gulp, prettier, typescript]
|
||||
|
||||
@@ -24,7 +24,7 @@ inputs:
|
||||
required: false
|
||||
default: 'pnpm-lock.yaml'
|
||||
package_json_file:
|
||||
description: File path to the package.json to read "packageManager" configuration
|
||||
description: File path to the package.json to read "packageManager" configuration. This path must be relative to the repository root (GITHUB_WORKSPACE).
|
||||
required: false
|
||||
default: 'package.json'
|
||||
standalone:
|
||||
@@ -37,6 +37,6 @@ outputs:
|
||||
bin_dest:
|
||||
description: Location of `pnpm` and `pnpx` command
|
||||
runs:
|
||||
using: node20
|
||||
using: node24
|
||||
main: dist/index.js
|
||||
post: dist/index.js
|
||||
|
||||
4
dist/index.js
vendored
4
dist/index.js
vendored
File diff suppressed because one or more lines are too long
@@ -12,8 +12,7 @@
|
||||
"@actions/exec": "^1.1.1",
|
||||
"@actions/glob": "^0.5.0",
|
||||
"@types/expand-tilde": "^2.0.2",
|
||||
"@types/node": "^20.11.5",
|
||||
"@types/node-fetch": "^2.6.11",
|
||||
"@types/node": "^22.0.0",
|
||||
"expand-tilde": "^2.0.2",
|
||||
"yaml": "^2.3.4",
|
||||
"zod": "^3.22.4"
|
||||
|
||||
39
pnpm-lock.yaml
generated
39
pnpm-lock.yaml
generated
@@ -24,11 +24,8 @@ importers:
|
||||
specifier: ^2.0.2
|
||||
version: 2.0.2
|
||||
'@types/node':
|
||||
specifier: ^20.11.5
|
||||
version: 20.17.17
|
||||
'@types/node-fetch':
|
||||
specifier: ^2.6.11
|
||||
version: 2.6.12
|
||||
specifier: ^22.0.0
|
||||
version: 22.19.11
|
||||
expand-tilde:
|
||||
specifier: ^2.0.2
|
||||
version: 2.0.2
|
||||
@@ -140,11 +137,8 @@ packages:
|
||||
'@types/expand-tilde@2.0.2':
|
||||
resolution: {integrity: sha512-wlsMYiapmIR4Eq/Z0qysN8xaDMjSkO6AIDNFx9oxgWGeKVA1jU+NzwPRZErBNP5z6/dx6QNkNpKglBGPO9OkTA==}
|
||||
|
||||
'@types/node-fetch@2.6.12':
|
||||
resolution: {integrity: sha512-8nneRWKCg3rMtF69nLQJnOYUcbafYeFSjqkw3jCRLsqkWFlHaoQrr5mXmofFGOx3DKn7UfmBMyov8ySvLRVldA==}
|
||||
|
||||
'@types/node@20.17.17':
|
||||
resolution: {integrity: sha512-/WndGO4kIfMicEQLTi/mDANUu/iVUhT7KboZPdEqqHQ4aTS+3qT3U5gIqWDFV+XouorjfgGqvKILJeHhuQgFYg==}
|
||||
'@types/node@22.19.11':
|
||||
resolution: {integrity: sha512-BH7YwL6rA93ReqeQS1c4bsPpcfOmJasG+Fkr6Y59q83f9M1WcBRHR2vM+P9eOisYRcN3ujQoiZY8uk5W+1WL8w==}
|
||||
|
||||
'@typespec/ts-http-runtime@0.3.0':
|
||||
resolution: {integrity: sha512-sOx1PKSuFwnIl7z4RN0Ls7N9AQawmR9r66eI5rFCzLDIs8HTIYrIpH9QjYWoX0lkgGrkLxXhi4QnK7MizPRrIg==}
|
||||
@@ -235,10 +229,6 @@ packages:
|
||||
resolution: {integrity: sha512-jqdObeR2rxZZbPSGL+3VckHMYtu+f9//KXBsVny6JSX/pa38Fy+bGjuG8eW/H6USNQWhLi8Num++cU2yOCNz4A==}
|
||||
engines: {node: '>= 0.12'}
|
||||
|
||||
form-data@4.0.1:
|
||||
resolution: {integrity: sha512-tzN8e4TX8+kkxGPK8D5u0FNmjPUjw3lwC9lSLxxoB/+GtsJG91CO8bSWy73APlgAZzZbXEYZJuxjkHH2w+Ezhw==}
|
||||
engines: {node: '>= 6'}
|
||||
|
||||
function-bind@1.1.2:
|
||||
resolution: {integrity: sha512-7XHNxH7qX9xG5mIwxkhumTox/MIRNcOgDrxWsMt2pAr23WHp6MrRlN7FBSFpCpr+oVO0F744iUgR82nJMfG2SA==}
|
||||
|
||||
@@ -345,8 +335,8 @@ packages:
|
||||
engines: {node: '>=14.17'}
|
||||
hasBin: true
|
||||
|
||||
undici-types@6.19.8:
|
||||
resolution: {integrity: sha512-ve2KP6f/JnbPBFyobGHuerC9g1FYGn/F8n1LWTwNxCEzd6IfqTwUQcNXgEtmmQ6DlRrC1hrSrBnCZPokRrDHjw==}
|
||||
undici-types@6.21.0:
|
||||
resolution: {integrity: sha512-iwDZqg0QAGrg9Rav5H4n0M64c3mkR59cJ6wQp+7C4nI0gsmExaedaYLNO44eT4AtBBwjbTiGPMlt2Md0T9H9JQ==}
|
||||
|
||||
undici@5.29.0:
|
||||
resolution: {integrity: sha512-raqeBD6NQK4SkWhQzeYKd1KmIG6dllBOTt55Rmkt4HtI9mwdWtJljnrXjAFUBLTSN67HWrOIZ3EPF4kjUw80Bg==}
|
||||
@@ -549,14 +539,9 @@ snapshots:
|
||||
|
||||
'@types/expand-tilde@2.0.2': {}
|
||||
|
||||
'@types/node-fetch@2.6.12':
|
||||
'@types/node@22.19.11':
|
||||
dependencies:
|
||||
'@types/node': 20.17.17
|
||||
form-data: 4.0.1
|
||||
|
||||
'@types/node@20.17.17':
|
||||
dependencies:
|
||||
undici-types: 6.19.8
|
||||
undici-types: 6.21.0
|
||||
|
||||
'@typespec/ts-http-runtime@0.3.0':
|
||||
dependencies:
|
||||
@@ -642,12 +627,6 @@ snapshots:
|
||||
mime-types: 2.1.35
|
||||
safe-buffer: 5.2.1
|
||||
|
||||
form-data@4.0.1:
|
||||
dependencies:
|
||||
asynckit: 0.4.0
|
||||
combined-stream: 1.0.8
|
||||
mime-types: 2.1.35
|
||||
|
||||
function-bind@1.1.2: {}
|
||||
|
||||
get-intrinsic@1.3.0:
|
||||
@@ -738,7 +717,7 @@ snapshots:
|
||||
|
||||
typescript@5.7.3: {}
|
||||
|
||||
undici-types@6.19.8: {}
|
||||
undici-types@6.21.0: {}
|
||||
|
||||
undici@5.29.0:
|
||||
dependencies:
|
||||
|
||||
@@ -1,19 +1,19 @@
|
||||
import * as cache from '@actions/cache';
|
||||
import * as core from '@actions/core';
|
||||
import { runRestoreCache } from './run';
|
||||
import { Inputs } from '../inputs';
|
||||
import { isFeatureAvailable } from '@actions/cache'
|
||||
import { endGroup, startGroup, warning } from '@actions/core'
|
||||
import { Inputs } from '../inputs'
|
||||
import { runRestoreCache } from './run'
|
||||
|
||||
export async function restoreCache(inputs: Inputs) {
|
||||
if (!inputs.cache) return
|
||||
|
||||
if (!cache.isFeatureAvailable()) {
|
||||
core.warning('Cache is not available, skipping cache restoration')
|
||||
if (!isFeatureAvailable()) {
|
||||
warning('Cache is not available, skipping cache restoration')
|
||||
return
|
||||
}
|
||||
|
||||
core.startGroup('Restoring cache...')
|
||||
await runRestoreCache(inputs);
|
||||
core.endGroup();
|
||||
startGroup('Restoring cache...')
|
||||
await runRestoreCache(inputs)
|
||||
endGroup()
|
||||
}
|
||||
|
||||
export default restoreCache
|
||||
|
||||
@@ -1,39 +1,39 @@
|
||||
import * as cache from '@actions/cache';
|
||||
import * as core from '@actions/core';
|
||||
import * as exec from '@actions/exec';
|
||||
import * as glob from '@actions/glob';
|
||||
import os from 'os';
|
||||
import { Inputs } from '../inputs';
|
||||
import { restoreCache } from '@actions/cache'
|
||||
import { debug, info, saveState, setOutput } from '@actions/core'
|
||||
import { getExecOutput } from '@actions/exec'
|
||||
import { hashFiles } from '@actions/glob'
|
||||
import os from 'os'
|
||||
import { Inputs } from '../inputs'
|
||||
|
||||
export async function runRestoreCache(inputs: Inputs) {
|
||||
const cachePath = await getCacheDirectory();
|
||||
core.saveState('cache_path', cachePath);
|
||||
const cachePath = await getCacheDirectory()
|
||||
saveState('cache_path', cachePath)
|
||||
|
||||
const fileHash = await glob.hashFiles(inputs.cacheDependencyPath);
|
||||
const fileHash = await hashFiles(inputs.cacheDependencyPath)
|
||||
if (!fileHash) {
|
||||
throw new Error('Some specified paths were not resolved, unable to cache dependencies.');
|
||||
throw new Error('Some specified paths were not resolved, unable to cache dependencies.')
|
||||
}
|
||||
|
||||
const primaryKey = `pnpm-cache-${process.env.RUNNER_OS}-${os.arch()}-${fileHash}`;
|
||||
core.debug(`Primary key is ${primaryKey}`);
|
||||
core.saveState('cache_primary_key', primaryKey);
|
||||
const primaryKey = `pnpm-cache-${process.env.RUNNER_OS}-${os.arch()}-${fileHash}`
|
||||
debug(`Primary key is ${primaryKey}`)
|
||||
saveState('cache_primary_key', primaryKey)
|
||||
|
||||
let cacheKey = await cache.restoreCache([cachePath], primaryKey);
|
||||
let cacheKey = await restoreCache([cachePath], primaryKey)
|
||||
|
||||
core.setOutput('cache-hit', Boolean(cacheKey));
|
||||
setOutput('cache-hit', Boolean(cacheKey))
|
||||
|
||||
if (!cacheKey) {
|
||||
core.info(`Cache is not found`);
|
||||
return;
|
||||
info(`Cache is not found`)
|
||||
return
|
||||
}
|
||||
|
||||
core.saveState('cache_restored_key', cacheKey)
|
||||
core.info(`Cache restored from key: ${cacheKey}`)
|
||||
saveState('cache_restored_key', cacheKey)
|
||||
info(`Cache restored from key: ${cacheKey}`)
|
||||
}
|
||||
|
||||
async function getCacheDirectory() {
|
||||
const { stdout } = await exec.getExecOutput('pnpm store path --silent')
|
||||
const { stdout } = await getExecOutput('pnpm store path --silent')
|
||||
const cacheFolderPath = stdout.trim()
|
||||
core.debug(`Cache folder is set to "${cacheFolderPath}"`)
|
||||
return cacheFolderPath;
|
||||
};
|
||||
debug(`Cache folder is set to "${cacheFolderPath}"`)
|
||||
return cacheFolderPath
|
||||
}
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
import * as core from '@actions/core';
|
||||
import { Inputs } from '../inputs';
|
||||
import { runSaveCache } from './run';
|
||||
import { setFailed } from '@actions/core'
|
||||
import { Inputs } from '../inputs'
|
||||
import { runSaveCache } from './run'
|
||||
|
||||
export async function saveCache(inputs: Inputs) {
|
||||
if (!inputs.cache) return
|
||||
|
||||
try {
|
||||
await runSaveCache();
|
||||
await runSaveCache()
|
||||
} catch (error) {
|
||||
core.setFailed((error as Error).message);
|
||||
setFailed((error as Error).message)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,18 +1,18 @@
|
||||
import * as core from '@actions/core';
|
||||
import * as cache from '@actions/cache';
|
||||
import { saveCache } from '@actions/cache'
|
||||
import { getState, info } from '@actions/core'
|
||||
|
||||
export async function runSaveCache() {
|
||||
const state = core.getState('cache_restored_key');
|
||||
const primaryKey = core.getState('cache_primary_key');
|
||||
const cachePath = core.getState('cache_path');
|
||||
const state = getState('cache_restored_key')
|
||||
const primaryKey = getState('cache_primary_key')
|
||||
const cachePath = getState('cache_path')
|
||||
|
||||
if (primaryKey === state) {
|
||||
core.info(`Cache hit occurred on the primary key ${primaryKey}, not saving cache.`);
|
||||
return;
|
||||
info(`Cache hit occurred on the primary key ${primaryKey}, not saving cache.`)
|
||||
return
|
||||
}
|
||||
|
||||
const cacheId = await cache.saveCache([cachePath], primaryKey);
|
||||
if (cacheId == -1) return;
|
||||
const cacheId = await saveCache([cachePath], primaryKey)
|
||||
if (cacheId == -1) return
|
||||
|
||||
core.info(`Cache saved with the key: ${primaryKey}`);
|
||||
info(`Cache saved with the key: ${primaryKey}`)
|
||||
}
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import { setFailed, saveState, getState } from '@actions/core'
|
||||
import restoreCache from './cache-restore'
|
||||
import saveCache from './cache-save'
|
||||
import getInputs, { Inputs } from './inputs'
|
||||
import installPnpm from './install-pnpm'
|
||||
import setOutputs from './outputs'
|
||||
import pnpmInstall from './pnpm-install'
|
||||
import pruneStore from './pnpm-store-prune'
|
||||
import restoreCache from './cache-restore'
|
||||
import saveCache from './cache-save'
|
||||
|
||||
async function main() {
|
||||
const inputs = getInputs()
|
||||
@@ -24,7 +24,7 @@ async function runMain(inputs: Inputs) {
|
||||
console.log('Installation Completed!')
|
||||
setOutputs(inputs)
|
||||
|
||||
await restoreCache(inputs);
|
||||
await restoreCache(inputs)
|
||||
|
||||
pnpmInstall(inputs)
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { getInput, error } from '@actions/core'
|
||||
import * as yaml from 'yaml'
|
||||
import { parse as parseYaml } from 'yaml'
|
||||
import { z, ZodError } from 'zod'
|
||||
|
||||
const RunInstallSchema = z.object({
|
||||
@@ -20,7 +20,7 @@ export type RunInstall = z.infer<typeof RunInstallSchema>
|
||||
|
||||
export function parseRunInstall(inputName: string): RunInstall[] {
|
||||
const input = getInput(inputName, { required: true })
|
||||
const parsedInput: unknown = yaml.parse(input)
|
||||
const parsedInput: unknown = parseYaml(input)
|
||||
|
||||
try {
|
||||
const result: RunInstallInput = RunInstallInputSchema.parse(parsedInput)
|
||||
|
||||
@@ -6,7 +6,7 @@ import path from 'path'
|
||||
import { execPath } from 'process'
|
||||
import util from 'util'
|
||||
import { Inputs } from '../inputs'
|
||||
import YAML from 'yaml'
|
||||
import { parse as parseYaml } from 'yaml'
|
||||
|
||||
export async function runSelfInstaller(inputs: Inputs): Promise<number> {
|
||||
const { version, dest, packageJsonFile, standalone } = inputs
|
||||
@@ -63,7 +63,7 @@ async function readTarget(opts: {
|
||||
try {
|
||||
const content = readFileSync(path.join(GITHUB_WORKSPACE, packageJsonFile), 'utf8');
|
||||
({ packageManager } = packageJsonFile.endsWith(".yaml")
|
||||
? YAML.parse(content, { merge: true })
|
||||
? parseYaml(content, { merge: true })
|
||||
: JSON.parse(content)
|
||||
)
|
||||
} catch (error: unknown) {
|
||||
|
||||
Reference in New Issue
Block a user