diff --git a/dist/index.js b/dist/index.js index a45113a..f2b8db3 100644 --- a/dist/index.js +++ b/dist/index.js @@ -285,5 +285,5 @@ var r;try{r=require("graceful-fs")}catch(s){r=require("fs")}function e(e,n,t){nu },{"universalify":"BgiA","graceful-fs":"X4Hm","../mkdirs":"K9sR","../path-exists":"EriC"}],"JTJ9":[function(require,module,exports) { "use strict";module.exports=Object.assign({},require("./fs"),require("./copy-sync"),require("./copy"),require("./empty"),require("./ensure"),require("./json"),require("./mkdirs"),require("./move-sync"),require("./move"),require("./output"),require("./path-exists"),require("./remove"));const e=require("fs");Object.getOwnPropertyDescriptor(e,"promises")&&Object.defineProperty(module.exports,"promises",{get:()=>e.promises}); },{"./fs":"NeZP","./copy-sync":"7ntm","./copy":"vWuT","./empty":"1Xa3","./ensure":"QssT","./json":"tcuq","./mkdirs":"K9sR","./move-sync":"z7nh","./move":"Vp9L","./output":"jQOt","./path-exists":"EriC","./remove":"0UN6"}],"7QCb":[function(require,module,exports) { -"use strict";function e(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);t&&(o=o.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,o)}return n}function t(t){for(var o=1;o{s+=e.toString()},stderr:e=>{r+=e.toString()}}},o)),stdout:s,stderr:r}}(async()=>{let e=process.env.GITHUB_TOKEN;if(!e)return void r.setFailed("Please add the GITHUB_TOKEN to the changesets action");let n=`${i.context.repo.owner}/${i.context.repo.repo}`;const o=new i.GitHub(e);let s=o.repos.get(i.context.repo).then(e=>e.data.default_branch);console.log("setting git user"),await a.exec("git",["config","--global","user.name",'"github-actions[bot]"']),await a.exec("git",["config","--global","user.email",'"github-actions[bot]@users.noreply.github.com"']),await a.exec("git",["remote","add","gh-https",`https://github.com/${n}`]),console.log("setting GitHub credentials"),await c.default.writeFile(`${process.env.HOME}/.netrc`,`machine github.com\nlogin github-actions[bot]\npassword ${e}`);let u=await s;if(i.context.ref.replace("refs/heads/","")!==u)return void r.setFailed(`The changesets action should only run on ${u} but it's running on ${i.context.ref.replace("refs/heads/","")}, please change your GitHub actions config to only run the Changesets action on ${u}`);let g=c.default.readdirSync(`${process.cwd()}/.changeset`).some(e=>"config.js"!==e&&"README.md"!==e),h=r.getInput("publish");if(!g&&h){console.log("No changesets found, attempting to publish any unpublished packages to npm"),c.default.writeFileSync(`${process.env.HOME}/.npmrc`,`//registry.npmjs.org/:_authToken=${process.env.NPM_TOKEN}`);let[e,...t]=h.split(/\s+/);return await a.exec(e,t),void(await a.exec("git",["push","--follow-tags","gh-https",i.context.ref]))}let{stderr:d}=await l("git",["checkout","changeset-release"],{ignoreReturnCode:!0}),p=!d.toString().includes("Switched to a new branch 'changeset-release'");p&&await a.exec("git",["checkout","-b","changeset-release"]);let f=p;if(!f){console.log("checking if new changesets should be added");const e=(await l("git",["merge-base","changeset-release",i.context.sha])).stdout.trim();f=(await l("git",["diff","--name-only",`${e}...${i.context.sha}`])).stdout.trim().includes(".changeset"),console.log("checked if new changesets should be added "+f)}if(f){await a.exec("git",["reset","--hard",i.context.sha]),await a.exec("yarn",["changeset","bump"]),await a.exec("git",["add","."]),await a.exec("git",["commit","-m","Version Packages"]),await a.exec("git",["push","gh-https","changeset-release","--force"]);let e=`repo:${n}+state:open+head:changeset-release+base:${u}`,s=await o.search.issuesAndPullRequests({q:e});console.log(JSON.stringify(s.data,null,2)),0===s.data.items.length?(console.log("creating pull request"),await o.pulls.create(t({base:u,head:"changeset-release",title:"Version Packages"},i.context.repo))):console.log("pull request found")}else console.log("no new changesets")})().catch(e=>{console.error(e),r.setFailed(e.message)}); +"use strict";function e(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);t&&(o=o.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,o)}return n}function t(t){for(var o=1;o{r+=e.toString()},stderr:e=>{s+=e.toString()}}},o)),stdout:r,stderr:s}}(async()=>{let e=process.env.GITHUB_TOKEN;if(!e)return void s.setFailed("Please add the GITHUB_TOKEN to the changesets action");let n=`${i.context.repo.owner}/${i.context.repo.repo}`;const o=new i.GitHub(e);let r=o.repos.get(i.context.repo).then(e=>e.data.default_branch);console.log("setting git user"),await a.exec("git",["config","--global","user.name",'"github-actions[bot]"']),await a.exec("git",["config","--global","user.email",'"github-actions[bot]@users.noreply.github.com"']),console.log("setting GitHub credentials"),await c.default.writeFile(`${process.env.HOME}/.netrc`,`machine github.com\nlogin github-actions[bot]\npassword ${e}`);let u=await r;if(i.context.ref.replace("refs/heads/","")!==u)return void s.setFailed(`The changesets action should only run on ${u} but it's running on ${i.context.ref.replace("refs/heads/","")}, please change your GitHub actions config to only run the Changesets action on ${u}`);let g=c.default.readdirSync(`${process.cwd()}/.changeset`).some(e=>"config.js"!==e&&"README.md"!==e),h=s.getInput("publish");if(!g&&h){console.log("No changesets found, attempting to publish any unpublished packages to npm"),c.default.writeFileSync(`${process.env.HOME}/.npmrc`,`//registry.npmjs.org/:_authToken=${process.env.NPM_TOKEN}`);let[e,...t]=h.split(/\s+/);return await a.exec(e,t),void(await a.exec("git",["push","--follow-tags"]))}let{stderr:d}=await l("git",["checkout","changeset-release"],{ignoreReturnCode:!0}),p=!d.toString().includes("Switched to a new branch 'changeset-release'");p&&await a.exec("git",["checkout","-b","changeset-release"]);let f=p;if(!f){console.log("checking if new changesets should be added");const e=(await l("git",["merge-base","changeset-release",i.context.sha])).stdout.trim();f=(await l("git",["diff","--name-only",`${e}...${i.context.sha}`])).stdout.trim().includes(".changeset"),console.log("checked if new changesets should be added "+f)}if(f){await a.exec("git",["reset","--hard",i.context.sha]),await a.exec("yarn",["changeset","bump"]),await a.exec("git",["add","."]),await a.exec("git",["commit","-m","Version Packages"]),await a.exec("git",["push","origin","changeset-release","--force"]);let e=`repo:${n}+state:open+head:changeset-release+base:${u}`,r=await o.search.issuesAndPullRequests({q:e});console.log(JSON.stringify(r.data,null,2)),0===r.data.items.length?(console.log("creating pull request"),await o.pulls.create(t({base:u,head:"changeset-release",title:"Version Packages"},i.context.repo))):console.log("pull request found")}else console.log("no new changesets")})().catch(e=>{console.error(e),s.setFailed(e.message)}); },{"@actions/core":"4FTV","@actions/exec":"utFe","@actions/github":"8Dol","fs-extra":"JTJ9"}]},{},["7QCb"], null) \ No newline at end of file diff --git a/index.ts b/index.ts index 36f6357..14b6200 100644 --- a/index.ts +++ b/index.ts @@ -58,13 +58,6 @@ async function execWithOutput( `"github-actions[bot]@users.noreply.github.com"` ]); - await exec("git", [ - "remote", - "add", - "gh-https", - `https://github.com/${repo}` - ]); - console.log("setting GitHub credentials"); await fs.writeFile( `${process.env.HOME}/.netrc`, @@ -99,12 +92,7 @@ async function execWithOutput( await exec(publishCommand, publishArgs); - await exec("git", [ - "push", - "--follow-tags", - "gh-https", - github.context.ref - ]); + await exec("git", ["push", "--follow-tags"]); return; } @@ -146,7 +134,7 @@ async function execWithOutput( await exec("yarn", ["changeset", "bump"]); await exec("git", ["add", "."]); await exec("git", ["commit", "-m", "Version Packages"]); - await exec("git", ["push", "gh-https", "changeset-release", "--force"]); + await exec("git", ["push", "origin", "changeset-release", "--force"]); let searchQuery = `repo:${repo}+state:open+head:changeset-release+base:${defaultBranch}`; let searchResult = await octokit.search.issuesAndPullRequests({ q: searchQuery