mirror of
https://github.com/pnpm/action-setup.git
synced 2025-12-09 14:03:31 +08:00
Compare commits
1 Commits
fix-ci-mac
...
v2
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
eae0cfeb28 |
28
.github/workflows/test.yaml
vendored
28
.github/workflows/test.yaml
vendored
@@ -15,19 +15,19 @@ jobs:
|
|||||||
fail-fast: false
|
fail-fast: false
|
||||||
matrix:
|
matrix:
|
||||||
pnpm:
|
pnpm:
|
||||||
- 9.15.5
|
- 4.11.1
|
||||||
os:
|
os:
|
||||||
- ubuntu-latest
|
- ubuntu-latest
|
||||||
- macos-latest
|
- macos-latest
|
||||||
- windows-latest
|
- windows-latest
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v3
|
||||||
|
|
||||||
- name: Run the action
|
- name: Run the action
|
||||||
uses: ./
|
uses: ./
|
||||||
with:
|
with:
|
||||||
version: 9.15.5
|
version: 4.11.1
|
||||||
|
|
||||||
- name: 'Test: which'
|
- name: 'Test: which'
|
||||||
run: which pnpm; which pnpx
|
run: which pnpm; which pnpx
|
||||||
@@ -44,19 +44,19 @@ jobs:
|
|||||||
fail-fast: false
|
fail-fast: false
|
||||||
matrix:
|
matrix:
|
||||||
pnpm:
|
pnpm:
|
||||||
- 9.15.5
|
- 4.11.1
|
||||||
os:
|
os:
|
||||||
- ubuntu-latest
|
- ubuntu-latest
|
||||||
- macos-latest
|
- macos-latest
|
||||||
- windows-latest
|
- windows-latest
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v3
|
||||||
|
|
||||||
- name: Run the action
|
- name: Run the action
|
||||||
uses: ./
|
uses: ./
|
||||||
with:
|
with:
|
||||||
version: 9.15.5
|
version: 4.11.1
|
||||||
dest: ~/test/pnpm
|
dest: ~/test/pnpm
|
||||||
|
|
||||||
- name: 'Test: which'
|
- name: 'Test: which'
|
||||||
@@ -74,8 +74,8 @@ jobs:
|
|||||||
fail-fast: false
|
fail-fast: false
|
||||||
matrix:
|
matrix:
|
||||||
os:
|
os:
|
||||||
# macos is excluded from this test because node 12 is no longer available on this platform
|
|
||||||
- ubuntu-latest
|
- ubuntu-latest
|
||||||
|
- macos-latest
|
||||||
- windows-latest
|
- windows-latest
|
||||||
|
|
||||||
standalone:
|
standalone:
|
||||||
@@ -83,16 +83,16 @@ jobs:
|
|||||||
- false
|
- false
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v3
|
||||||
|
|
||||||
- name: Run the action
|
- name: Run the action
|
||||||
uses: ./
|
uses: ./
|
||||||
with:
|
with:
|
||||||
version: 9.15.0
|
version: 7.0.0
|
||||||
standalone: ${{ matrix.standalone }}
|
standalone: ${{ matrix.standalone }}
|
||||||
|
|
||||||
- name: install Node.js
|
- name: install Node.js
|
||||||
uses: actions/setup-node@v4
|
uses: actions/setup-node@v3
|
||||||
with:
|
with:
|
||||||
# pnpm@7.0.0 is not compatible with Node.js 12
|
# pnpm@7.0.0 is not compatible with Node.js 12
|
||||||
node-version: 12.22.12
|
node-version: 12.22.12
|
||||||
@@ -129,7 +129,7 @@ jobs:
|
|||||||
fail-fast: false
|
fail-fast: false
|
||||||
matrix:
|
matrix:
|
||||||
pnpm:
|
pnpm:
|
||||||
- 9.15.5
|
- 4.11.1
|
||||||
os:
|
os:
|
||||||
- ubuntu-latest
|
- ubuntu-latest
|
||||||
- macos-latest
|
- macos-latest
|
||||||
@@ -149,6 +149,7 @@ jobs:
|
|||||||
- --global-dir=./pnpm-global
|
- --global-dir=./pnpm-global
|
||||||
- npm
|
- npm
|
||||||
- yarn
|
- yarn
|
||||||
|
- pnpm
|
||||||
- name: 'array'
|
- name: 'array'
|
||||||
value: |
|
value: |
|
||||||
- {}
|
- {}
|
||||||
@@ -158,14 +159,15 @@ jobs:
|
|||||||
- --global-dir=./pnpm-global
|
- --global-dir=./pnpm-global
|
||||||
- npm
|
- npm
|
||||||
- yarn
|
- yarn
|
||||||
|
- pnpm
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v3
|
||||||
|
|
||||||
- name: Run the action
|
- name: Run the action
|
||||||
uses: ./
|
uses: ./
|
||||||
with:
|
with:
|
||||||
version: 9.15.5
|
version: 4.11.1
|
||||||
run_install: ${{ matrix.run_install.value }}
|
run_install: ${{ matrix.run_install.value }}
|
||||||
|
|
||||||
- name: 'Test: which'
|
- name: 'Test: which'
|
||||||
|
|||||||
3
.gitignore
vendored
3
.gitignore
vendored
@@ -2,8 +2,7 @@ node_modules
|
|||||||
*.log
|
*.log
|
||||||
/dist/*
|
/dist/*
|
||||||
!/dist/index.js
|
!/dist/index.js
|
||||||
!/dist/pnpm.cjs
|
!/dist/pnpm.js
|
||||||
!/dist/worker.js
|
|
||||||
tmp
|
tmp
|
||||||
temp
|
temp
|
||||||
*.tmp
|
*.tmp
|
||||||
|
|||||||
77
README.md
77
README.md
@@ -1,7 +1,3 @@
|
|||||||
> ## :warning: Upgrade from v2!
|
|
||||||
>
|
|
||||||
> The v2 version of this action [has stopped working](https://github.com/pnpm/action-setup/issues/135) with newer Node.js versions. Please, upgrade to the latest version to fix any issues.
|
|
||||||
|
|
||||||
# Setup pnpm
|
# Setup pnpm
|
||||||
|
|
||||||
Install pnpm package manager.
|
Install pnpm package manager.
|
||||||
@@ -40,19 +36,11 @@ If `run_install` is a YAML string representation of either an object or an array
|
|||||||
|
|
||||||
#### `run_install.args`
|
#### `run_install.args`
|
||||||
|
|
||||||
**Optional** (_type:_ `string[]`) Additional arguments after `pnpm [recursive] install`, e.g. `[--ignore-scripts, --strict-peer-dependencies]`.
|
**Optional** (_type:_ `string[]`) Additional arguments after `pnpm [recursive] install`, e.g. `[--frozen-lockfile, --strict-peer-dependencies]`.
|
||||||
|
|
||||||
### `cache`
|
|
||||||
|
|
||||||
**Optional** (_type:_ `boolean`, _default:_ `false`) Whether to cache the pnpm store directory.
|
|
||||||
|
|
||||||
### `cache_dependency_path`
|
|
||||||
|
|
||||||
**Optional** (_type:_ `string|string[]`, _default:_ `pnpm-lock.yaml`) File path to the pnpm lockfile, which contents hash will be used as a cache key.
|
|
||||||
|
|
||||||
### `package_json_file`
|
### `package_json_file`
|
||||||
|
|
||||||
**Optional** (_type:_ `string`, _default:_ `package.json`) File path to the `package.json`/[`package.yaml`](https://github.com/pnpm/pnpm/pull/1799) to read "packageManager" configuration.
|
**Optional** (_type:_ `string`, _default:_ `package.json`) File path to the `package.json` to read "packageManager" configuration.
|
||||||
|
|
||||||
### `standalone`
|
### `standalone`
|
||||||
|
|
||||||
@@ -72,9 +60,7 @@ Location of `pnpm` and `pnpx` command.
|
|||||||
|
|
||||||
## Usage example
|
## Usage example
|
||||||
|
|
||||||
### Install only pnpm without `packageManager`
|
### Just install pnpm
|
||||||
|
|
||||||
This works when the repo either doesn't have a `package.json` or has a `package.json` but it doesn't specify `packageManager`.
|
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
on:
|
on:
|
||||||
@@ -86,26 +72,9 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: pnpm/action-setup@v4
|
- uses: pnpm/action-setup@v2
|
||||||
with:
|
with:
|
||||||
version: 10
|
version: 8
|
||||||
```
|
|
||||||
|
|
||||||
### Install only pnpm with `packageManager`
|
|
||||||
|
|
||||||
Omit `version` input to use the version in the [`packageManager` field in the `package.json`](https://nodejs.org/api/corepack.html).
|
|
||||||
|
|
||||||
```yaml
|
|
||||||
on:
|
|
||||||
- push
|
|
||||||
- pull_request
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
install:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- uses: pnpm/action-setup@v4
|
|
||||||
```
|
```
|
||||||
|
|
||||||
### Install pnpm and a few npm packages
|
### Install pnpm and a few npm packages
|
||||||
@@ -120,14 +89,14 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v3
|
||||||
|
|
||||||
- uses: pnpm/action-setup@v4
|
- uses: pnpm/action-setup@v2
|
||||||
with:
|
with:
|
||||||
version: 10
|
version: 8
|
||||||
run_install: |
|
run_install: |
|
||||||
- recursive: true
|
- recursive: true
|
||||||
args: [--strict-peer-dependencies]
|
args: [--frozen-lockfile, --strict-peer-dependencies]
|
||||||
- args: [--global, gulp, prettier, typescript]
|
- args: [--global, gulp, prettier, typescript]
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -144,13 +113,31 @@ jobs:
|
|||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v3
|
||||||
|
|
||||||
- uses: pnpm/action-setup@v4
|
- name: Install Node.js
|
||||||
|
uses: actions/setup-node@v3
|
||||||
|
with:
|
||||||
|
node-version: 16
|
||||||
|
|
||||||
|
- uses: pnpm/action-setup@v2
|
||||||
name: Install pnpm
|
name: Install pnpm
|
||||||
with:
|
with:
|
||||||
version: 10
|
version: 7
|
||||||
cache: true
|
run_install: false
|
||||||
|
|
||||||
|
- name: Get pnpm store directory
|
||||||
|
shell: bash
|
||||||
|
run: |
|
||||||
|
echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV
|
||||||
|
|
||||||
|
- uses: actions/cache@v3
|
||||||
|
name: Setup pnpm cache
|
||||||
|
with:
|
||||||
|
path: ${{ env.STORE_PATH }}
|
||||||
|
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
|
||||||
|
restore-keys: |
|
||||||
|
${{ runner.os }}-pnpm-store-
|
||||||
|
|
||||||
- name: Install dependencies
|
- name: Install dependencies
|
||||||
run: pnpm install
|
run: pnpm install
|
||||||
@@ -164,4 +151,4 @@ This action does not setup Node.js for you, use [actions/setup-node](https://git
|
|||||||
|
|
||||||
## License
|
## License
|
||||||
|
|
||||||
[MIT](https://github.com/pnpm/action-setup/blob/master/LICENSE.md) © [Hoàng Văn Khải](https://github.com/KSXGitHub/)
|
[MIT](https://git.io/JfclH) © [Hoàng Văn Khải](https://github.com/KSXGitHub/)
|
||||||
|
|||||||
17
action.yml
17
action.yml
@@ -15,28 +15,15 @@ inputs:
|
|||||||
description: If specified, run `pnpm install`
|
description: If specified, run `pnpm install`
|
||||||
required: false
|
required: false
|
||||||
default: 'null'
|
default: 'null'
|
||||||
cache:
|
|
||||||
description: Whether to cache the pnpm store directory
|
|
||||||
required: false
|
|
||||||
default: 'false'
|
|
||||||
cache_dependency_path:
|
|
||||||
description: File path to the pnpm lockfile, which contents hash will be used as a cache key
|
|
||||||
required: false
|
|
||||||
default: 'pnpm-lock.yaml'
|
|
||||||
package_json_file:
|
package_json_file:
|
||||||
description: File path to the package.json to read "packageManager" configuration. This path must be relative to the repository root (GITHUB_WORKSPACE).
|
description: File path to the package.json to read "packageManager" configuration
|
||||||
required: false
|
required: false
|
||||||
default: 'package.json'
|
default: 'package.json'
|
||||||
standalone:
|
standalone:
|
||||||
description: When set to true, @pnpm/exe, which is a Node.js bundled package, will be installed, enabling using pnpm without Node.js.
|
description: When set to true, @pnpm/exe, which is a Node.js bundled package, will be installed, enabling using pnpm without Node.js.
|
||||||
required: false
|
required: false
|
||||||
default: 'false'
|
default: 'false'
|
||||||
outputs:
|
|
||||||
dest:
|
|
||||||
description: Expanded path of inputs#dest
|
|
||||||
bin_dest:
|
|
||||||
description: Location of `pnpm` and `pnpx` command
|
|
||||||
runs:
|
runs:
|
||||||
using: node20
|
using: node16
|
||||||
main: dist/index.js
|
main: dist/index.js
|
||||||
post: dist/index.js
|
post: dist/index.js
|
||||||
|
|||||||
8
dist/index.js
vendored
8
dist/index.js
vendored
File diff suppressed because one or more lines are too long
70874
dist/pnpm.cjs → dist/pnpm.js
vendored
70874
dist/pnpm.cjs → dist/pnpm.js
vendored
File diff suppressed because one or more lines are too long
16625
dist/worker.js
vendored
16625
dist/worker.js
vendored
File diff suppressed because it is too large
Load Diff
29
package.json
29
package.json
@@ -1,25 +1,26 @@
|
|||||||
{
|
{
|
||||||
"private": true,
|
"private": true,
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
"build:schemas": "ts-schema-autogen generate",
|
||||||
"build:ncc": "ncc build --minify --no-source-map-register --no-cache dist/tsc/index.js --out dist/",
|
"build:ncc": "ncc build --minify --no-source-map-register --no-cache dist/tsc/index.js --out dist/",
|
||||||
"build": "tsc && pnpm run build:ncc",
|
"build": "pnpm run build:schemas && tsc && pnpm run build:ncc && cp src/install-pnpm/pnpm.js dist/pnpm.js",
|
||||||
"start": "pnpm run build && sh ./run.sh",
|
"start": "pnpm run build && sh ./run.sh"
|
||||||
"update-pnpm-dist": "pnpm install && cp ./node_modules/pnpm/dist/pnpm.cjs ./dist/pnpm.cjs && cp ./node_modules/pnpm/dist/worker.js ./dist/worker.js"
|
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@actions/cache": "^4.1.0",
|
"@actions/core": "^1.10.0",
|
||||||
"@actions/core": "^1.10.1",
|
"@types/expand-tilde": "^2.0.0",
|
||||||
"@actions/exec": "^1.1.1",
|
"@types/fs-extra": "^9.0.13",
|
||||||
"@actions/glob": "^0.5.0",
|
"@types/js-yaml": "^4.0.5",
|
||||||
"@types/expand-tilde": "^2.0.2",
|
"@types/node": "^14.18.54",
|
||||||
"@types/node": "^20.11.5",
|
"@types/node-fetch": "^2.6.4",
|
||||||
|
"ajv": "^6.12.6",
|
||||||
"expand-tilde": "^2.0.2",
|
"expand-tilde": "^2.0.2",
|
||||||
"yaml": "^2.3.4",
|
"fs-extra": "^10.1.0",
|
||||||
"zod": "^3.22.4"
|
"js-yaml": "^4.1.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@vercel/ncc": "^0.38.1",
|
"@ts-schema-autogen/cli": "^0.1.2",
|
||||||
"pnpm": "^8.14.3",
|
"@vercel/ncc": "^0.33.4",
|
||||||
"typescript": "^5.3.3"
|
"typescript": "^4.9.5"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
1424
pnpm-lock.yaml
generated
1424
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
@@ -1,19 +0,0 @@
|
|||||||
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 (!isFeatureAvailable()) {
|
|
||||||
warning('Cache is not available, skipping cache restoration')
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
startGroup('Restoring cache...')
|
|
||||||
await runRestoreCache(inputs)
|
|
||||||
endGroup()
|
|
||||||
}
|
|
||||||
|
|
||||||
export default restoreCache
|
|
||||||
@@ -1,39 +0,0 @@
|
|||||||
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()
|
|
||||||
saveState('cache_path', cachePath)
|
|
||||||
|
|
||||||
const fileHash = await hashFiles(inputs.cacheDependencyPath)
|
|
||||||
if (!fileHash) {
|
|
||||||
throw new Error('Some specified paths were not resolved, unable to cache dependencies.')
|
|
||||||
}
|
|
||||||
|
|
||||||
const primaryKey = `pnpm-cache-${process.env.RUNNER_OS}-${os.arch()}-${fileHash}`
|
|
||||||
debug(`Primary key is ${primaryKey}`)
|
|
||||||
saveState('cache_primary_key', primaryKey)
|
|
||||||
|
|
||||||
let cacheKey = await restoreCache([cachePath], primaryKey)
|
|
||||||
|
|
||||||
setOutput('cache-hit', Boolean(cacheKey))
|
|
||||||
|
|
||||||
if (!cacheKey) {
|
|
||||||
info(`Cache is not found`)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
saveState('cache_restored_key', cacheKey)
|
|
||||||
info(`Cache restored from key: ${cacheKey}`)
|
|
||||||
}
|
|
||||||
|
|
||||||
async function getCacheDirectory() {
|
|
||||||
const { stdout } = await getExecOutput('pnpm store path --silent')
|
|
||||||
const cacheFolderPath = stdout.trim()
|
|
||||||
debug(`Cache folder is set to "${cacheFolderPath}"`)
|
|
||||||
return cacheFolderPath
|
|
||||||
}
|
|
||||||
@@ -1,15 +0,0 @@
|
|||||||
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()
|
|
||||||
} catch (error) {
|
|
||||||
setFailed((error as Error).message)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export default saveCache
|
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
import { saveCache } from '@actions/cache'
|
|
||||||
import { getState, info } from '@actions/core'
|
|
||||||
|
|
||||||
export async function runSaveCache() {
|
|
||||||
const state = getState('cache_restored_key')
|
|
||||||
const primaryKey = getState('cache_primary_key')
|
|
||||||
const cachePath = getState('cache_path')
|
|
||||||
|
|
||||||
if (primaryKey === state) {
|
|
||||||
info(`Cache hit occurred on the primary key ${primaryKey}, not saving cache.`)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
const cacheId = await saveCache([cachePath], primaryKey)
|
|
||||||
if (cacheId == -1) return
|
|
||||||
|
|
||||||
info(`Cache saved with the key: ${primaryKey}`)
|
|
||||||
}
|
|
||||||
24
src/index.ts
24
src/index.ts
@@ -1,7 +1,5 @@
|
|||||||
import { setFailed, saveState, getState } from '@actions/core'
|
import { setFailed, saveState, getState } from '@actions/core'
|
||||||
import restoreCache from './cache-restore'
|
import getInputs from './inputs'
|
||||||
import saveCache from './cache-save'
|
|
||||||
import getInputs, { Inputs } from './inputs'
|
|
||||||
import installPnpm from './install-pnpm'
|
import installPnpm from './install-pnpm'
|
||||||
import setOutputs from './outputs'
|
import setOutputs from './outputs'
|
||||||
import pnpmInstall from './pnpm-install'
|
import pnpmInstall from './pnpm-install'
|
||||||
@@ -9,31 +7,15 @@ import pruneStore from './pnpm-store-prune'
|
|||||||
|
|
||||||
async function main() {
|
async function main() {
|
||||||
const inputs = getInputs()
|
const inputs = getInputs()
|
||||||
|
const isPost = getState('is_post')
|
||||||
if (getState('is_post') === 'true') {
|
if (isPost === 'true') return pruneStore(inputs)
|
||||||
await runPost(inputs)
|
|
||||||
} else {
|
|
||||||
await runMain(inputs)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async function runMain(inputs: Inputs) {
|
|
||||||
saveState('is_post', 'true')
|
saveState('is_post', 'true')
|
||||||
|
|
||||||
await installPnpm(inputs)
|
await installPnpm(inputs)
|
||||||
console.log('Installation Completed!')
|
console.log('Installation Completed!')
|
||||||
setOutputs(inputs)
|
setOutputs(inputs)
|
||||||
|
|
||||||
await restoreCache(inputs)
|
|
||||||
|
|
||||||
pnpmInstall(inputs)
|
pnpmInstall(inputs)
|
||||||
}
|
}
|
||||||
|
|
||||||
async function runPost(inputs: Inputs) {
|
|
||||||
pruneStore(inputs)
|
|
||||||
await saveCache(inputs)
|
|
||||||
}
|
|
||||||
|
|
||||||
main().catch(error => {
|
main().catch(error => {
|
||||||
console.error(error)
|
console.error(error)
|
||||||
setFailed(error)
|
setFailed(error)
|
||||||
|
|||||||
@@ -5,8 +5,6 @@ import { RunInstall, parseRunInstall } from './run-install'
|
|||||||
export interface Inputs {
|
export interface Inputs {
|
||||||
readonly version?: string
|
readonly version?: string
|
||||||
readonly dest: string
|
readonly dest: string
|
||||||
readonly cache: boolean
|
|
||||||
readonly cacheDependencyPath: string
|
|
||||||
readonly runInstall: RunInstall[]
|
readonly runInstall: RunInstall[]
|
||||||
readonly packageJsonFile: string
|
readonly packageJsonFile: string
|
||||||
readonly standalone: boolean
|
readonly standalone: boolean
|
||||||
@@ -21,8 +19,6 @@ const parseInputPath = (name: string) => expandTilde(getInput(name, options))
|
|||||||
export const getInputs = (): Inputs => ({
|
export const getInputs = (): Inputs => ({
|
||||||
version: getInput('version'),
|
version: getInput('version'),
|
||||||
dest: parseInputPath('dest'),
|
dest: parseInputPath('dest'),
|
||||||
cache: getBooleanInput('cache'),
|
|
||||||
cacheDependencyPath: parseInputPath('cache_dependency_path'),
|
|
||||||
runInstall: parseRunInstall('run_install'),
|
runInstall: parseRunInstall('run_install'),
|
||||||
packageJsonFile: parseInputPath('package_json_file'),
|
packageJsonFile: parseInputPath('package_json_file'),
|
||||||
standalone: getBooleanInput('standalone'),
|
standalone: getBooleanInput('standalone'),
|
||||||
|
|||||||
21
src/inputs/run-install-input.schema.autogen.json
Normal file
21
src/inputs/run-install-input.schema.autogen.json
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
{
|
||||||
|
"$schema": "https://raw.githubusercontent.com/ksxnodeapps/ts-schema-autogen/master/packages/schemas/config.schema.json",
|
||||||
|
"instruction": {
|
||||||
|
"compilerOptions": {
|
||||||
|
"strict": true,
|
||||||
|
"target": "ES2018",
|
||||||
|
"lib": [
|
||||||
|
"ES2018",
|
||||||
|
"ES2019",
|
||||||
|
"ES2020",
|
||||||
|
"ESNext"
|
||||||
|
],
|
||||||
|
"moduleResolution": "Node",
|
||||||
|
"esModuleInterop": true,
|
||||||
|
"resolveJsonModule": true
|
||||||
|
},
|
||||||
|
"input": "run-install.ts",
|
||||||
|
"symbol": "RunInstallInput",
|
||||||
|
"output": "run-install-input.schema.json"
|
||||||
|
}
|
||||||
|
}
|
||||||
39
src/inputs/run-install-input.schema.json
Normal file
39
src/inputs/run-install-input.schema.json
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
{
|
||||||
|
"anyOf": [
|
||||||
|
{
|
||||||
|
"$ref": "#/definitions/RunInstall"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "array",
|
||||||
|
"items": {
|
||||||
|
"$ref": "#/definitions/RunInstall"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": [
|
||||||
|
"null",
|
||||||
|
"boolean"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"definitions": {
|
||||||
|
"RunInstall": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"recursive": {
|
||||||
|
"type": "boolean"
|
||||||
|
},
|
||||||
|
"cwd": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"args": {
|
||||||
|
"type": "array",
|
||||||
|
"items": {
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"$schema": "http://json-schema.org/draft-07/schema#"
|
||||||
|
}
|
||||||
@@ -1,41 +1,39 @@
|
|||||||
import { getInput, error } from '@actions/core'
|
import { getInput, error, InputOptions } from '@actions/core'
|
||||||
import * as yaml from 'yaml'
|
import Ajv from 'ajv'
|
||||||
import { z, ZodError } from 'zod'
|
import { load } from 'js-yaml'
|
||||||
|
import process from 'process'
|
||||||
|
import runInstallSchema from './run-install-input.schema.json'
|
||||||
|
|
||||||
const RunInstallSchema = z.object({
|
export interface RunInstall {
|
||||||
recursive: z.boolean().optional(),
|
readonly recursive?: boolean
|
||||||
cwd: z.string().optional(),
|
readonly cwd?: string
|
||||||
args: z.array(z.string()).optional(),
|
readonly args?: readonly string[]
|
||||||
})
|
}
|
||||||
|
|
||||||
const RunInstallInputSchema = z.union([
|
export type RunInstallInput =
|
||||||
z.null(),
|
| null
|
||||||
z.boolean(),
|
| boolean
|
||||||
RunInstallSchema,
|
| RunInstall
|
||||||
z.array(RunInstallSchema),
|
| RunInstall[]
|
||||||
])
|
|
||||||
|
const options: InputOptions = {
|
||||||
export type RunInstallInput = z.infer<typeof RunInstallInputSchema>
|
required: true,
|
||||||
export type RunInstall = z.infer<typeof RunInstallSchema>
|
}
|
||||||
|
|
||||||
export function parseRunInstall(inputName: string): RunInstall[] {
|
export function parseRunInstall(name: string): RunInstall[] {
|
||||||
const input = getInput(inputName, { required: true })
|
const result: RunInstallInput = load(getInput(name, options)) as any
|
||||||
const parsedInput: unknown = yaml.parse(input)
|
const ajv = new Ajv({
|
||||||
|
allErrors: true,
|
||||||
try {
|
})
|
||||||
const result: RunInstallInput = RunInstallInputSchema.parse(parsedInput)
|
const validate = ajv.compile(runInstallSchema)
|
||||||
if (!result) return []
|
if (!validate(result)) {
|
||||||
if (result === true) return [{ recursive: true }]
|
for (const errorItem of validate.errors!) {
|
||||||
if (Array.isArray(result)) return result
|
error(`with.run_install${errorItem.dataPath}: ${errorItem.message}`)
|
||||||
return [result]
|
}
|
||||||
} catch (exception: unknown) {
|
return process.exit(1)
|
||||||
error(`Error for input "${inputName}" = ${input}`)
|
}
|
||||||
|
if (!result) return []
|
||||||
if (exception instanceof ZodError) {
|
if (result === true) return [{ recursive: true }]
|
||||||
error(`Errors: ${exception.errors}`)
|
if (Array.isArray(result)) return result
|
||||||
} else {
|
return [result]
|
||||||
error(`Exception: ${exception}`)
|
|
||||||
}
|
|
||||||
process.exit(1)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
134031
src/install-pnpm/pnpm.js
Normal file
134031
src/install-pnpm/pnpm.js
Normal file
File diff suppressed because one or more lines are too long
@@ -1,38 +1,22 @@
|
|||||||
import { addPath, exportVariable } from '@actions/core'
|
import { addPath, exportVariable } from '@actions/core'
|
||||||
import { spawn } from 'child_process'
|
import { spawn } from 'child_process'
|
||||||
import { rm, writeFile, mkdir, copyFile } from 'fs/promises'
|
import { remove, ensureFile, writeFile, readFile } from 'fs-extra'
|
||||||
import { readFileSync } from 'fs'
|
|
||||||
import path from 'path'
|
import path from 'path'
|
||||||
import { execPath } from 'process'
|
import { execPath } from 'process'
|
||||||
import util from 'util'
|
|
||||||
import { Inputs } from '../inputs'
|
import { Inputs } from '../inputs'
|
||||||
import YAML from 'yaml'
|
|
||||||
|
|
||||||
export async function runSelfInstaller(inputs: Inputs): Promise<number> {
|
export async function runSelfInstaller(inputs: Inputs): Promise<number> {
|
||||||
const { version, dest, packageJsonFile, standalone } = inputs
|
const { version, dest, packageJsonFile, standalone } = inputs
|
||||||
const { GITHUB_WORKSPACE } = process.env
|
|
||||||
|
|
||||||
// prepare self install
|
// prepare self install
|
||||||
await rm(dest, { recursive: true, force: true })
|
await remove(dest)
|
||||||
// create dest directory after removal
|
|
||||||
await mkdir(dest, { recursive: true })
|
|
||||||
const pkgJson = path.join(dest, 'package.json')
|
const pkgJson = path.join(dest, 'package.json')
|
||||||
// we have ensured the dest directory exists, we can write the file directly
|
await ensureFile(pkgJson)
|
||||||
await writeFile(pkgJson, JSON.stringify({ private: true }))
|
await writeFile(pkgJson, JSON.stringify({ private: true }))
|
||||||
|
|
||||||
// copy .npmrc if it exists to install from custom registry
|
|
||||||
if (GITHUB_WORKSPACE) {
|
|
||||||
try {
|
|
||||||
await copyFile(path.join(GITHUB_WORKSPACE, '.npmrc'), path.join(dest, '.npmrc'))
|
|
||||||
} catch (error) {
|
|
||||||
// Swallow error if .npmrc doesn't exist
|
|
||||||
if (!util.types.isNativeError(error) || !('code' in error) || error.code !== 'ENOENT') throw error
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// prepare target pnpm
|
// prepare target pnpm
|
||||||
const target = await readTarget({ version, packageJsonFile, standalone })
|
const target = await readTarget({ version, packageJsonFile, standalone })
|
||||||
const cp = spawn(execPath, [path.join(__dirname, 'pnpm.cjs'), 'install', target, '--no-lockfile'], {
|
const cp = spawn(execPath, [path.join(__dirname, 'pnpm.js'), 'install', target, '--no-lockfile'], {
|
||||||
cwd: dest,
|
cwd: dest,
|
||||||
stdio: ['pipe', 'inherit', 'inherit'],
|
stdio: ['pipe', 'inherit', 'inherit'],
|
||||||
})
|
})
|
||||||
@@ -55,45 +39,18 @@ async function readTarget(opts: {
|
|||||||
readonly standalone: boolean
|
readonly standalone: boolean
|
||||||
}) {
|
}) {
|
||||||
const { version, packageJsonFile, standalone } = opts
|
const { version, packageJsonFile, standalone } = opts
|
||||||
|
|
||||||
|
if (version) return `${ standalone ? '@pnpm/exe' : 'pnpm' }@${version}`
|
||||||
|
|
||||||
const { GITHUB_WORKSPACE } = process.env
|
const { GITHUB_WORKSPACE } = process.env
|
||||||
|
|
||||||
let packageManager
|
|
||||||
|
|
||||||
if (GITHUB_WORKSPACE) {
|
|
||||||
try {
|
|
||||||
const content = readFileSync(path.join(GITHUB_WORKSPACE, packageJsonFile), 'utf8');
|
|
||||||
({ packageManager } = packageJsonFile.endsWith(".yaml")
|
|
||||||
? YAML.parse(content, { merge: true })
|
|
||||||
: JSON.parse(content)
|
|
||||||
)
|
|
||||||
} catch (error: unknown) {
|
|
||||||
// Swallow error if package.json doesn't exist in root
|
|
||||||
if (!util.types.isNativeError(error) || !('code' in error) || error.code !== 'ENOENT') throw error
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (version) {
|
|
||||||
if (
|
|
||||||
typeof packageManager === 'string' &&
|
|
||||||
packageManager.startsWith('pnpm@') &&
|
|
||||||
packageManager.replace('pnpm@', '') !== version
|
|
||||||
) {
|
|
||||||
throw new Error(`Multiple versions of pnpm specified:
|
|
||||||
- version ${version} in the GitHub Action config with the key "version"
|
|
||||||
- version ${packageManager} in the package.json with the key "packageManager"
|
|
||||||
Remove one of these versions to avoid version mismatch errors like ERR_PNPM_BAD_PM_VERSION`)
|
|
||||||
}
|
|
||||||
|
|
||||||
return `${ standalone ? '@pnpm/exe' : 'pnpm' }@${version}`
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!GITHUB_WORKSPACE) {
|
if (!GITHUB_WORKSPACE) {
|
||||||
throw new Error(`No workspace is found.
|
throw new Error(`No workspace is found.
|
||||||
If you've intended to let pnpm/action-setup read preferred pnpm version from the "packageManager" field in the package.json file,
|
If you're intended to let pnpm/action-setup read preferred pnpm version from the "packageManager" field in the package.json file,
|
||||||
please run the actions/checkout before pnpm/action-setup.
|
please run the actions/checkout before pnpm/action-setup.
|
||||||
Otherwise, please specify the pnpm version in the action configuration.`)
|
Otherwise, please specify the pnpm version in the action configuration.`)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const { packageManager } = JSON.parse(await readFile(path.join(GITHUB_WORKSPACE, packageJsonFile), 'utf8'))
|
||||||
if (typeof packageManager !== 'string') {
|
if (typeof packageManager !== 'string') {
|
||||||
throw new Error(`No pnpm version is specified.
|
throw new Error(`No pnpm version is specified.
|
||||||
Please specify it by one of the following ways:
|
Please specify it by one of the following ways:
|
||||||
@@ -105,7 +62,7 @@ Please specify it by one of the following ways:
|
|||||||
throw new Error('Invalid packageManager field in package.json')
|
throw new Error('Invalid packageManager field in package.json')
|
||||||
}
|
}
|
||||||
|
|
||||||
if (standalone) {
|
if(standalone){
|
||||||
return packageManager.replace('pnpm@', '@pnpm/exe@')
|
return packageManager.replace('pnpm@', '@pnpm/exe@')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,11 +1,15 @@
|
|||||||
|
|
||||||
{
|
{
|
||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
"target": "ES2022",
|
"target": "ES2018",
|
||||||
"module": "Node16",
|
"module": "CommonJS",
|
||||||
|
"moduleResolution": "Node",
|
||||||
"resolveJsonModule": true,
|
"resolveJsonModule": true,
|
||||||
"lib": [
|
"lib": [
|
||||||
"ES2023"
|
"ES2018",
|
||||||
|
"ES2019",
|
||||||
|
"ES2020",
|
||||||
|
"ESNext"
|
||||||
],
|
],
|
||||||
"outDir": "./dist/tsc",
|
"outDir": "./dist/tsc",
|
||||||
"preserveConstEnums": true,
|
"preserveConstEnums": true,
|
||||||
|
|||||||
Reference in New Issue
Block a user