-
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 all 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 |
---|---|---|
|
@@ -159,7 +159,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 | ||
|
||
|
@@ -267,7 +267,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. | ||
|
||
|
||
|
@@ -418,3 +418,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 |
---|---|---|
|
@@ -7,7 +7,11 @@ import * as path from 'path'; | |
import {restoreCache} from './cache-restore'; | ||
import {isCacheFeatureAvailable} from './cache-utils'; | ||
import {getNodejsDistribution} from './distributions/installer-factory'; | ||
import {getNodeVersionFromFile, printEnvDetailsAndSetOutput} from './util'; | ||
import { | ||
getNodeVersionFromFile, | ||
printEnvDetailsAndSetOutput, | ||
enableCorepack | ||
} from './util'; | ||
import {State} from './constants'; | ||
|
||
export async function run() { | ||
|
@@ -59,6 +63,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 |
---|---|---|
|
@@ -3,6 +3,7 @@ import * as exec from '@actions/exec'; | |
|
||
import fs from 'fs'; | ||
import path from 'path'; | ||
import {getCommandOutput} from './cache-utils'; | ||
|
||
export function getNodeVersionFromFile(versionFilePath: string): string | null { | ||
if (!fs.existsSync(versionFilePath)) { | ||
|
@@ -105,3 +106,14 @@ export const unique = () => { | |
return true; | ||
}; | ||
}; | ||
|
||
export async function enableCorepack(input: string): Promise<void> { | ||
if (input.length && input !== 'false') { | ||
const corepackArgs = ['enable']; | ||
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 getCommandOutput(`corepack ${corepackArgs.join(' ')}`); | ||
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. Looking back at previous PRs, it was suggested that if Yarn ends up being enabled, any existing Yarn installation (which is evidently present on GitHub runners) should be uninstalled first: #482 (review). Is this is a concern? 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. thought corepack would interop with existing yarn installations (could be wrong) 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. Yes, the existing Yarn installation can be left as is and it won't cause conflict with the installed Yarn from Corepack. |
||
} | ||
} |
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.