Skip to content
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

use NODE_AUTH_TOKEN as environment variable name for the NPM_TOKEN secret #266

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changeset/brave-buckets-double.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@changesets/action": major
---

use `NODE_AUTH_TOKEN` as the environment variable name for the `NPM_TOKEN` secret

This matches the official GitHub `setup-node` action (documentation)[https://docs.github.com/en/actions/publishing-packages/publishing-nodejs-packages#publishing-packages-to-the-npm-registry].
7 changes: 7 additions & 0 deletions .changeset/light-yaks-search.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@changesets/action": patch
---

write environment variable references to files instead of the values

Within the `.npmrc` and `.netrc` files, write references to `NODE_AUTH_TOKEN` and `GITHUB_TOKEN` rather than the actual values.
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,31 +95,31 @@ jobs:
publish: yarn release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

- name: Send a Slack notification if a publish happens
if: steps.changesets.outputs.published == 'true'
# You can do something when a publish happens.
run: my-slack-bot send-notification --message "A new version of ${GITHUB_REPOSITORY} was published!"
```

By default the GitHub Action creates a `.npmrc` file with the following content:
If you include the `registry-url` option with the (`setup-node` Github Action)[https://github.com/actions/setup-node], the action creates a `.npmrc` file (with the following content)[https://docs.github.com/en/actions/publishing-packages/publishing-nodejs-packages#publishing-packages-to-the-npm-registry]:

```
//registry.npmjs.org/:_authToken=${process.env.NPM_TOKEN}
//registry.npmjs.org/:_authToken=NODE_AUTH_TOKEN
```

However, if a `.npmrc` file is found, the GitHub Action does not recreate the file. This is useful if you need to configure the `.npmrc` file on your own.
If a `.npmrc` file is found, the GitHub Action does not recreate the file. This is useful if you need to configure the `.npmrc` file on your own.
For example, you can add a step before running the Changesets GitHub Action:

```yml
- name: Creating .npmrc
run: |
cat << EOF > "$HOME/.npmrc"
//registry.npmjs.org/:_authToken=$NPM_TOKEN
//registry.npmjs.org/:_authToken=\$NODE_AUTH_TOKEN
EOF
env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
```

#### Custom Publishing
Expand Down
6 changes: 3 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const getOptionalInput = (name: string) => core.getInput(name) || undefined;
console.log("setting GitHub credentials");
await fs.writeFile(
`${process.env.HOME}/.netrc`,
`machine github.com\nlogin github-actions[bot]\npassword ${githubToken}`
`machine github.com\nlogin github-actions[bot]\npassword \$GITHUB_TOKEN`
);

let { changesets } = await readChangesetState();
Expand Down Expand Up @@ -73,14 +73,14 @@ const getOptionalInput = (name: string) => core.getInput(name) || undefined;
);
fs.appendFileSync(
userNpmrcPath,
`\n//registry.npmjs.org/:_authToken=${process.env.NPM_TOKEN}\n`
`\n//registry.npmjs.org/:_authToken=\$\{NODE_AUTH_TOKEN\}\n`
);
}
} else {
console.log("No user .npmrc file found, creating one");
fs.writeFileSync(
userNpmrcPath,
`//registry.npmjs.org/:_authToken=${process.env.NPM_TOKEN}\n`
`//registry.npmjs.org/:_authToken=\$\{NODE_AUTH_TOKEN\}\n`
);
}

Expand Down