mirror of
https://github.com/changesets/action
synced 2026-10-26 16:39:56 +08:00
2 lines
2.9 KiB
JavaScript
2 lines
2.9 KiB
JavaScript
import{c as e,d as t,l as n,o as r,s as i,u as a}from"./github-B-FmP-qI.js";import{i as o,n as s,r as c,t as l}from"./run-CVDXZtwd.js";import{r as u}from"./utils-CZUacPOo.js";import{t as d}from"./readChangesetState-Otq6gfkp.js";import f from"node:fs/promises";import"node:path";const p=t=>e(t)||void 0;(async()=>{let m=process.env.GITHUB_TOKEN||e(`github-token`);if(!m){a(`Please add the GITHUB_TOKEN to the changesets action`);return}let h=process.cwd(),g=c(m),_=p(`commitMode`)??`git-cli`,v=p(`prDraft`);if(_!==`git-cli`&&_!==`github-api`){a(`Invalid commit mode: ${_}`);return}if(v!==void 0&&v!==`always`&&v!==`create`){a(`Invalid prDraft: ${v}`);return}let y=new o({octokit:_===`github-api`?g:void 0,cwd:h});i(`setupGitUser`)&&(n(`setting git user`),await y.setupUser()),n(`setting GitHub credentials`),await f.writeFile(`${process.env.HOME}/.netrc`,`machine github.com\nlogin github-actions[bot]\npassword ${m}`);let{changesets:b}=await d(h),x=e(`publish`),S=b.length!==0,C=b.some(e=>e.releases.length>0),w=!!x;switch(t(`published`,`false`),t(`publishedPackages`,`[]`),t(`hasChangesets`,String(S)),!0){case!S&&!w:n(`No changesets present or were removed by merging release PR. Not publishing because no publish script found.`);return;case!S&&w:{if(n(`No changesets found. Attempting to publish any unpublished packages to npm`),process.env.NPM_TOKEN){let e=`${process.env.HOME}/.npmrc`;await u(e)?(n(`Found existing user .npmrc file`),(await f.readFile(e,`utf8`)).split(`
|
|
`).find(e=>/^\s*\/\/registry\.npmjs\.org\/:[_-]authToken=/i.test(e))?n(`Found existing auth token for the npm registry in the user .npmrc file`):(n(`Didn't find existing auth token for the npm registry in the user .npmrc file, creating one`),await f.appendFile(e,`\n//registry.npmjs.org/:_authToken=${process.env.NPM_TOKEN}\n`))):(n(`No user .npmrc file found, creating one with NPM_TOKEN used as auth token`),await f.writeFile(e,`//registry.npmjs.org/:_authToken=${process.env.NPM_TOKEN}\n`))}else process.env.ACTIONS_ID_TOKEN_REQUEST_TOKEN&&process.env.ACTIONS_ID_TOKEN_REQUEST_URL?n(`No NPM_TOKEN found, but OIDC is available - using npm trusted publishing`):n(`No NPM_TOKEN or OIDC available - assuming npm is already authenticated`);let e=await l({script:x,githubToken:m,git:y,octokit:g,createGithubReleases:i(`createGithubReleases`),cwd:h});e.published&&(t(`published`,`true`),t(`publishedPackages`,JSON.stringify(e.publishedPackages))),e.exitCode!==0&&(r(`Publish command exited with code ${e.exitCode}${e.published?`, but some packages were published: ${e.publishedPackages.map(e=>`${e.name}@${e.version}`).join(`, `)}`:``}`),process.exit(e.exitCode));return}case S&&!C:n(`All changesets are empty; not creating PR`);return;case S:{let e=c(m),{pullRequestNumber:n}=await s({script:p(`version`),githubToken:m,git:y,octokit:e,cwd:h,prTitle:p(`title`),commitMessage:p(`commit`),hasPublishScript:w,prDraft:v,branch:p(`branch`)});t(`pullRequestNumber`,String(n));return}}})().catch(e=>{r(e),a(e.message)});export{};
|