-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added option to enable corepack #901
base: main
Are you sure you want to change the base?
Changes from 6 commits
2936fe8
7c0fdd0
f9532b2
28c91a3
d8a8b93
802542b
c871b9d
c73bf90
0c618ce
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -157,7 +157,7 @@ jobs: | |
|
||
## Nightly versions | ||
|
||
You can specify a nightly version to download it from https://nodejs.org/download/nightly. | ||
You can specify a nightly version to download it from https://nodejs.org/download/nightly. | ||
|
||
### Install the nightly build for a major version | ||
|
||
|
@@ -265,7 +265,7 @@ steps: | |
- run: pnpm test | ||
``` | ||
|
||
> **Note**: By default `--frozen-lockfile` option is passed starting from pnpm `6.10.x`. It will be automatically added if you run it on [CI](https://pnpm.io/cli/install#--frozen-lockfile). | ||
> **Note**: By default `--frozen-lockfile` option is passed starting from pnpm `6.10.x`. It will be automatically added if you run it on [CI](https://pnpm.io/cli/install#--frozen-lockfile). | ||
> If the `pnpm-lock.yaml` file changes then pass `--frozen-lockfile` option. | ||
|
||
|
||
|
@@ -416,3 +416,30 @@ Please refer to the [Ensuring workflow access to your package - Configuring a pa | |
|
||
### always-auth input | ||
The always-auth input sets `always-auth=true` in .npmrc file. With this option set [npm](https://docs.npmjs.com/cli/v6/using-npm/config#always-auth)/yarn sends the authentication credentials when making a request to the registries. | ||
|
||
## Enabling Corepack | ||
You can enable [Corepack](https://github.com/nodejs/corepack) by using the `corepack` input. You can then use `pnpm` and `yarn` commands in your project. | ||
|
||
```yaml | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: actions/setup-node@v4 | ||
with: | ||
node-version: '18.x' | ||
corepack: true | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the input There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
- name: Install dependencies | ||
run: yarn install --immutable | ||
``` | ||
|
||
You can also pass package manager names separated by a space to enable corepack for specific package managers only. | ||
|
||
```yaml | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: actions/setup-node@v4 | ||
with: | ||
node-version: '18.x' | ||
corepack: yarn pnpm | ||
- name: Install dependencies | ||
run: yarn install --immutable | ||
``` |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,11 @@ import * as path from 'path'; | |
import {restoreCache} from './cache-restore'; | ||
import {isCacheFeatureAvailable} from './cache-utils'; | ||
import {getNodejsDistribution} from './distributions/installer-factory'; | ||
import {parseNodeVersionFile, printEnvDetailsAndSetOutput} from './util'; | ||
import { | ||
parseNodeVersionFile, | ||
printEnvDetailsAndSetOutput, | ||
enableCorepack | ||
} from './util'; | ||
import {State} from './constants'; | ||
|
||
export async function run() { | ||
|
@@ -60,6 +64,9 @@ export async function run() { | |
auth.configAuthentication(registryUrl, alwaysAuth); | ||
} | ||
|
||
const corepack = core.getInput('corepack') || 'false'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. given that the yaml is structured and supports array, why not specifying the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For simplicity, i would prefer to keep it using a string as the input. But probably we can also make it support array, however currently there's no built-in function to do that. |
||
await enableCorepack(corepack); | ||
|
||
if (cache && isCacheFeatureAvailable()) { | ||
core.saveState(State.CachePackageManager, cache); | ||
const cacheDependencyPath = core.getInput('cache-dependency-path'); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -88,3 +88,16 @@ export const unique = () => { | |
return true; | ||
}; | ||
}; | ||
|
||
export async function enableCorepack(input: string): Promise<void> { | ||
const corepackArgs = ['enable']; | ||
if (input.length > 0 && input !== 'false') { | ||
if (input !== 'true') { | ||
const packageManagers = input.split(' '); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe also trim the input and split by |
||
corepackArgs.push(...packageManagers); | ||
} | ||
await exec.getExecOutput('corepack', corepackArgs, { | ||
ignoreReturnCode: true | ||
}); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.