1
0
Fork 0
mirror of synced 2026-06-05 15:38:19 +00:00

Compare commits

...

2 commits

Author SHA1 Message Date
gowridurgad
0355742c94
Remove dummy NODE_AUTH_TOKEN export (#1558)
Co-authored-by: gowridurgad <gowridurgad@gmail.com>
2026-05-27 21:56:31 -05:00
priya-kinthali
ad1b57eb81
docs: Update restore-only cache documentation (#1550)
* update restore-only cache example in advanced-usage.md

* fix copilot suggestion

* update naming
2026-05-26 17:51:36 -05:00
4 changed files with 69 additions and 32 deletions

View file

@ -118,6 +118,27 @@ describe('authutil tests', () => {
expect(process.env.NODE_AUTH_TOKEN).toEqual('foobar');
});
it('should not export NODE_AUTH_TOKEN if not set in environment', async () => {
const exportSpy = jest.spyOn(core, 'exportVariable');
delete process.env.NODE_AUTH_TOKEN;
await auth.configAuthentication('https://registry.npmjs.org/');
expect(fs.statSync(rcFile)).toBeDefined();
const rc = readRcFile(rcFile);
expect(rc['registry']).toBe('https://registry.npmjs.org/');
expect(exportSpy).not.toHaveBeenCalledWith(
'NODE_AUTH_TOKEN',
expect.anything()
);
});
it('should export NODE_AUTH_TOKEN if set to empty string', async () => {
const exportSpy = jest.spyOn(core, 'exportVariable');
process.env.NODE_AUTH_TOKEN = '';
await auth.configAuthentication('https://registry.npmjs.org/');
expect(fs.statSync(rcFile)).toBeDefined();
expect(exportSpy).toHaveBeenCalledWith('NODE_AUTH_TOKEN', '');
});
it('configAuthentication should overwrite non-scoped with non-scoped', async () => {
fs.writeFileSync(rcFile, 'registry=NNN');
await auth.configAuthentication('https://registry.npmjs.org/');

6
dist/setup/index.js vendored
View file

@ -78875,8 +78875,10 @@ function writeRegistryToFile(registryUrl, fileLocation) {
newContents += `${authString}${os.EOL}${registryString}`;
fs.writeFileSync(fileLocation, newContents);
core.exportVariable('NPM_CONFIG_USERCONFIG', fileLocation);
// Export empty node_auth_token if didn't exist so npm doesn't complain about not being able to find it
core.exportVariable('NODE_AUTH_TOKEN', process.env.NODE_AUTH_TOKEN || 'XXXXX-XXXXX-XXXXX-XXXXX');
// Only export NODE_AUTH_TOKEN if explicitly provided by user
if (Object.prototype.hasOwnProperty.call(process.env, 'NODE_AUTH_TOKEN')) {
core.exportVariable('NODE_AUTH_TOKEN', process.env.NODE_AUTH_TOKEN);
}
}

View file

@ -329,36 +329,51 @@ steps:
- run: npm test
```
**Restore-Only Cache**
**Restore-only cache**
You can restore caches without saving new entries, which helps reduce cache writes and storage usage in read-only cache workflows.
```yaml
## In some workflows, you may want to restore a cache without saving it. This can help reduce cache writes and storage usage in workflows that only need to read from cache
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
# Restore Node.js modules cache (restore-only)
- name: Restore Node modules cache
uses: actions/cache@v5
id: cache-node-modules
with:
path: ~/.npm
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
# Setup Node.js
- name: Setup Node.js
uses: actions/setup-node@v6
with:
node-version: '24'
# Install dependencies
- run: npm install
steps:
- uses: actions/checkout@v6
# - uses: pnpm/action-setup@v6
# with:
# version: 10
- name: Setup Node.js
uses: actions/setup-node@v6
with:
node-version: '24'
- name: Normalize runner architecture
shell: bash
run: echo "ARCH=$(echo '${{ runner.arch }}' | tr '[:upper:]' '[:lower:]')" >> $GITHUB_ENV
- name: Output of cache path
id: cachepath
shell: bash
run: echo "path=$(npm config get cache)" >> $GITHUB_OUTPUT
# run: echo "path=$(pnpm store path --silent)" >> $GITHUB_OUTPUT
# For yarn workflow, output of yarn cache dir (v1) or yarn config get cacheFolder (v2+)
# run: echo "path=$(yarn cache dir)" >> $GITHUB_OUTPUT
- name: Restore Node cache
uses: actions/cache/restore@v5
with:
path: ${{ steps.cachepath.outputs.path }}
key: node-cache-${{ runner.os }}-${{ env.ARCH }}-npm-${{ hashFiles('**/package-lock.json') }}
# key: node-cache-${{ runner.os }}-${{ env.ARCH }}-yarn-${{ hashFiles('**/yarn.lock') }}
# key: node-cache-${{ runner.os }}-${{ env.ARCH }}-pnpm-${{ hashFiles('**/pnpm-lock.yaml') }}
- run: npm ci
# - run: yarn install --frozen-lockfile # optional, --immutable
# - run: pnpm install
```
> **Note**: Uncomment the commands relevant to your project's package manager.
> For more details related to cache scenarios, please refer [Node npm](https://github.com/actions/cache/blob/main/examples.md#node---npm).
> For more details related to cache scenarios, please refer [actions/cache/restore](https://github.com/actions/cache/tree/main/restore#only-restore-cache).
## Multiple Operating Systems and Architectures
## Multiple operating systems and architectures
```yaml
jobs:

View file

@ -46,9 +46,8 @@ function writeRegistryToFile(registryUrl: string, fileLocation: string) {
newContents += `${authString}${os.EOL}${registryString}`;
fs.writeFileSync(fileLocation, newContents);
core.exportVariable('NPM_CONFIG_USERCONFIG', fileLocation);
// Export empty node_auth_token if didn't exist so npm doesn't complain about not being able to find it
core.exportVariable(
'NODE_AUTH_TOKEN',
process.env.NODE_AUTH_TOKEN || 'XXXXX-XXXXX-XXXXX-XXXXX'
);
// Only export NODE_AUTH_TOKEN if explicitly provided by user
if (Object.prototype.hasOwnProperty.call(process.env, 'NODE_AUTH_TOKEN')) {
core.exportVariable('NODE_AUTH_TOKEN', process.env.NODE_AUTH_TOKEN);
}
}