mirror of
https://github.com/changesets/action
synced 2026-10-26 16:39:56 +08:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
615034bb14 | ||
|
|
8380fc6a4d | ||
|
|
e912ac334c | ||
|
|
f01916801c | ||
|
|
a4133a0d28 | ||
|
|
0138f456ec | ||
|
|
88338839e3 | ||
|
|
e08fde7435 | ||
|
|
371fd77b45 | ||
|
|
85efcafd80 | ||
|
|
5bb9d5ccac | ||
|
|
ca8589735a | ||
|
|
36f529f13a | ||
|
|
d7669c894a | ||
|
|
da1ea291ef |
@@ -27,12 +27,12 @@ jobs:
|
|||||||
security-events: write # allow writing security events
|
security-events: write # allow writing security events
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout repository
|
- name: Checkout repository
|
||||||
uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
|
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
||||||
with:
|
with:
|
||||||
persist-credentials: false
|
persist-credentials: false
|
||||||
|
|
||||||
- name: Run zizmor
|
- name: Run zizmor
|
||||||
uses: zizmorcore/zizmor-action@3dc1ecc9bcb9e94e9b2c709687979e1298497054 # v0.6.2
|
uses: zizmorcore/zizmor-action@cc914d7f3750a2d13d75c7f184a1060aa0e9d482 # v0.6.4
|
||||||
with:
|
with:
|
||||||
persona: pedantic
|
persona: pedantic
|
||||||
annotations: true
|
annotations: true
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ jobs:
|
|||||||
|
|
||||||
- name: Select mode
|
- name: Select mode
|
||||||
id: select-mode
|
id: select-mode
|
||||||
uses: ./select-mode
|
uses: $/select-mode
|
||||||
|
|
||||||
version:
|
version:
|
||||||
name: Version
|
name: Version
|
||||||
@@ -62,7 +62,7 @@ jobs:
|
|||||||
|
|
||||||
- name: Create or update release pull request
|
- name: Create or update release pull request
|
||||||
id: changesets
|
id: changesets
|
||||||
uses: ./version
|
uses: $/version
|
||||||
with:
|
with:
|
||||||
github-token: ${{ steps.bot-auth.outputs.token }}
|
github-token: ${{ steps.bot-auth.outputs.token }}
|
||||||
script: pnpm bump
|
script: pnpm bump
|
||||||
@@ -92,7 +92,7 @@ jobs:
|
|||||||
permission-contents: write # to bypass branch and tag protection rules (release.ts)
|
permission-contents: write # to bypass branch and tag protection rules (release.ts)
|
||||||
|
|
||||||
- name: Publish to marketplace
|
- name: Publish to marketplace
|
||||||
uses: ./publish
|
uses: $/publish
|
||||||
with:
|
with:
|
||||||
github-token: ${{ steps.bot-auth.outputs.token }}
|
github-token: ${{ steps.bot-auth.outputs.token }}
|
||||||
script: pnpm release
|
script: pnpm release
|
||||||
|
|||||||
@@ -1,5 +1,23 @@
|
|||||||
# @changesets/action
|
# @changesets/action
|
||||||
|
|
||||||
|
## 2.1.2
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- [#735](https://github.com/changesets/action/pull/735) [`8833883`](https://github.com/changesets/action/commit/88338839e35c3e0fa61f3c9c3f27e7572cd5f2cf) Thanks [@bluwy](https://github.com/bluwy)! - Handle error when pushing git tags with the git CLI
|
||||||
|
|
||||||
|
- [#724](https://github.com/changesets/action/pull/724) [`36f529f`](https://github.com/changesets/action/commit/36f529f13ab58bbcf6331035cb950385586e8a89) Thanks [@bluwy](https://github.com/bluwy)! - Improve log messages
|
||||||
|
|
||||||
|
- [#724](https://github.com/changesets/action/pull/724) [`36f529f`](https://github.com/changesets/action/commit/36f529f13ab58bbcf6331035cb950385586e8a89) Thanks [@bluwy](https://github.com/bluwy)! - Fix root action double error logs
|
||||||
|
|
||||||
|
- [#729](https://github.com/changesets/action/pull/729) [`ca85897`](https://github.com/changesets/action/commit/ca8589735af2ff6977a0f6474537d550040530d8) Thanks [@bluwy](https://github.com/bluwy)! - Always switch and reset branch when generating version commits, similar to if `push-with-git-cli` is enabled
|
||||||
|
|
||||||
|
## 2.1.1
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- [#721](https://github.com/changesets/action/pull/721) [`da1ea29`](https://github.com/changesets/action/commit/da1ea291ef93203a08fad360eac36f4858dd0514) Thanks [@KEBABSELLER6](https://github.com/KEBABSELLER6)! - Fixed typo in renamed inputs from v1 to v2
|
||||||
|
|
||||||
## 2.1.0
|
## 2.1.0
|
||||||
|
|
||||||
### Minor Changes
|
### Minor Changes
|
||||||
|
|||||||
Vendored
-12
File diff suppressed because one or more lines are too long
Vendored
-1
@@ -1 +0,0 @@
|
|||||||
import{A as e,D as t,E as n,O as r,f as i,j as a,k as o,m as s,o as c,p as l,s as u}from"./utils-CAuP846_.js";import{n as d,r as f,t as p}from"./run-NkR1hNWV.js";import{t as m}from"./readChangesetState-D-vw_tSH.js";(async()=>{let h=c(`cwd`)||process.cwd();await s(h),l({publish:`publish-script`,version:`version-script`,commit:`commit-mesage`,title:`pr-title`,branch:`pr-base-branch`,prDraft:`pr-draft`,createGithubReleases:`create-github-releases`}),i();let g=u(`github-token`);if(process.env.GITHUB_TOKEN&&process.env.GITHUB_TOKEN!==g)throw Error(`The GITHUB_TOKEN environment variable is set and does not match the "github-token" input. Please pass the custom GitHub token to the "github-token" input and remove the GITHUB_TOKEN environment variable to avoid conflicts.`);let _=t(`push-with-git-cli`),v=c(`pr-draft`);if(v!==void 0&&v!==`always`&&v!==`create`){e(`Invalid pr-draft: ${v}`);return}let y=new f({cwd:h,githubToken:g,pushWithGitCli:_}),{changesets:b}=await m(h),x=r(`publish-script`),S=b.length!==0,C=b.some(e=>e.releases.length>0),w=!!x;switch(a(`published`,`false`),a(`published-packages`,`[]`),a(`has-changesets`,String(S)),!0){case!S&&!w:o(`No changesets present or were removed by merging release PR. Not publishing because no publish script found.`);return;case!S&&w:{o(`No changesets found. Attempting to publish any unpublished packages to npm`);let e=t(`create-github-releases`),r=t(`push-git-tags`);if(e&&!r)throw Error(`The input 'create-github-releases' is set to true, but 'push-git-tags' is set to false. Creating GitHub releases requires pushing git tags. Please set 'push-git-tags' to true or set 'create-github-releases' to false.`);let i=await p({script:x,github:y,createGithubReleases:e,pushGitTags:r,cwd:h});i.published&&(a(`published`,`true`),a(`published-packages`,JSON.stringify(i.publishedPackages))),i.exitCode!==0&&(n(`Publish command exited with code ${i.exitCode}${i.published?`, but some packages were published: ${i.publishedPackages.map(e=>`${e.name}@${e.version}`).join(`, `)}`:``}`),process.exit(i.exitCode));return}case S&&!C:o(`All changesets are empty; not creating PR`);return;case S:{let{pullRequestNumber:e}=await d({script:c(`version-script`),github:y,cwd:h,prTitle:c(`pr-title`),commitMessage:c(`commit-message`),hasPublishScript:w,prDraft:v,branch:c(`pr-base-branch`)});a(`pr-number`,String(e));return}}})().catch(t=>{n(t),e(t.message)});export{};
|
|
||||||
Vendored
-1
@@ -1 +0,0 @@
|
|||||||
import{A as e,j as t,m as n,n as r,o as i,t as a,y as o}from"./utils-CAuP846_.js";import s from"node:fs/promises";import c from"node:path";import l from"node:os";try{await u()}catch(t){e(t.message)}async function u(){let e=i(`cwd`)||process.cwd();await n(e);let r=i(`publish-plan-artifact-id`),a=process.env.RUNNER_TEMP??await s.realpath(l.tmpdir()),u=c.join(a,`changeset-pack-${Date.now()}`);await d(e,{outDir:u,publishPlanPath:r?await f(a,Number(r)):void 0});let m=await o.uploadArtifact(`changeset-pack-${Date.now()}`,await p(u),u,{retentionDays:30});if(m.id===void 0)throw Error(`Packed artifact upload did not return an artifact id`);t(`pack-dir-artifact-id`,String(m.id))}async function d(e,t){let n=[`pack`,`--out-dir`,t.outDir];t.publishPlanPath&&n.push(`--from-publish-plan`,t.publishPlanPath),await r(n,{cwd:e,env:process.env})}async function f(e,t){let n=await a(e,t,`changeset-publish-plan`);return c.join(n,`publish-plan.json`)}async function p(e){let t=await s.readdir(e,{withFileTypes:!0});return(await Promise.all(t.map(async t=>{let n=c.join(e,t.name);return t.isDirectory()?p(n):[n]}))).flat()}export{};
|
|
||||||
Vendored
-1
@@ -1 +0,0 @@
|
|||||||
import{A as e,T as t,j as n,k as r,o as i,s as a,w as o}from"./utils-CAuP846_.js";try{await s()}catch(t){e(t.message)}async function s(){let e=o.payload.pull_request;if(!e)throw Error("This action should only be run on `pull_request_target` or `pull_request` events");let s=a(`github-token`),l=a(`body`),u=i(`update-id`),d=u?c(u):null,f=d?`${d}\n\n${l}`:l,p={repo:e.base.repo.name,owner:e.base.repo.owner.login,issue_number:e.number,body:f},m=t(s),h;if(d&&(r(`Checking for existing comment...`),h=await m.rest.issues.listComments({repo:e.base.repo.name,owner:e.base.repo.owner.login,issue_number:e.number}).then(e=>e.data.find(e=>e.body?.includes(d))?.id)),h)r(`Updating existing comment (id: ${h})...`),await m.rest.issues.updateComment({...p,comment_id:h}),n(`comment-id`,h);else{r(`Creating new comment...`);let e=await m.rest.issues.createComment(p);n(`comment-id`,e.data.id)}r(`Done!`)}function c(e){let t=`changesets-action-pr-comment`;return t===e?`<!-- ${t} -->`:`<!-- ${t}:${e} -->`}export{};
|
|
||||||
Vendored
-38
File diff suppressed because one or more lines are too long
Vendored
-1
@@ -1 +0,0 @@
|
|||||||
import{A as e,D as t,j as n,m as r,o as i,s as a,t as o}from"./utils-CAuP846_.js";import{r as s,t as c}from"./run-NkR1hNWV.js";import l from"node:fs/promises";import u from"node:os";try{await d()}catch(t){e(t.message)}async function d(){let e=i(`cwd`)||process.cwd();await r(e);let d=a(`github-token`),f=i(`script`),p=i(`pack-dir-artifact-id`),m=t(`create-github-releases`),h=t(`push-git-tags`);if(m&&!h)throw Error(`The input 'create-github-releases' is set to true, but 'push-git-tags' is set to false. Creating GitHub releases requires pushing git tags. Please set 'push-git-tags' to true or set 'create-github-releases' to false.`);let g=new s({cwd:e,githubToken:d}),_=p?await o(process.env.RUNNER_TEMP??await l.realpath(u.tmpdir()),Number(p),`changeset-pack`):void 0,v=await c({script:f,github:g,createGithubReleases:m,pushGitTags:h,cwd:e,fromPackDir:_});if(v.published?(n(`published`,`true`),n(`published-packages`,JSON.stringify(v.publishedPackages))):n(`published`,`false`),v.exitCode!==0)throw Error(`Publish command exited with code ${v.exitCode}${v.published?`, but some packages were published: ${v.publishedPackages.map(e=>`${e.name}@${e.version}`).join(`, `)}`:``}`)}export{};
|
|
||||||
Vendored
-1
@@ -1 +0,0 @@
|
|||||||
import{i as e,t}from"./dist-Bc2tm86q.js";async function n(n=process.cwd()){let r=await e(n),i=await t(n);return r!==void 0&&r.mode===`pre`?{preState:r,changesets:i.filter(e=>!e.id.startsWith(`pre/`))}:{preState:void 0,changesets:i}}export{n as t};
|
|
||||||
Vendored
-98
File diff suppressed because one or more lines are too long
Vendored
-1
@@ -1 +0,0 @@
|
|||||||
import{A as e,j as t,m as n,n as r,o as i,y as a}from"./utils-CAuP846_.js";import{t as o}from"./readChangesetState-D-vw_tSH.js";import s from"node:fs/promises";import c from"node:path";import l from"node:os";try{await u()}catch(t){e(t.message)}async function u(){let e=i(`cwd`)||process.cwd();await n(e);let r=await d(e);if(t(`mode`,r.mode),r.mode===`publish`){let e=await a.uploadArtifact(c.basename(r.publishPlanPath,`.json`),[r.publishPlanPath],c.dirname(r.publishPlanPath),{skipArchive:!0,retentionDays:30});if(e.id===void 0)throw Error(`Publish plan artifact upload did not return an artifact id`);t(`publish-plan-artifact-id`,String(e.id))}}async function d(e){let{changesets:t}=await o(e);if(t.length>0)return t.some(e=>e.releases.length>0)?{mode:`version`}:{mode:`none`};let n=c.join(process.env.RUNNER_TEMP??await s.realpath(l.tmpdir()),`changeset-publish-plan-${Date.now()}`,`publish-plan.json`);return await r([`publish-plan`,`--output`,n],{cwd:e,env:process.env}),(await f(n)).length===0?{mode:`none`}:{mode:`publish`,publishPlanPath:n}}async function f(e){let t;try{t=await s.readFile(e,`utf8`)}catch(t){throw Error(`Failed to read publish plan at ${e}`,{cause:t})}let n;try{n=JSON.parse(t)}catch(t){throw Error(`Failed to parse publish plan at ${e}`,{cause:t})}if(typeof n!=`object`||!n||!(`version`in n)||typeof n.version!=`number`||!(`plan`in n)||!Array.isArray(n.plan))throw Error(`Invalid publish plan at ${e}: expected { version: number; plan: unknown[] }`);return n.plan}export{};
|
|
||||||
Vendored
-228
File diff suppressed because one or more lines are too long
Vendored
-1
@@ -1 +0,0 @@
|
|||||||
import{A as e,D as t,f as n,j as r,m as i,o as a,s as o}from"./utils-CAuP846_.js";import{n as s,r as c}from"./run-NkR1hNWV.js";try{await l()}catch(t){e(t.message)}async function l(){let e=a(`cwd`)||process.cwd();await i(e),n();let l=o(`github-token`),u=a(`script`),d=o(`commit-message`),f=o(`pr-title`),p=a(`pr-draft`),m=a(`pr-base-branch`),h=t(`push-with-git-cli`);if(p!==void 0&&p!==`always`&&p!==`create`)throw Error(`Invalid pr-draft input: ${p}`);let g=new c({cwd:e,githubToken:l,pushWithGitCli:h}),{pullRequestNumber:_}=await s({script:u,github:g,cwd:e,prTitle:f,commitMessage:d,hasPublishScript:!0,prDraft:p,branch:m});r(`pr-number`,String(_))}export{};
|
|
||||||
+18
-18
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@changesets/action",
|
"name": "@changesets/action",
|
||||||
"version": "2.1.0",
|
"version": "2.1.2",
|
||||||
"private": true,
|
"private": true,
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
@@ -23,33 +23,33 @@
|
|||||||
"@actions/core": "^3.0.1",
|
"@actions/core": "^3.0.1",
|
||||||
"@actions/exec": "^3.0.0",
|
"@actions/exec": "^3.0.0",
|
||||||
"@actions/github": "^9.1.1",
|
"@actions/github": "^9.1.1",
|
||||||
"@changesets/get-release-plan": "^5.0.0",
|
"@changesets/get-release-plan": "^5.0.2",
|
||||||
"@changesets/ghcommit": "^3.0.0",
|
"@changesets/ghcommit": "^3.0.0",
|
||||||
"@changesets/git": "^4.0.0",
|
"@changesets/git": "^4.0.1",
|
||||||
"@changesets/pre": "^3.0.0",
|
"@changesets/pre": "^3.0.0",
|
||||||
"@changesets/read": "^1.0.0",
|
"@changesets/read": "^1.0.1",
|
||||||
"@manypkg/get-packages": "^3.1.0",
|
"@manypkg/get-packages": "^3.1.0",
|
||||||
"@octokit/core": "^7.0.7",
|
"@octokit/core": "^7.0.8",
|
||||||
"@octokit/plugin-throttling": "^11.0.5",
|
"@octokit/plugin-throttling": "^11.0.5",
|
||||||
"human-id": "^4.2.0",
|
"human-id": "^4.2.1",
|
||||||
"markdown-table": "^3.0.4",
|
"markdown-table": "^3.0.4",
|
||||||
"semver": "^7.8.5",
|
"semver": "^7.8.5",
|
||||||
"tinyexec": "^1.3.0"
|
"tinyexec": "^1.3.1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@changesets/changelog-github": "^1.0.0",
|
"@changesets/changelog-github": "^1.0.1",
|
||||||
"@changesets/cli": "^3.0.0",
|
"@changesets/cli": "^3.0.3",
|
||||||
"@changesets/types": "^7.0.0",
|
"@changesets/types": "^7.0.0",
|
||||||
"@changesets/write": "^1.0.0",
|
"@changesets/write": "^1.0.1",
|
||||||
"@tsconfig/node24": "^24.0.4",
|
"@tsconfig/node24": "^24.0.5",
|
||||||
"@types/node": "^26.1.2",
|
"@types/node": "^26.6.2",
|
||||||
"@types/semver": "^7.8.0",
|
"@types/semver": "^7.8.0",
|
||||||
"fs-fixture": "^2.14.0",
|
"fs-fixture": "^2.16.0",
|
||||||
"oxfmt": "^0.61.0",
|
"oxfmt": "^0.70.0",
|
||||||
"rolldown": "^1.2.2",
|
"rolldown": "^1.2.10",
|
||||||
"typescript": "^6.0.3",
|
"typescript": "^7.0.2",
|
||||||
"vitest": "^4.1.10",
|
"vitest": "^5.0.1",
|
||||||
"yaml": "^2.9.0"
|
"yaml": "^2.9.1"
|
||||||
},
|
},
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=24"
|
"node": ">=24"
|
||||||
|
|||||||
Generated
+635
-422
File diff suppressed because it is too large
Load Diff
+10
-12
@@ -195,7 +195,7 @@ export class GitHub {
|
|||||||
if (authorIdentity.exitCode === 0 && committerIdentity.exitCode === 0) {
|
if (authorIdentity.exitCode === 0 && committerIdentity.exitCode === 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
core.info("Setting Git user to github-actions[bot]");
|
core.info("Setting git user to github-actions[bot]");
|
||||||
await exec("git", ["config", "user.name", `"github-actions[bot]"`], {
|
await exec("git", ["config", "user.name", `"github-actions[bot]"`], {
|
||||||
cwd: this.cwd,
|
cwd: this.cwd,
|
||||||
});
|
});
|
||||||
@@ -213,18 +213,14 @@ export class GitHub {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async pushTag(tag: string) {
|
async pushTag(tag: string) {
|
||||||
|
try {
|
||||||
if (!this.pushWithGitCli) {
|
if (!this.pushWithGitCli) {
|
||||||
return this.octokit.rest.git
|
await this.octokit.rest.git.createRef({
|
||||||
.createRef({
|
|
||||||
...context.repo,
|
...context.repo,
|
||||||
ref: `refs/tags/${tag}`,
|
ref: `refs/tags/${tag}`,
|
||||||
sha: context.sha,
|
sha: context.sha,
|
||||||
})
|
|
||||||
.catch((err) => {
|
|
||||||
// Assuming tag was manually pushed in custom publish script
|
|
||||||
core.warning(`Failed to create tag ${tag}: ${err.message}`);
|
|
||||||
});
|
});
|
||||||
}
|
} else {
|
||||||
await exec("git", ["push", "origin", tag], {
|
await exec("git", ["push", "origin", tag], {
|
||||||
cwd: this.cwd,
|
cwd: this.cwd,
|
||||||
env: {
|
env: {
|
||||||
@@ -233,12 +229,14 @@ export class GitHub {
|
|||||||
} as Record<string, string>,
|
} as Record<string, string>,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
} catch (err) {
|
||||||
|
core.warning(
|
||||||
|
`Failed to create git tag "${tag}". Assuming it was manually pushed by the publish script: ${(err as Error).message}`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async prepareBranch(branch: string) {
|
async prepareBranch(branch: string) {
|
||||||
if (!this.pushWithGitCli) {
|
|
||||||
// Preparing a new local branch is not necessary when using the API
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
await switchToMaybeExistingBranch(branch, { cwd: this.cwd });
|
await switchToMaybeExistingBranch(branch, { cwd: this.cwd });
|
||||||
await reset(context.sha, { cwd: this.cwd });
|
await reset(context.sha, { cwd: this.cwd });
|
||||||
}
|
}
|
||||||
|
|||||||
+12
-10
@@ -10,14 +10,20 @@ import {
|
|||||||
validateChangesetsCliVersion,
|
validateChangesetsCliVersion,
|
||||||
} from "./utils.ts";
|
} from "./utils.ts";
|
||||||
|
|
||||||
(async () => {
|
try {
|
||||||
|
await main();
|
||||||
|
} catch (err) {
|
||||||
|
core.setFailed((err as Error).message);
|
||||||
|
}
|
||||||
|
|
||||||
|
async function main() {
|
||||||
const cwd = getOptionalInput("cwd") || process.cwd();
|
const cwd = getOptionalInput("cwd") || process.cwd();
|
||||||
await validateChangesetsCliVersion(cwd);
|
await validateChangesetsCliVersion(cwd);
|
||||||
|
|
||||||
throwOnRenamedInputs({
|
throwOnRenamedInputs({
|
||||||
publish: "publish-script",
|
publish: "publish-script",
|
||||||
version: "version-script",
|
version: "version-script",
|
||||||
commit: "commit-mesage",
|
commit: "commit-message",
|
||||||
title: "pr-title",
|
title: "pr-title",
|
||||||
branch: "pr-base-branch",
|
branch: "pr-base-branch",
|
||||||
prDraft: "pr-draft",
|
prDraft: "pr-draft",
|
||||||
@@ -62,7 +68,7 @@ import {
|
|||||||
switch (true) {
|
switch (true) {
|
||||||
case !hasChangesets && !hasPublishScript:
|
case !hasChangesets && !hasPublishScript:
|
||||||
core.info(
|
core.info(
|
||||||
"No changesets present or were removed by merging release PR. Not publishing because no publish script found.",
|
"No changesets present or were removed by merging version PR. Not publishing because publish-script is not set.",
|
||||||
);
|
);
|
||||||
return;
|
return;
|
||||||
case !hasChangesets && hasPublishScript: {
|
case !hasChangesets && hasPublishScript: {
|
||||||
@@ -98,7 +104,7 @@ import {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (result.exitCode !== 0) {
|
if (result.exitCode !== 0) {
|
||||||
core.error(
|
throw new Error(
|
||||||
`Publish command exited with code ${result.exitCode}${
|
`Publish command exited with code ${result.exitCode}${
|
||||||
result.published
|
result.published
|
||||||
? `, but some packages were published: ${result.publishedPackages
|
? `, but some packages were published: ${result.publishedPackages
|
||||||
@@ -107,12 +113,11 @@ import {
|
|||||||
: ""
|
: ""
|
||||||
}`,
|
}`,
|
||||||
);
|
);
|
||||||
process.exit(result.exitCode);
|
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
case hasChangesets && !hasNonEmptyChangesets:
|
case hasChangesets && !hasNonEmptyChangesets:
|
||||||
core.info("All changesets are empty; not creating PR");
|
core.info("All changesets are empty. Not creating PR");
|
||||||
return;
|
return;
|
||||||
case hasChangesets: {
|
case hasChangesets: {
|
||||||
const { pullRequestNumber } = await runVersion({
|
const { pullRequestNumber } = await runVersion({
|
||||||
@@ -131,7 +136,4 @@ import {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})().catch((err) => {
|
}
|
||||||
core.error(err);
|
|
||||||
core.setFailed(err.message);
|
|
||||||
});
|
|
||||||
|
|||||||
+23
-9
@@ -1,12 +1,13 @@
|
|||||||
import path from "node:path";
|
import path from "node:path";
|
||||||
import * as core from "@actions/core";
|
import * as core from "@actions/core";
|
||||||
|
import * as github from "@actions/github";
|
||||||
import type { Changeset } from "@changesets/types";
|
import type { Changeset } from "@changesets/types";
|
||||||
import { writeChangeset } from "@changesets/write";
|
import { writeChangeset } from "@changesets/write";
|
||||||
import { createFixture } from "fs-fixture";
|
|
||||||
import { exec } from "tinyexec";
|
import { exec } from "tinyexec";
|
||||||
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||||
import { GitHub } from "./github.ts";
|
import { GitHub } from "./github.ts";
|
||||||
import { runPublish, runVersion } from "./run.ts";
|
import { runPublish, runVersion } from "./run.ts";
|
||||||
|
import { gitdir } from "./test-utils.ts";
|
||||||
|
|
||||||
vi.mock("@actions/github", () => ({
|
vi.mock("@actions/github", () => ({
|
||||||
context: {
|
context: {
|
||||||
@@ -44,7 +45,7 @@ let mockedGraphql = vi.fn();
|
|||||||
const nodeModulesDir = path.join(import.meta.dirname, "..", "node_modules");
|
const nodeModulesDir = path.join(import.meta.dirname, "..", "node_modules");
|
||||||
|
|
||||||
function createSimpleProjectFixture() {
|
function createSimpleProjectFixture() {
|
||||||
return createFixture({
|
return gitdir({
|
||||||
node_modules: (api) => api.symlink(nodeModulesDir),
|
node_modules: (api) => api.symlink(nodeModulesDir),
|
||||||
".changeset/config.json": JSON.stringify({}),
|
".changeset/config.json": JSON.stringify({}),
|
||||||
"packages/pkg-a/package.json": JSON.stringify({
|
"packages/pkg-a/package.json": JSON.stringify({
|
||||||
@@ -69,7 +70,7 @@ function createSimpleProjectFixture() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function createIgnoredPackageFixture() {
|
function createIgnoredPackageFixture() {
|
||||||
return createFixture({
|
return gitdir({
|
||||||
node_modules: (api) => api.symlink(nodeModulesDir),
|
node_modules: (api) => api.symlink(nodeModulesDir),
|
||||||
".changeset/config.json": JSON.stringify({
|
".changeset/config.json": JSON.stringify({
|
||||||
ignore: ["changesets-dev-ignored-package-pkg-a"],
|
ignore: ["changesets-dev-ignored-package-pkg-a"],
|
||||||
@@ -106,15 +107,20 @@ const createGithub = (cwd: string) =>
|
|||||||
pushWithGitCli: false,
|
pushWithGitCli: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
async function initializeGitRepository(cwd: string) {
|
async function updateGithubContext(cwd: string) {
|
||||||
await exec("git", ["init"], {
|
const head = await exec("git", ["rev-parse", "HEAD"], {
|
||||||
nodeOptions: { cwd },
|
nodeOptions: { cwd },
|
||||||
throwOnError: true,
|
|
||||||
});
|
});
|
||||||
|
github.context.sha = head.stdout.trim();
|
||||||
|
}
|
||||||
|
|
||||||
|
function resetGithubContext() {
|
||||||
|
github.context.sha = "xeac7";
|
||||||
}
|
}
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
vi.clearAllMocks();
|
vi.clearAllMocks();
|
||||||
|
resetGithubContext();
|
||||||
});
|
});
|
||||||
|
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
@@ -125,7 +131,7 @@ describe("publish", () => {
|
|||||||
it("warns when a custom publish script does not create the output file", async () => {
|
it("warns when a custom publish script does not create the output file", async () => {
|
||||||
await using fixture = await createSimpleProjectFixture();
|
await using fixture = await createSimpleProjectFixture();
|
||||||
const cwd = fixture.path;
|
const cwd = fixture.path;
|
||||||
await initializeGitRepository(cwd);
|
await updateGithubContext(cwd);
|
||||||
vi.stubEnv("RUNNER_TEMP", cwd);
|
vi.stubEnv("RUNNER_TEMP", cwd);
|
||||||
|
|
||||||
const result = await runPublish({
|
const result = await runPublish({
|
||||||
@@ -145,7 +151,7 @@ describe("publish", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("throws when the built-in publish command does not create the output file", async () => {
|
it("throws when the built-in publish command does not create the output file", async () => {
|
||||||
await using fixture = await createFixture({
|
await using fixture = await gitdir({
|
||||||
"node_modules/@changesets/cli/package.json": JSON.stringify({
|
"node_modules/@changesets/cli/package.json": JSON.stringify({
|
||||||
name: "@changesets/cli",
|
name: "@changesets/cli",
|
||||||
type: "module",
|
type: "module",
|
||||||
@@ -158,7 +164,7 @@ describe("publish", () => {
|
|||||||
"package-lock.json": "",
|
"package-lock.json": "",
|
||||||
});
|
});
|
||||||
const cwd = fixture.path;
|
const cwd = fixture.path;
|
||||||
await initializeGitRepository(cwd);
|
await updateGithubContext(cwd);
|
||||||
vi.stubEnv("RUNNER_TEMP", cwd);
|
vi.stubEnv("RUNNER_TEMP", cwd);
|
||||||
|
|
||||||
await expect(
|
await expect(
|
||||||
@@ -176,6 +182,7 @@ describe("version", () => {
|
|||||||
it("creates simple PR", async () => {
|
it("creates simple PR", async () => {
|
||||||
await using fixture = await createSimpleProjectFixture();
|
await using fixture = await createSimpleProjectFixture();
|
||||||
const cwd = fixture.path;
|
const cwd = fixture.path;
|
||||||
|
await updateGithubContext(cwd);
|
||||||
|
|
||||||
mockedGithubMethods.pulls.list.mockImplementationOnce(() => ({ data: [] }));
|
mockedGithubMethods.pulls.list.mockImplementationOnce(() => ({ data: [] }));
|
||||||
|
|
||||||
@@ -213,6 +220,7 @@ describe("version", () => {
|
|||||||
it('creates a draft PR when prDraft is "create"', async () => {
|
it('creates a draft PR when prDraft is "create"', async () => {
|
||||||
await using fixture = await createSimpleProjectFixture();
|
await using fixture = await createSimpleProjectFixture();
|
||||||
const cwd = fixture.path;
|
const cwd = fixture.path;
|
||||||
|
await updateGithubContext(cwd);
|
||||||
|
|
||||||
mockedGithubMethods.pulls.list.mockImplementationOnce(() => ({ data: [] }));
|
mockedGithubMethods.pulls.list.mockImplementationOnce(() => ({ data: [] }));
|
||||||
|
|
||||||
@@ -247,6 +255,7 @@ describe("version", () => {
|
|||||||
it("only includes bumped packages in the PR body", async () => {
|
it("only includes bumped packages in the PR body", async () => {
|
||||||
await using fixture = await createSimpleProjectFixture();
|
await using fixture = await createSimpleProjectFixture();
|
||||||
const cwd = fixture.path;
|
const cwd = fixture.path;
|
||||||
|
await updateGithubContext(cwd);
|
||||||
|
|
||||||
mockedGithubMethods.pulls.list.mockImplementationOnce(() => ({ data: [] }));
|
mockedGithubMethods.pulls.list.mockImplementationOnce(() => ({ data: [] }));
|
||||||
|
|
||||||
@@ -280,6 +289,7 @@ describe("version", () => {
|
|||||||
it("doesn't include ignored package that got a dependency update in the PR body", async () => {
|
it("doesn't include ignored package that got a dependency update in the PR body", async () => {
|
||||||
await using fixture = await createIgnoredPackageFixture();
|
await using fixture = await createIgnoredPackageFixture();
|
||||||
const cwd = fixture.path;
|
const cwd = fixture.path;
|
||||||
|
await updateGithubContext(cwd);
|
||||||
|
|
||||||
mockedGithubMethods.pulls.list.mockImplementationOnce(() => ({ data: [] }));
|
mockedGithubMethods.pulls.list.mockImplementationOnce(() => ({ data: [] }));
|
||||||
|
|
||||||
@@ -313,6 +323,7 @@ describe("version", () => {
|
|||||||
it("does not include changelog entries if full message exceeds size limit", async () => {
|
it("does not include changelog entries if full message exceeds size limit", async () => {
|
||||||
await using fixture = await createSimpleProjectFixture();
|
await using fixture = await createSimpleProjectFixture();
|
||||||
const cwd = fixture.path;
|
const cwd = fixture.path;
|
||||||
|
await updateGithubContext(cwd);
|
||||||
|
|
||||||
mockedGithubMethods.pulls.list.mockImplementationOnce(() => ({ data: [] }));
|
mockedGithubMethods.pulls.list.mockImplementationOnce(() => ({ data: [] }));
|
||||||
|
|
||||||
@@ -370,6 +381,7 @@ fluminis divesque vulnere aquis parce lapsis rabie si visa fulmineis.
|
|||||||
it("does not include any release information if a message with simplified release info exceeds size limit", async () => {
|
it("does not include any release information if a message with simplified release info exceeds size limit", async () => {
|
||||||
await using fixture = await createSimpleProjectFixture();
|
await using fixture = await createSimpleProjectFixture();
|
||||||
const cwd = fixture.path;
|
const cwd = fixture.path;
|
||||||
|
await updateGithubContext(cwd);
|
||||||
|
|
||||||
mockedGithubMethods.pulls.list.mockImplementationOnce(() => ({ data: [] }));
|
mockedGithubMethods.pulls.list.mockImplementationOnce(() => ({ data: [] }));
|
||||||
|
|
||||||
@@ -427,6 +439,7 @@ fluminis divesque vulnere aquis parce lapsis rabie si visa fulmineis.
|
|||||||
it('updates an existing PR via GraphQL without converting it to draft when prDraft is "create"', async () => {
|
it('updates an existing PR via GraphQL without converting it to draft when prDraft is "create"', async () => {
|
||||||
await using fixture = await createSimpleProjectFixture();
|
await using fixture = await createSimpleProjectFixture();
|
||||||
const cwd = fixture.path;
|
const cwd = fixture.path;
|
||||||
|
await updateGithubContext(cwd);
|
||||||
|
|
||||||
mockedGithubMethods.pulls.list.mockImplementationOnce(() => ({
|
mockedGithubMethods.pulls.list.mockImplementationOnce(() => ({
|
||||||
data: [{ number: 123, node_id: "PR_kwDOA" }],
|
data: [{ number: 123, node_id: "PR_kwDOA" }],
|
||||||
@@ -459,6 +472,7 @@ fluminis divesque vulnere aquis parce lapsis rabie si visa fulmineis.
|
|||||||
it('updates an existing PR via GraphQL and converts it to draft when prDraft is "always"', async () => {
|
it('updates an existing PR via GraphQL and converts it to draft when prDraft is "always"', async () => {
|
||||||
await using fixture = await createSimpleProjectFixture();
|
await using fixture = await createSimpleProjectFixture();
|
||||||
const cwd = fixture.path;
|
const cwd = fixture.path;
|
||||||
|
await updateGithubContext(cwd);
|
||||||
|
|
||||||
mockedGithubMethods.pulls.list.mockImplementationOnce(() => ({
|
mockedGithubMethods.pulls.list.mockImplementationOnce(() => ({
|
||||||
data: [{ number: 123, node_id: "PR_kwDOA" }],
|
data: [{ number: 123, node_id: "PR_kwDOA" }],
|
||||||
|
|||||||
+3
-3
@@ -401,7 +401,7 @@ export async function runVersion({
|
|||||||
head: `${context.repo.owner}:${versionBranch}`,
|
head: `${context.repo.owner}:${versionBranch}`,
|
||||||
base: branch,
|
base: branch,
|
||||||
});
|
});
|
||||||
core.info(
|
core.debug(
|
||||||
`Existing pull requests: ${JSON.stringify(
|
`Existing pull requests: ${JSON.stringify(
|
||||||
existingPullRequests.data,
|
existingPullRequests.data,
|
||||||
null,
|
null,
|
||||||
@@ -427,7 +427,7 @@ export async function runVersion({
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (existingPullRequests.data.length === 0) {
|
if (existingPullRequests.data.length === 0) {
|
||||||
core.info("creating pull request");
|
core.info("Creating pull request");
|
||||||
const { data: newPullRequest } = await octokit.rest.pulls.create({
|
const { data: newPullRequest } = await octokit.rest.pulls.create({
|
||||||
base: branch,
|
base: branch,
|
||||||
head: versionBranch,
|
head: versionBranch,
|
||||||
@@ -443,7 +443,7 @@ export async function runVersion({
|
|||||||
} else {
|
} else {
|
||||||
const [pullRequest] = existingPullRequests.data;
|
const [pullRequest] = existingPullRequests.data;
|
||||||
|
|
||||||
core.info(`updating found pull request #${pullRequest.number}`);
|
core.info(`Updating found pull request #${pullRequest.number}`);
|
||||||
const convertPullRequestToDraftMutation =
|
const convertPullRequestToDraftMutation =
|
||||||
prDraft === "always"
|
prDraft === "always"
|
||||||
? `
|
? `
|
||||||
|
|||||||
Reference in New Issue
Block a user