mirror of
https://github.com/changesets/action
synced 2026-10-26 16:39:56 +08:00
Automatically use the GitHub-provided token to allow most users to avoid explicit GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} configuration (#564)
This commit is contained in:
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
"@changesets/action": minor
|
||||||
|
---
|
||||||
|
|
||||||
|
Automatically use the GitHub-provided token to allow most users to avoid explicit `GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}` configuration.
|
||||||
@@ -54,8 +54,6 @@ jobs:
|
|||||||
|
|
||||||
- name: Create Release Pull Request
|
- name: Create Release Pull Request
|
||||||
uses: changesets/action@v1
|
uses: changesets/action@v1
|
||||||
env:
|
|
||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
||||||
```
|
```
|
||||||
|
|
||||||
#### With Publishing
|
#### With Publishing
|
||||||
@@ -95,7 +93,6 @@ jobs:
|
|||||||
# This expects you to have a script called release which does a build for your packages and calls changeset publish
|
# This expects you to have a script called release which does a build for your packages and calls changeset publish
|
||||||
publish: yarn release
|
publish: yarn release
|
||||||
env:
|
env:
|
||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
||||||
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
|
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
|
||||||
|
|
||||||
- name: Send a Slack notification if a publish happens
|
- name: Send a Slack notification if a publish happens
|
||||||
@@ -156,8 +153,6 @@ jobs:
|
|||||||
- name: Create Release Pull Request or Publish to npm
|
- name: Create Release Pull Request or Publish to npm
|
||||||
id: changesets
|
id: changesets
|
||||||
uses: changesets/action@v1
|
uses: changesets/action@v1
|
||||||
env:
|
|
||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
||||||
|
|
||||||
- name: Publish
|
- name: Publish
|
||||||
if: steps.changesets.outputs.hasChangesets == 'false'
|
if: steps.changesets.outputs.hasChangesets == 'false'
|
||||||
@@ -202,8 +197,6 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
# this expects you to have a npm script called version that runs some logic and then calls `changeset version`.
|
# this expects you to have a npm script called version that runs some logic and then calls `changeset version`.
|
||||||
version: yarn version
|
version: yarn version
|
||||||
env:
|
|
||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
||||||
```
|
```
|
||||||
|
|
||||||
#### With Yarn 2 / Plug'n'Play
|
#### With Yarn 2 / Plug'n'Play
|
||||||
|
|||||||
@@ -4,6 +4,10 @@ runs:
|
|||||||
using: "node24"
|
using: "node24"
|
||||||
main: "dist/index.js"
|
main: "dist/index.js"
|
||||||
inputs:
|
inputs:
|
||||||
|
github-token:
|
||||||
|
description: "The GitHub token to use for authentication. Defaults to the GitHub-provided token."
|
||||||
|
required: false
|
||||||
|
default: ${{ github.token }}
|
||||||
publish:
|
publish:
|
||||||
description: "The command to use to build and publish packages"
|
description: "The command to use to build and publish packages"
|
||||||
required: false
|
required: false
|
||||||
|
|||||||
+5
-1
@@ -10,7 +10,9 @@ import { fileExists } from "./utils.ts";
|
|||||||
const getOptionalInput = (name: string) => core.getInput(name) || undefined;
|
const getOptionalInput = (name: string) => core.getInput(name) || undefined;
|
||||||
|
|
||||||
(async () => {
|
(async () => {
|
||||||
let githubToken = process.env.GITHUB_TOKEN;
|
// to maintain compatibility with workflows created before github-token input was introduced
|
||||||
|
// it's important to prefer the explicitly set GITHUB_TOKEN over the default token coming from github.token
|
||||||
|
let githubToken = process.env.GITHUB_TOKEN || core.getInput("github-token");
|
||||||
|
|
||||||
if (!githubToken) {
|
if (!githubToken) {
|
||||||
core.setFailed("Please add the GITHUB_TOKEN to the changesets action");
|
core.setFailed("Please add the GITHUB_TOKEN to the changesets action");
|
||||||
@@ -114,6 +116,7 @@ const getOptionalInput = (name: string) => core.getInput(name) || undefined;
|
|||||||
|
|
||||||
const result = await runPublish({
|
const result = await runPublish({
|
||||||
script: publishScript,
|
script: publishScript,
|
||||||
|
githubToken,
|
||||||
git,
|
git,
|
||||||
octokit,
|
octokit,
|
||||||
createGithubReleases: core.getBooleanInput("createGithubReleases"),
|
createGithubReleases: core.getBooleanInput("createGithubReleases"),
|
||||||
@@ -136,6 +139,7 @@ const getOptionalInput = (name: string) => core.getInput(name) || undefined;
|
|||||||
const octokit = setupOctokit(githubToken);
|
const octokit = setupOctokit(githubToken);
|
||||||
const { pullRequestNumber } = await runVersion({
|
const { pullRequestNumber } = await runVersion({
|
||||||
script: getOptionalInput("version"),
|
script: getOptionalInput("version"),
|
||||||
|
githubToken,
|
||||||
git,
|
git,
|
||||||
octokit,
|
octokit,
|
||||||
prTitle: getOptionalInput("title"),
|
prTitle: getOptionalInput("title"),
|
||||||
|
|||||||
@@ -82,6 +82,7 @@ describe("version", () => {
|
|||||||
|
|
||||||
await runVersion({
|
await runVersion({
|
||||||
octokit: setupOctokit("@@GITHUB_TOKEN"),
|
octokit: setupOctokit("@@GITHUB_TOKEN"),
|
||||||
|
githubToken: "@@GITHUB_TOKEN",
|
||||||
git: new Git({ cwd }),
|
git: new Git({ cwd }),
|
||||||
cwd,
|
cwd,
|
||||||
});
|
});
|
||||||
@@ -116,6 +117,7 @@ describe("version", () => {
|
|||||||
|
|
||||||
await runVersion({
|
await runVersion({
|
||||||
octokit: setupOctokit("@@GITHUB_TOKEN"),
|
octokit: setupOctokit("@@GITHUB_TOKEN"),
|
||||||
|
githubToken: "@@GITHUB_TOKEN",
|
||||||
git: new Git({ cwd }),
|
git: new Git({ cwd }),
|
||||||
cwd,
|
cwd,
|
||||||
});
|
});
|
||||||
@@ -150,6 +152,7 @@ describe("version", () => {
|
|||||||
|
|
||||||
await runVersion({
|
await runVersion({
|
||||||
octokit: setupOctokit("@@GITHUB_TOKEN"),
|
octokit: setupOctokit("@@GITHUB_TOKEN"),
|
||||||
|
githubToken: "@@GITHUB_TOKEN",
|
||||||
git: new Git({ cwd }),
|
git: new Git({ cwd }),
|
||||||
cwd,
|
cwd,
|
||||||
});
|
});
|
||||||
@@ -204,6 +207,7 @@ fluminis divesque vulnere aquis parce lapsis rabie si visa fulmineis.
|
|||||||
|
|
||||||
await runVersion({
|
await runVersion({
|
||||||
octokit: setupOctokit("@@GITHUB_TOKEN"),
|
octokit: setupOctokit("@@GITHUB_TOKEN"),
|
||||||
|
githubToken: "@@GITHUB_TOKEN",
|
||||||
git: new Git({ cwd }),
|
git: new Git({ cwd }),
|
||||||
cwd,
|
cwd,
|
||||||
prBodyMaxCharacters: 1000,
|
prBodyMaxCharacters: 1000,
|
||||||
@@ -262,6 +266,7 @@ fluminis divesque vulnere aquis parce lapsis rabie si visa fulmineis.
|
|||||||
|
|
||||||
await runVersion({
|
await runVersion({
|
||||||
octokit: setupOctokit("@@GITHUB_TOKEN"),
|
octokit: setupOctokit("@@GITHUB_TOKEN"),
|
||||||
|
githubToken: "@@GITHUB_TOKEN",
|
||||||
git: new Git({ cwd }),
|
git: new Git({ cwd }),
|
||||||
cwd,
|
cwd,
|
||||||
prBodyMaxCharacters: 500,
|
prBodyMaxCharacters: 500,
|
||||||
|
|||||||
+16
-3
@@ -60,6 +60,7 @@ const createRelease = async (
|
|||||||
|
|
||||||
type PublishOptions = {
|
type PublishOptions = {
|
||||||
script: string;
|
script: string;
|
||||||
|
githubToken: string;
|
||||||
octokit: Octokit;
|
octokit: Octokit;
|
||||||
createGithubReleases: boolean;
|
createGithubReleases: boolean;
|
||||||
git: Git;
|
git: Git;
|
||||||
@@ -79,6 +80,7 @@ type PublishResult =
|
|||||||
|
|
||||||
export async function runPublish({
|
export async function runPublish({
|
||||||
script,
|
script,
|
||||||
|
githubToken,
|
||||||
git,
|
git,
|
||||||
octokit,
|
octokit,
|
||||||
createGithubReleases,
|
createGithubReleases,
|
||||||
@@ -89,7 +91,7 @@ export async function runPublish({
|
|||||||
let changesetPublishOutput = await getExecOutput(
|
let changesetPublishOutput = await getExecOutput(
|
||||||
publishCommand,
|
publishCommand,
|
||||||
publishArgs,
|
publishArgs,
|
||||||
{ cwd }
|
{ cwd, env: { ...process.env, GITHUB_TOKEN: githubToken } }
|
||||||
);
|
);
|
||||||
|
|
||||||
let { packages, tool } = await getPackages(cwd);
|
let { packages, tool } = await getPackages(cwd);
|
||||||
@@ -249,6 +251,7 @@ export async function getVersionPrBody({
|
|||||||
|
|
||||||
type VersionOptions = {
|
type VersionOptions = {
|
||||||
script?: string;
|
script?: string;
|
||||||
|
githubToken: string;
|
||||||
git: Git;
|
git: Git;
|
||||||
octokit: Octokit;
|
octokit: Octokit;
|
||||||
cwd?: string;
|
cwd?: string;
|
||||||
@@ -265,6 +268,7 @@ type RunVersionResult = {
|
|||||||
|
|
||||||
export async function runVersion({
|
export async function runVersion({
|
||||||
script,
|
script,
|
||||||
|
githubToken,
|
||||||
git,
|
git,
|
||||||
octokit,
|
octokit,
|
||||||
cwd = process.cwd(),
|
cwd = process.cwd(),
|
||||||
@@ -282,9 +286,11 @@ export async function runVersion({
|
|||||||
|
|
||||||
let versionsByDirectory = await getVersionsByDirectory(cwd);
|
let versionsByDirectory = await getVersionsByDirectory(cwd);
|
||||||
|
|
||||||
|
const env = { ...process.env, GITHUB_TOKEN: githubToken };
|
||||||
|
|
||||||
if (script) {
|
if (script) {
|
||||||
let [versionCommand, ...versionArgs] = script.split(/\s+/);
|
let [versionCommand, ...versionArgs] = script.split(/\s+/);
|
||||||
await exec(versionCommand, versionArgs, { cwd });
|
await exec(versionCommand, versionArgs, { cwd, env });
|
||||||
} else {
|
} else {
|
||||||
let changesetsCliPkgJson = requireChangesetsCliPkgJson(cwd);
|
let changesetsCliPkgJson = requireChangesetsCliPkgJson(cwd);
|
||||||
let cmd = semverLt(changesetsCliPkgJson.version, "2.0.0")
|
let cmd = semverLt(changesetsCliPkgJson.version, "2.0.0")
|
||||||
@@ -300,6 +306,7 @@ export async function runVersion({
|
|||||||
],
|
],
|
||||||
{
|
{
|
||||||
cwd,
|
cwd,
|
||||||
|
env,
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -340,7 +347,13 @@ export async function runVersion({
|
|||||||
head: `${github.context.repo.owner}:${versionBranch}`,
|
head: `${github.context.repo.owner}:${versionBranch}`,
|
||||||
base: branch,
|
base: branch,
|
||||||
});
|
});
|
||||||
core.info(`Existing pull requests: ${JSON.stringify(existingPullRequests.data, null, 2)}`);
|
core.info(
|
||||||
|
`Existing pull requests: ${JSON.stringify(
|
||||||
|
existingPullRequests.data,
|
||||||
|
null,
|
||||||
|
2
|
||||||
|
)}`
|
||||||
|
);
|
||||||
|
|
||||||
await git.pushChanges({ branch: versionBranch, message: finalCommitMessage });
|
await git.pushChanges({ branch: versionBranch, message: finalCommitMessage });
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user