22 Commits

Author SHA1 Message Date
537643d491 Merge pull request #56 from i7eo/master
chore: bump node version
2022-10-11 11:58:06 +07:00
f4129fb46e fix
Update node version, see https://github.blog/changelog/2022-09-22-github-actions-all-actions-will-begin-running-on-node16-instead-of-node12/
2022-10-11 10:56:24 +08:00
6e1964dde3 Fix spacing issue in README.md example (#48) 2022-06-17 23:17:05 +03:00
10693b3829 Update action.yml 2022-05-28 17:23:43 +03:00
99ecd24520 v2.2.2 2022-05-28 17:22:28 +03:00
958500fcab fix: do not download pnpm from get.pnpm.io (#46)
* fix: do not download pnpm from get.pnpm.io

* fix: remove redundant files
2022-05-28 16:54:43 +03:00
57b9359b4c Merge pull request #41 from nelson6e65/patch-1
docs(readme): improve Cache example
2022-05-07 10:00:37 +07:00
ec1a8b444c Change runs-on back to ubuntu-latest 2022-05-07 09:59:56 +07:00
73e15250cb docs(readme): improve and fix cache example
Dynamically detect the Store directory and use the latest GitHub actions.
2022-05-06 21:57:00 -05:00
10b4b0b462 Merge pull request #36 from pnpm/dependabot/github_actions/actions/checkout-3
Bump actions/checkout from 2 to 3
2022-03-08 10:33:01 +07:00
5fa8980bf4 Update dependabot.yml 2022-03-08 10:32:48 +07:00
ae78e9abbe Bump actions/checkout from 2 to 3
Bumps [actions/checkout](https://github.com/actions/checkout) from 2 to 3.
- [Release notes](https://github.com/actions/checkout/releases)
- [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md)
- [Commits](https://github.com/actions/checkout/compare/v2...v3)

---
updated-dependencies:
- dependency-name: actions/checkout
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
2022-03-07 23:02:26 +00:00
35ab4267a1 fix: packageManager reader (#35)
* fix: packageManager reader

* chore: resolve review

* chore: run build
2022-02-25 12:43:26 +08:00
11ba3424e0 fmt 2022-02-23 10:07:15 +07:00
847a737d63 Merge pull request #33 from pnpm/packageManager
feat: try support packageManager
2022-02-22 16:39:23 +07:00
225f3bb4b0 build 2022-02-22 11:34:20 +02:00
777a50d72e Update src/install-pnpm/run.ts 2022-02-22 11:32:59 +02:00
e7c10c6fc5 Update dist/index.js 2022-02-22 13:04:41 +07:00
a576a70bc6 chore: resolve review 2022-02-22 13:37:35 +08:00
1d51e20937 feat: try support packageManager 2022-02-22 12:26:05 +08:00
ad2b35ae0c Merge pull request #32 from pnpm/retry-fetch
fix: retry fetch of pnpm script
2022-02-21 10:28:16 +07:00
d8ea532ac4 fix: retry fetch of pnpm script
close #22
2022-02-20 21:49:26 +02:00
17 changed files with 268184 additions and 110 deletions

View File

@ -5,6 +5,3 @@ updates:
schedule:
interval: weekly
open-pull-requests-limit: 10
labels:
- dependabot
- github-actions

View File

@ -22,7 +22,7 @@ jobs:
- windows-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Run the action
uses: ./
@ -51,7 +51,7 @@ jobs:
- windows-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Run the action
uses: ./
@ -107,7 +107,7 @@ jobs:
- pnpm
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Run the action
uses: ./

1
.gitignore vendored
View File

@ -2,6 +2,7 @@ node_modules
*.log
/dist/*
!/dist/index.js
!/dist/pnpm.js
tmp
temp
*.tmp

View File

@ -6,7 +6,11 @@ Install pnpm package manager.
### `version`
**Required** Version of pnpm to install. It supports npm versioning scheme, it could be an exact version (such as `6.24.1`), or a version range (such as `6`, `6.x.x`, `6.24.x`, `^6.24.1`, `*`, etc.), or `latest`.
Version of pnpm to install.
**Optional** when there is a [`packageManager` field in the `package.json`](https://nodejs.org/api/corepack.html).
otherwise, this field is **required** It supports npm versioning scheme, it could be an exact version (such as `6.24.1`), or a version range (such as `6`, `6.x.x`, `6.24.x`, `^6.24.1`, `*`, etc.), or `latest`.
### `dest`
@ -58,7 +62,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: pnpm/action-setup@v2.1.0
- uses: pnpm/action-setup@v2.2.2
with:
version: 6.0.2
```
@ -77,7 +81,7 @@ jobs:
steps:
- uses: actions/checkout@v2
- uses: pnpm/action-setup@v2.1.0
- uses: pnpm/action-setup@v2.2.2
with:
version: 6.0.2
run_install: |
@ -98,21 +102,36 @@ jobs:
runs-on: ubuntu-latest
steps:
build:
- uses: actions/checkout@v2
- name: Checkout
uses: actions/checkout@v3
- name: Cache pnpm modules
uses: actions/cache@v2
with:
path: ~/.pnpm-store
key: ${{ runner.os }}-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-
- name: Install Node.js
uses: actions/setup-node@v3
with:
node-version: 16
- uses: pnpm/action-setup@v2.1.0
with:
version: 6.0.2
run_install: true
- uses: pnpm/action-setup@v2.0.1
name: Install pnpm
id: pnpm-install
with:
version: 7
run_install: false
- name: Get pnpm store directory
id: pnpm-cache
run: |
echo "::set-output name=pnpm_cache_dir::$(pnpm store path)"
- uses: actions/cache@v3
name: Setup pnpm cache
with:
path: ${{ steps.pnpm-cache.outputs.pnpm_cache_dir }}
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-pnpm-store-
- name: Install dependencies
run: pnpm install
```
**Note:** You don't need to run `pnpm store prune` at the end; post-action has already taken care of that.

View File

@ -1,14 +1,13 @@
name: Setup PNPM
description: Install PNPM package manager
name: Setup pnpm
description: Install pnpm package manager
branding:
icon: package
color: orange
inputs:
version:
description: Version of PNPM to install
required: true
description: Version of pnpm to install
dest:
description: Where to store PNPM files
description: Where to store pnpm files
required: false
default: ~/setup-pnpm
run_install:
@ -16,6 +15,6 @@ inputs:
required: false
default: 'null'
runs:
using: node12
using: node16
main: dist/index.js
post: dist/index.js

11
dist/index.js vendored

File diff suppressed because one or more lines are too long

134031
dist/pnpm.js vendored Normal file

File diff suppressed because one or more lines are too long

View File

@ -3,7 +3,7 @@
"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": "pnpm run build:schemas && 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"
},
"dependencies": {
@ -12,16 +12,15 @@
"@types/fs-extra": "^9.0.13",
"@types/js-yaml": "^4.0.5",
"@types/node": "^14.18.10",
"@types/node-fetch": "^2.5.12",
"@types/node-fetch": "^2.6.1",
"ajv": "^6.12.6",
"expand-tilde": "^2.0.2",
"fs-extra": "^9.1.0",
"js-yaml": "^4.1.0",
"node-fetch": "^2.6.7"
"fs-extra": "^10.0.0",
"js-yaml": "^4.1.0"
},
"devDependencies": {
"@ts-schema-autogen/cli": "^0.1.2",
"@vercel/ncc": "^0.27.0",
"@vercel/ncc": "^0.33.3",
"typescript": "^4.5.5"
}
}

75
pnpm-lock.yaml generated
View File

@ -1,4 +1,4 @@
lockfileVersion: 5.3
lockfileVersion: 5.4
specifiers:
'@actions/core': ^1.6.0
@ -7,13 +7,12 @@ specifiers:
'@types/fs-extra': ^9.0.13
'@types/js-yaml': ^4.0.5
'@types/node': ^14.18.10
'@types/node-fetch': ^2.5.12
'@vercel/ncc': ^0.27.0
'@types/node-fetch': ^2.6.1
'@vercel/ncc': ^0.33.3
ajv: ^6.12.6
expand-tilde: ^2.0.2
fs-extra: ^9.1.0
fs-extra: ^10.0.0
js-yaml: ^4.1.0
node-fetch: ^2.6.7
typescript: ^4.5.5
dependencies:
@ -22,16 +21,15 @@ dependencies:
'@types/fs-extra': 9.0.13
'@types/js-yaml': 4.0.5
'@types/node': 14.18.10
'@types/node-fetch': 2.5.12
'@types/node-fetch': 2.6.1
ajv: 6.12.6
expand-tilde: 2.0.2
fs-extra: 9.1.0
fs-extra: 10.0.0
js-yaml: 4.1.0
node-fetch: 2.6.7
devDependencies:
'@ts-schema-autogen/cli': 0.1.2
'@vercel/ncc': 0.27.0
'@vercel/ncc': 0.33.3
typescript: 4.5.5
packages:
@ -216,8 +214,8 @@ packages:
resolution: {integrity: sha512-qcUXuemtEu+E5wZSJHNxUXeCZhAfXKQ41D+duX+VYPde7xyEVZci+/oXKJL13tnRs9lR2pr4fod59GT6/X1/yQ==}
dev: true
/@types/node-fetch/2.5.12:
resolution: {integrity: sha512-MKgC4dlq4kKNa/mYrwpKfzQMB5X3ee5U6fSprkKpToBqBmX4nFZL9cW5jl6sWn+xpRJ7ypWh2yyqqr8UUCstSw==}
/@types/node-fetch/2.6.1:
resolution: {integrity: sha512-oMqjURCaxoSIsHSr1E47QHzbmzNR5rK8McHuNb11BOM9cHcIK3Avy0s/b2JlXHoQGTYS3NsvWzV1M0iK7l0wbA==}
dependencies:
'@types/node': 14.18.10
form-data: 3.0.1
@ -240,8 +238,8 @@ packages:
'@types/yargs-parser': 20.2.1
dev: true
/@vercel/ncc/0.27.0:
resolution: {integrity: sha512-DllIJQapnU2YwewIhh/4dYesmMQw3h2cFtabECc/zSJHqUbNa0eJuEkRa6DXbZvh1YPWBtYQoPV17NlDpBw1Vw==}
/@vercel/ncc/0.33.3:
resolution: {integrity: sha512-JGZ11QV+/ZcfudW2Cz2JVp54/pJNXbsuWRgSh2ZmmZdQBKXqBtIGrwI1Wyx8nlbzAiEFe7FHi4K1zX4//jxTnQ==}
hasBin: true
dev: true
@ -291,11 +289,6 @@ packages:
resolution: {integrity: sha1-x57Zf380y48robyXkLzDZkdLS3k=}
dev: false
/at-least-node/1.0.0:
resolution: {integrity: sha512-+q/t7Ekv1EDY2l6Gda6LLiX14rU9TV20Wa3ofeQmwPFZbOMo9DXrLbOjFaaclkXKWidIaopwAObQDqwWtGUjqg==}
engines: {node: '>= 4.0.0'}
dev: false
/balanced-match/1.0.2:
resolution: {integrity: sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==}
dev: true
@ -442,6 +435,15 @@ packages:
mime-types: 2.1.34
dev: false
/fs-extra/10.0.0:
resolution: {integrity: sha512-C5owb14u9eJwizKGdchcDUQeFtlSHHthBk8pbX9Vc1PFZrLombudjDnNns88aYslCyF6IY5SUw3Roz6xShcEIQ==}
engines: {node: '>=12'}
dependencies:
graceful-fs: 4.2.9
jsonfile: 6.1.0
universalify: 2.0.0
dev: false
/fs-extra/8.1.0:
resolution: {integrity: sha512-yhlQgA6mnOJUKOsRUFsgJdQCvkKhcz8tlZG5HBQfReYZy46OwLcY+Zia0mtdHsOo9y/hP+CxMN0TU9QxoOtG4g==}
engines: {node: '>=6 <7 || >=8'}
@ -451,16 +453,6 @@ packages:
universalify: 0.1.2
dev: true
/fs-extra/9.1.0:
resolution: {integrity: sha512-hcg3ZmepS30/7BSFqRvoo3DOMQu7IjqxO5nCDt+zM9XWjb33Wg7ziNT+Qvqbuc3+gWpzO02JubVyk2G4Zvo1OQ==}
engines: {node: '>=10'}
dependencies:
at-least-node: 1.0.0
graceful-fs: 4.2.9
jsonfile: 6.1.0
universalify: 2.0.0
dev: false
/fs.realpath/1.0.0:
resolution: {integrity: sha1-FQStJSMVjKpA20onh8sBQRmU6k8=}
dev: true
@ -587,18 +579,6 @@ packages:
brace-expansion: 1.1.11
dev: true
/node-fetch/2.6.7:
resolution: {integrity: sha512-ZjMPFEfVx5j+y2yF35Kzx5sF7kDzxuDj6ziH4FFbOp87zKDZNx8yExJIb05OGF4Nlt9IHFIMBkRl41VdvcNdbQ==}
engines: {node: 4.x || >=6.0.0}
peerDependencies:
encoding: ^0.1.0
peerDependenciesMeta:
encoding:
optional: true
dependencies:
whatwg-url: 5.0.0
dev: false
/once/1.4.0:
resolution: {integrity: sha1-WDsap3WWHUsROsF9nFC6753Xa9E=}
dependencies:
@ -704,10 +684,6 @@ packages:
ansi-regex: 5.0.1
dev: true
/tr46/0.0.3:
resolution: {integrity: sha1-gYT9NH2snNwYWZLzpmIuFLnZq2o=}
dev: false
/tslib/1.14.1:
resolution: {integrity: sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg==}
dev: true
@ -764,17 +740,6 @@ packages:
engines: {node: '>= 4'}
dev: true
/webidl-conversions/3.0.1:
resolution: {integrity: sha1-JFNCdeKnvGvnvIZhHMFq4KVlSHE=}
dev: false
/whatwg-url/5.0.0:
resolution: {integrity: sha1-lmRU6HZUYuN2RNNib2dCzotwll0=}
dependencies:
tr46: 0.0.3
webidl-conversions: 3.0.1
dev: false
/which-module/2.0.0:
resolution: {integrity: sha1-2e8H3Od7mQK4o6j6SzHD4/fm6Ho=}
dev: true

View File

@ -1,7 +1,7 @@
import { setFailed, saveState, getState } from '@actions/core'
import getInputs from './inputs'
import setOutputs from './outputs'
import installPnpm from './install-pnpm'
import setOutputs from './outputs'
import pnpmInstall from './pnpm-install'
import pruneStore from './pnpm-store-prune'

View File

@ -3,7 +3,7 @@ import expandTilde from 'expand-tilde'
import { RunInstall, parseRunInstall } from './run-install'
export interface Inputs {
readonly version: string
readonly version?: string
readonly dest: string
readonly runInstall: RunInstall[]
}
@ -15,7 +15,7 @@ const options: InputOptions = {
const parseInputPath = (name: string) => expandTilde(getInput(name, options))
export const getInputs = (): Inputs => ({
version: getInput('version', options),
version: getInput('version'),
dest: parseInputPath('dest'),
runInstall: parseRunInstall('run_install'),
})

View File

@ -1,7 +1,7 @@
import process from 'process'
import { load } from 'js-yaml'
import Ajv from 'ajv'
import { getInput, error, InputOptions } from '@actions/core'
import Ajv from 'ajv'
import { load } from 'js-yaml'
import process from 'process'
import runInstallSchema from './run-install-input.schema.json'
export interface RunInstall {

134031
src/install-pnpm/pnpm.js Normal file

File diff suppressed because one or more lines are too long

View File

@ -1,28 +1,26 @@
import { addPath, exportVariable } from '@actions/core'
import { spawn } from 'child_process'
import { execPath } from 'process'
import { remove, ensureFile, writeFile, readFile } from 'fs-extra'
import path from 'path'
import { remove, ensureFile, writeFile } from 'fs-extra'
import fetch from 'node-fetch'
import { execPath } from 'process'
import { Inputs } from '../inputs'
export async function runSelfInstaller(inputs: Inputs): Promise<number> {
const { version, dest } = inputs
const target = version ? `pnpm@${version}` : 'pnpm'
const pkgJson = path.join(dest, 'package.json')
// prepare self install
await remove(dest)
const pkgJson = path.join(dest, 'package.json')
await ensureFile(pkgJson)
await writeFile(pkgJson, JSON.stringify({ private: true }))
const cp = spawn(execPath, ['-', 'install', target, '--no-lockfile'], {
// prepare target pnpm
const target = await readTarget(version)
const cp = spawn(execPath, [path.join(__dirname, 'pnpm.js'), 'install', target, '--no-lockfile'], {
cwd: dest,
stdio: ['pipe', 'inherit', 'inherit'],
})
const response = await fetch('https://pnpm.io/pnpm.js')
response.body.pipe(cp.stdin)
const exitCode = await new Promise<number>((resolve, reject) => {
cp.on('error', reject)
cp.on('close', resolve)
@ -35,4 +33,29 @@ export async function runSelfInstaller(inputs: Inputs): Promise<number> {
return exitCode
}
async function readTarget(version?: string | undefined) {
if (version) return `pnpm@${version}`
const { GITHUB_WORKSPACE } = process.env
if (!GITHUB_WORKSPACE) {
throw new Error(`No workspace is found.
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.
Otherwise, please specify the pnpm version in the action configuration.`)
}
const { packageManager } = JSON.parse(await readFile(path.join(GITHUB_WORKSPACE, 'package.json'), 'utf8'))
if (typeof packageManager !== 'string') {
throw new Error(`No pnpm version is specified.
Please specify it by one of the following ways:
- in the GitHub Action config with the key "version"
- in the package.json with the key "packageManager" (See https://nodejs.org/api/corepack.html)`)
}
if (!packageManager.startsWith('pnpm@')) {
throw new Error('Invalid packageManager field in package.json')
}
return packageManager
}
export default runSelfInstaller

View File

@ -1,5 +1,5 @@
import { spawnSync } from 'child_process'
import { setFailed, startGroup, endGroup } from '@actions/core'
import { spawnSync } from 'child_process'
import { Inputs } from '../inputs'
import { patchPnpmEnv } from '../utils'

View File

@ -1,5 +1,5 @@
import { spawnSync } from 'child_process'
import { warning, startGroup, endGroup } from '@actions/core'
import { spawnSync } from 'child_process'
import { Inputs } from '../inputs'
import { patchPnpmEnv } from '../utils'
@ -13,7 +13,7 @@ export function pruneStore(inputs: Inputs) {
const { error, status } = spawnSync('pnpm', ['store', 'prune'], {
stdio: 'inherit',
shell: true,
env: patchPnpmEnv(inputs)
env: patchPnpmEnv(inputs),
})
endGroup()

View File

@ -1,10 +1,10 @@
import process from 'process'
import path from 'path'
import process from 'process'
import { Inputs } from '../inputs'
export const getBinDest = (inputs: Inputs): string => path.join(inputs.dest, 'node_modules', '.bin')
export const patchPnpmEnv = (inputs: Inputs): NodeJS.ProcessEnv => ({
...process.env,
PATH: getBinDest(inputs) + path.delimiter + process.env.PATH
PATH: getBinDest(inputs) + path.delimiter + process.env.PATH,
})