From 99bc8238f9b3a7158136f4af59609cd5b39e4856 Mon Sep 17 00:00:00 2001 From: mitchellhamilton Date: Wed, 14 Aug 2019 21:19:49 +1000 Subject: [PATCH] Try again --- dist/index.js | 2 +- index.ts | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/dist/index.js b/dist/index.js index f3b1e1b..28aaa0d 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 r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,r)}return n}function t(t){for(var r=1;r{o+=e.toString()},stderr:e=>{s+=e.toString()}}},r)),stdout:o,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 r=new i.GitHub(e);let o=r.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 o;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","gh-https",u]))}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.ref])).stdout.trim();f=(await l("git",["diff","--name-only",`${e}...${i.context.ref}`])).stdout.trim().includes(".changeset"),console.log("checked if new changesets should be added "+f)}if(f){await a.exec("git",["reset","--hard",i.context.ref]),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}`,o=await r.search.issuesAndPullRequests({q:e});console.log(JSON.stringify(o.data,null,2)),0===o.data.items.length?(console.log("creating pull request"),await r.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)}); +"use strict";function e(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var s=Object.getOwnPropertySymbols(e);t&&(s=s.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,s)}return n}function t(t){for(var s=1;s{o+=e.toString()},stderr:e=>{r+=e.toString()}}},s)),stdout:o,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 s=new i.GitHub(e);let o=s.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 o;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",u]))}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}`,o=await s.search.issuesAndPullRequests({q:e});console.log(JSON.stringify(o.data,null,2)),0===o.data.items.length?(console.log("creating pull request"),await s.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)}); },{"@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 324497c..d8a91eb 100644 --- a/index.ts +++ b/index.ts @@ -123,21 +123,21 @@ async function execWithOutput( let cmd = await execWithOutput("git", [ "merge-base", "changeset-release", - github.context.ref + github.context.sha ]); const divergedAt = cmd.stdout.trim(); let diffOutput = await execWithOutput("git", [ "diff", "--name-only", - `${divergedAt}...${github.context.ref}` + `${divergedAt}...${github.context.sha}` ]); const files = diffOutput.stdout.trim(); shouldBump = files.includes(".changeset"); console.log("checked if new changesets should be added " + shouldBump); } if (shouldBump) { - await exec("git", ["reset", "--hard", github.context.ref]); + await exec("git", ["reset", "--hard", github.context.sha]); await exec("yarn", ["changeset", "bump"]); await exec("git", ["add", "."]); await exec("git", ["commit", "-m", "Version Packages"]);