diff --git a/dist/index.js b/dist/index.js index dbe8a14..c2988d9 100644 --- a/dist/index.js +++ b/dist/index.js @@ -903,7 +903,7 @@ var e=require("./conversions"),n=require("./route"),r={},o=Object.keys(e);functi },{"fs-extra":"1591","@changesets/parse":"pjrD","@changesets/git":"hWLG","chalk":"hGPX","p-filter":"o7Ua","@changesets/logger":"z9Gu"}],"yOXS":[function(require,module,exports) { "use strict";var e=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0});const t=require("@changesets/pre"),r=e(require("@changesets/read"));async function s(e=process.cwd()){let s=await t.readPreState(e),a=void 0!==s&&"pre"===s.mode,i=await r.default(e);if(a){let e=new Set(s.changesets);i=i.filter(t=>!e.has(t.id))}return{preState:a?s:void 0,changesets:i}}exports.default=s; },{"@changesets/pre":"mAOc","@changesets/read":"X/D8"}],"gwbb":[function(require,module,exports) { -"use strict";function e(e,t){var a=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),a.push.apply(a,n)}return a}function t(t){for(var n=1;n{try{let s=l.default.join(a.dir,"CHANGELOG.md"),c=await i.default.readFile(s,"utf8"),u=p.getChangelogEntry(c,a.packageJson.version);if(!u)throw new Error(`Could not find changelog entry for ${a.packageJson.name}@${a.packageJson.version}`);await e.repos.createRelease(t({tag_name:n,body:u.content,prerelease:a.packageJson.version.includes("-")},o.context.repo))}catch(r){if("ENOENT"!==r.code)throw r}};async function f({script:e,githubToken:t,cwd:a=process.cwd()}){let n=o.context.ref.replace("refs/heads/",""),r=o.getOctokit(t),[s,...i]=e.split(/\s+/),l=await p.execWithOutput(s,i,{cwd:a});await g.pullBranch(n),await g.push(n,{includeTags:!0});let{packages:u,tool:h}=await c.getPackages(a),f=[];if("root"!==h){let e=/New tag:\s+(@[^/]+\/[^@]+|[^/]+)@([^\s]+)/,t=new Map(u.map(e=>[e.packageJson.name,e]));for(let a of l.stdout.split("\n")){let n=a.match(e);if(null===n)continue;let r=n[1],s=t.get(r);if(void 0===s)throw new Error(`Package "${r}" not found.`+"This is probably a bug in the action, please open an issue");f.push(s)}await Promise.all(f.map(e=>d(r,{pkg:e,tagName:`${e.packageJson.name}@${e.packageJson.version}`})))}else{if(0===u.length)throw new Error("No package found.This is probably a bug in the action, please open an issue");const e=u[0];f.push(e),await d(r,{pkg:e,tagName:`v${e.packageJson.version}`})}return f.length?{published:!0,publishedPackages:f.map(e=>({name:e.packageJson.name,version:e.packageJson.version}))}:{published:!1}}async function w({script:e,githubToken:a,cwd:n=process.cwd(),prTitle:r="Version Packages",commitMessage:c="Version Packages",hasPublishScript:d=!1}){let f=`${o.context.repo.owner}/${o.context.repo.repo}`,w=o.context.ref.replace("refs/heads/",""),b=`changeset-release/${w}`,m=o.getOctokit(a),{preState:y}=await h.default(n);await g.switchToMaybeExistingBranch(b),await g.reset(o.context.sha);let k=await p.getVersionsByDirectory(n);if(e){let[t,...a]=e.split(/\s+/);await s.exec(t,a,{cwd:n})}else{let e=await require(l.default.join(n,"node_modules","@changesets","cli","package.json")),t=u.lt(e.version,"2.0.0")?"bump":"version";await s.exec("node",["./node_modules/@changesets/cli/bin.js",t],{cwd:n})}let v=`repo:${f}+state:open+head:${b}+base:${w}`,O=m.search.issuesAndPullRequests({q:v}),$=await p.getChangedPackages(n,k),P=(async()=>`This PR was opened by the [Changesets release](https://github.com/changesets/action) GitHub action. When you're ready to do a release, you can merge this and ${d?"the packages will be published to npm automatically":"publish to npm yourself or [setup this action to publish automatically](https://github.com/changesets/action#with-publishing)"}. If you're not ready to do a release yet, that's fine, whenever you add more changesets to ${w}, this PR will be updated.\n${y?`\n⚠️⚠️⚠️⚠️⚠️⚠️\n\n\`${w}\` is currently in **pre mode** so this branch has prereleases rather than normal releases. If you want to exit prereleases, run \`changeset pre exit\` on \`${w}\`.\n\n⚠️⚠️⚠️⚠️⚠️⚠️\n`:""}\n# Releases\n`+(await Promise.all($.map(async e=>{let t=await i.default.readFile(l.default.join(e.dir,"CHANGELOG.md"),"utf8"),a=p.getChangelogEntry(t,e.packageJson.version);return{highestLevel:a.highestLevel,private:!!e.packageJson.private,content:`## ${e.packageJson.name}@${e.packageJson.version}\n\n`+a.content}}))).filter(e=>e).sort(p.sortTheThings).map(e=>e.content).join("\n "))();const x=`${r}${y?` (${y.tag})`:""}`,j=`${c}${y?` (${y.tag})`:""}`;await g.commitAll(j),await g.push(b,{force:!0});let J=await O;console.log(JSON.stringify(J.data,null,2)),0===J.data.items.length?(console.log("creating pull request"),await m.pulls.create(t({base:w,head:b,title:x,body:await P},o.context.repo))):(m.pulls.update(t({pull_number:J.data.items[0].number,title:x,body:await P},o.context.repo)),console.log("pull request found"))}exports.runPublish=f,exports.runVersion=w; +"use strict";function e(e,t){var a=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),a.push.apply(a,n)}return a}function t(t){for(var n=1;n{try{let s=l.default.join(a.dir,"CHANGELOG.md"),c=await i.default.readFile(s,"utf8"),u=p.getChangelogEntry(c,a.packageJson.version);if(!u)throw new Error(`Could not find changelog entry for ${a.packageJson.name}@${a.packageJson.version}`);await e.repos.createRelease(t({tag_name:n,body:u.content,prerelease:a.packageJson.version.includes("-")},o.context.repo))}catch(r){if("ENOENT"!==r.code)throw r}};async function f({script:e,githubToken:t,cwd:a=process.cwd()}){let n=o.context.ref.replace("refs/heads/",""),r=o.getOctokit(t),[s,...i]=e.split(/\s+/),l=await p.execWithOutput(s,i,{cwd:a});await g.pullBranch(n),await g.push(n,{includeTags:!0});let{packages:u,tool:h}=await c.getPackages(a),f=[];if("root"!==h){let e=/New tag:\s+(@[^/]+\/[^@]+|[^/]+)@([^\s]+)/,t=new Map(u.map(e=>[e.packageJson.name,e]));for(let a of l.stdout.split("\n")){let n=a.match(e);if(null===n)continue;let r=n[1],s=t.get(r);if(void 0===s)throw new Error(`Package "${r}" not found.`+"This is probably a bug in the action, please open an issue");f.push(s)}await Promise.all(f.map(e=>d(r,{pkg:e,tagName:`${e.packageJson.name}@${e.packageJson.version}`})))}else{if(0===u.length)throw new Error("No package found.This is probably a bug in the action, please open an issue");let e=u[0],t=/New tag:/;for(let a of l.stdout.split("\n")){if(a.match(t)){f.push(e),await d(r,{pkg:e,tagName:`v${e.packageJson.version}`});break}}}return f.length?{published:!0,publishedPackages:f.map(e=>({name:e.packageJson.name,version:e.packageJson.version}))}:{published:!1}}async function w({script:e,githubToken:a,cwd:n=process.cwd(),prTitle:r="Version Packages",commitMessage:c="Version Packages",hasPublishScript:d=!1}){let f=`${o.context.repo.owner}/${o.context.repo.repo}`,w=o.context.ref.replace("refs/heads/",""),b=`changeset-release/${w}`,m=o.getOctokit(a),{preState:y}=await h.default(n);await g.switchToMaybeExistingBranch(b),await g.reset(o.context.sha);let k=await p.getVersionsByDirectory(n);if(e){let[t,...a]=e.split(/\s+/);await s.exec(t,a,{cwd:n})}else{let e=await require(l.default.join(n,"node_modules","@changesets","cli","package.json")),t=u.lt(e.version,"2.0.0")?"bump":"version";await s.exec("node",["./node_modules/@changesets/cli/bin.js",t],{cwd:n})}let v=`repo:${f}+state:open+head:${b}+base:${w}`,O=m.search.issuesAndPullRequests({q:v}),$=await p.getChangedPackages(n,k),P=(async()=>`This PR was opened by the [Changesets release](https://github.com/changesets/action) GitHub action. When you're ready to do a release, you can merge this and ${d?"the packages will be published to npm automatically":"publish to npm yourself or [setup this action to publish automatically](https://github.com/changesets/action#with-publishing)"}. If you're not ready to do a release yet, that's fine, whenever you add more changesets to ${w}, this PR will be updated.\n${y?`\n⚠️⚠️⚠️⚠️⚠️⚠️\n\n\`${w}\` is currently in **pre mode** so this branch has prereleases rather than normal releases. If you want to exit prereleases, run \`changeset pre exit\` on \`${w}\`.\n\n⚠️⚠️⚠️⚠️⚠️⚠️\n`:""}\n# Releases\n`+(await Promise.all($.map(async e=>{let t=await i.default.readFile(l.default.join(e.dir,"CHANGELOG.md"),"utf8"),a=p.getChangelogEntry(t,e.packageJson.version);return{highestLevel:a.highestLevel,private:!!e.packageJson.private,content:`## ${e.packageJson.name}@${e.packageJson.version}\n\n`+a.content}}))).filter(e=>e).sort(p.sortTheThings).map(e=>e.content).join("\n "))();const x=`${r}${y?` (${y.tag})`:""}`,j=`${c}${y?` (${y.tag})`:""}`;await g.commitAll(j),await g.push(b,{force:!0});let J=await O;console.log(JSON.stringify(J.data,null,2)),0===J.data.items.length?(console.log("creating pull request"),await m.pulls.create(t({base:w,head:b,title:x,body:await P},o.context.repo))):(m.pulls.update(t({pull_number:J.data.items[0].number,title:x,body:await P},o.context.repo)),console.log("pull request found"))}exports.runPublish=f,exports.runVersion=w; },{"@actions/exec":"AjbX","@actions/github":"Jpqw","fs-extra":"qdgD","@manypkg/get-packages":"9z3N","semver":"y4rL","./utils":"UnXq","./gitUtils":"pH2w","./readChangesetState":"yOXS"}],"7QCb":[function(require,module,exports) { "use strict";var e=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var s in e)Object.hasOwnProperty.call(e,s)&&(t[s]=e[s]);return t.default=e,t},t=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0});const s=e(require("@actions/core")),i=t(require("fs-extra")),n=e(require("./gitUtils")),r=require("./run"),o=t(require("./readChangesetState")),u=e=>s.getInput(e)||void 0;(async()=>{let e=process.env.GITHUB_TOKEN;if(!e)return void s.setFailed("Please add the GITHUB_TOKEN to the changesets action");s.setOutput("published","false"),s.setOutput("publishedPackages","[]"),console.log("setting git user"),await n.setupUser(),console.log("setting GitHub credentials"),await i.default.writeFile(`${process.env.HOME}/.netrc`,`machine github.com\nlogin github-actions[bot]\npassword ${e}`);let{changesets:t}=await o.default(),a=s.getInput("publish"),l=0!==t.length,c=!!a;switch(!0){case!l&&!c:return void console.log("No changesets found");case!l&&c:{console.log("No changesets found, attempting to publish any unpublished packages to npm");let t=`${process.env.HOME}/.npmrc`;i.default.existsSync(t)?console.log("Found existing .npmrc file"):(console.log("No .npmrc file found, creating one"),i.default.writeFileSync(t,`//registry.npmjs.org/:_authToken=${process.env.NPM_TOKEN}`));const n=await r.runPublish({script:a,githubToken:e});return void(n.published&&(s.setOutput("published","true"),s.setOutput("publishedPackages",JSON.stringify(n.publishedPackages))))}case l:return void(await r.runVersion({script:u("version"),githubToken:e,prTitle:u("title"),commitMessage:u("commit"),hasPublishScript:c}))}})().catch(e=>{console.error(e),s.setFailed(e.message)}); },{"@actions/core":"RNev","fs-extra":"qdgD","./gitUtils":"pH2w","./run":"gwbb","./readChangesetState":"yOXS"}]},{},["7QCb"], null) \ No newline at end of file diff --git a/src/run.ts b/src/run.ts index 57fc299..ec14dab 100644 --- a/src/run.ts +++ b/src/run.ts @@ -119,12 +119,21 @@ export async function runPublish({ "This is probably a bug in the action, please open an issue" ); } - const pkg = packages[0]; - releasedPackages.push(pkg); - await createRelease(octokit, { - pkg, - tagName: `v${pkg.packageJson.version}`, - }); + let pkg = packages[0]; + let newTagRegex = /New tag:/; + + for (let line of changesetPublishOutput.stdout.split("\n")) { + let match = line.match(newTagRegex); + + if (match) { + releasedPackages.push(pkg); + await createRelease(octokit, { + pkg, + tagName: `v${pkg.packageJson.version}`, + }); + break; + } + } } if (releasedPackages.length) {