From fd6b0637710f5f50e81c2f68ee661597deb859d3 Mon Sep 17 00:00:00 2001 From: mitchellhamilton Date: Wed, 14 Aug 2019 20:53:44 +1000 Subject: [PATCH] Try another thing --- dist/index.js | 2 +- index.ts | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/dist/index.js b/dist/index.js index f8c9891..1733482 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 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{n+=e.toString()},stderr:e=>{s+=e.toString()}}};return{code:await o.exec(e,t,r),stdout:n,stderr:s}}(async()=>{let e=process.env.GITHUB_TOKEN;if(!e)return void a.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 r=s.repos.get(i.context.repo).then(e=>e.data.default_branch);console.log("setting git user"),await o.exec("git",["config","--global","user.name",'"github-actions[bot]"']),await o.exec("git",["config","--global","user.email",'"github-actions[bot]@users.noreply.github.com"']),await o.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 r;if(i.context.ref!==u)return void a.setFailed(`The changesets action should only run on ${u} but it's running on ${i.context.ref}, 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=a.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 o.exec(e,t),void(await o.exec("git",["push","--follow-tags","gh-https","master"]))}let{stderr:d}=await l("git",["checkout","changeset-release"]),p=!d.toString().includes("Switched to a new branch 'changeset-release'");p&&await o.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","master"])).stdout.trim();f=(await l("git",["diff","--name-only",`${e}...master`])).stdout.trim().includes(".changeset"),console.log("checked if new changesets should be added "+f)}if(f){await o.exec("git",["reset","--hard","master"]),await o.exec("yarn",["changeset","bump"]),await o.exec("git",["add","."]),await o.exec("git",["commit","-m","Version Packages"]),await o.exec("git",["push","gh-https","changeset-release","--force"]);let e=`repo:${n}+state:open+head:changeset-release+base:master`,r=await s.search.issuesAndPullRequests({q:e});console.log(JSON.stringify(r.data,null,2)),0===r.data.items.length?(console.log("creating pull request"),await s.pulls.create(t({base:"master",head:"changeset-release",title:"Version Packages"},i.context.repo))):console.log("pull request found")}else console.log("no new changesets")})(); +"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{n+=e.toString()},stderr:e=>{s+=e.toString()}}};return{code:await o.exec(e,t,r),stdout:n,stderr:s}}(async()=>{let e=process.env.GITHUB_TOKEN;if(!e)return void a.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 r=s.repos.get(i.context.repo).then(e=>e.data.default_branch);console.log("setting git user"),await o.exec("git",["config","--global","user.name",'"github-actions[bot]"']),await o.exec("git",["config","--global","user.email",'"github-actions[bot]@users.noreply.github.com"']),await o.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 r;if(i.context.ref.replace("refs/heads/","")!==u)return void a.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=a.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 o.exec(e,t),void(await o.exec("git",["push","--follow-tags","gh-https","master"]))}let{stderr:d}=await l("git",["checkout","changeset-release"]),p=!d.toString().includes("Switched to a new branch 'changeset-release'");p&&await o.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","master"])).stdout.trim();f=(await l("git",["diff","--name-only",`${e}...master`])).stdout.trim().includes(".changeset"),console.log("checked if new changesets should be added "+f)}if(f){await o.exec("git",["reset","--hard","master"]),await o.exec("yarn",["changeset","bump"]),await o.exec("git",["add","."]),await o.exec("git",["commit","-m","Version Packages"]),await o.exec("git",["push","gh-https","changeset-release","--force"]);let e=`repo:${n}+state:open+head:changeset-release+base:master`,r=await s.search.issuesAndPullRequests({q:e});console.log(JSON.stringify(r.data,null,2)),0===r.data.items.length?(console.log("creating pull request"),await s.pulls.create(t({base:"master",head:"changeset-release",title:"Version Packages"},i.context.repo))):console.log("pull request found")}else console.log("no new changesets")})(); },{"@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 4c9f0d8..deee4ca 100644 --- a/index.ts +++ b/index.ts @@ -67,11 +67,12 @@ async function execWithOutput(command: string, args?: string[]) { ); let defaultBranch = await defaultBranchPromise; - if (github.context.ref !== defaultBranch) { + if (github.context.ref.replace("refs/heads/", "") !== defaultBranch) { core.setFailed( - `The changesets action should only run on ${defaultBranch} but it's running on ${ - github.context.ref - }, please change your GitHub actions config to only run the Changesets action on ${defaultBranch}` + `The changesets action should only run on ${defaultBranch} but it's running on ${github.context.ref.replace( + "refs/heads/", + "" + )}, please change your GitHub actions config to only run the Changesets action on ${defaultBranch}` ); return; }