@tarsilla/commit-wizard 1.4.8 → 1.4.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,2 +1,2 @@
1
- import e from"crypto";import t from"fs";import{Octokit as a}from"@octokit/rest";import{analyzeCommits as r}from"@semantic-release/commit-analyzer";import{generateNotes as o}from"@semantic-release/release-notes-generator";const n={preset:"conventionalcommits",parserOpts:{headerPattern:RegExp("^(?<type>\\w+)(?<exclamation1>!?)(?:\\((?<scope>[^)]+)\\)(?<exclamation2>!?))?: (?<subject>.+)$"),headerCorrespondence:["type","exclamation1","scope","exclamation2","subject"]},releaseRules:[{type:"feat",exclamation1:"!",release:"major"},{type:"feat",exclamation2:"!",release:"major"},{type:"feat",release:"minor"},{type:"fix",release:"patch"},{type:"docs",release:"patch"},{type:"style",release:"patch"},{type:"refactor",release:"patch"},{type:"perf",release:"patch"},{type:"test",release:"patch"},{type:"build",release:"patch"},{type:"ci",release:"patch"},{type:"chore",release:"patch"},{type:"revert",release:"patch"}]};let s=!1;function i(e,t){const a=new URL(t).pathname,r=(a.startsWith("/")?a.slice(1):a).split("/").pop();return e.tap??`${r}.rb`}async function c(a,r){const{nextRelease:o,logger:n,options:s}=r;if(!o?.version)throw new Error("Next release version is not available.");const c=`v${o.version}`,l=s.repositoryUrl,p=new URL(l).pathname,h=`https://codeload.github.com/${p.startsWith("/")?p.slice(1):p}/tar.gz/refs/tags/${c}`,m=await async function(t,a){const{logger:r}=a;r.log(`Calculating SHA256 for URL: ${t}`);const o=await fetch(t);if(!o.ok)throw new Error(`Failed to fetch file. Status Code: ${o.status}`);if(!o.body)throw new Error("Response body is null.");const n=e.createHash("sha256"),s=o.body.getReader();return new Promise(((e,t)=>{!function a(){s.read().then((({done:t,value:r})=>{t?e(n.digest("hex")):(r&&n.update(r),a())})).catch(t)}()}))}(h,r),f=i(a,l);let u=t.readFileSync(f,"utf8");u=u.replace(/url ".*"/,`url "${h}"`),u=u.replace(/sha256 ".*"/,`sha256 "${m}"`),t.writeFileSync(f,u),n.log(`Updated formula with version ${c}, URL ${h}, and SHA256 ${m}`)}async function l(e,t){s=!0}const p={addChannel:async function(e,t){},verifyConditions:l,analyzeCommits:async function(e,t){return s||(await l(),s=!0),r(n,t)},generateNotes:async function(e,t){return s||(await l(),s=!0),o({},t)},prepare:async function(e,t){},publish:async function(e,r){return s||(await l(),s=!0),await c(e,r),await async function(e,r){if(!process.env.GITHUB_TOKEN)throw new Error("GITHUB_TOKEN is not set in the environment.");const{nextRelease:o,logger:n,options:s}=r,c=s.repositoryUrl,[l,p]=new URL(c).pathname.slice(1).split("/"),h=i(e,c),m=s.branch??"main";n.log(`Committing updated formula file ${h} to branch ${m}...`);const f=new a({auth:process.env.GITHUB_TOKEN});try{const{data:e}=await f.repos.getBranch({owner:l,repo:p,branch:m}),a=e.commit.sha,r=e.commit.commit.tree.sha;n.log(`Latest commit SHA: ${a}`),n.log(`Base tree SHA: ${r}`);const s=t.readFileSync(h,"utf8"),{data:i}=await f.git.createBlob({owner:l,repo:p,content:s,encoding:"utf-8"});n.log(`Created blob for ${h} with SHA: ${i.sha}`);const{data:c}=await f.git.createTree({owner:l,repo:p,base_tree:r,tree:[{path:h,mode:"100644",type:"blob",sha:i.sha}]});n.log(`Created new tree with SHA: ${c.sha}`);const u=`chore(release): ${o.version}`,{data:d}=await f.git.createCommit({owner:l,repo:p,message:u,tree:c.sha,parents:[a]});n.log(`Created new commit with SHA: ${d.sha}`),await f.git.updateRef({owner:l,repo:p,ref:`heads/${m}`,sha:d.sha}),n.log(`Branch ${m} updated to commit ${d.sha}`)}catch(e){throw n.error(`Failed to commit formula file: ${e.message}`),e}}(e,r),null},success:async function(e,t){},fail:async function(e,t){}};export{p as default};
1
+ import{execSync as e}from"child_process";import a from"crypto";import t from"fs";import{analyzeCommits as s}from"@semantic-release/commit-analyzer";import{prepare as r,verifyConditions as n}from"@semantic-release/git";import{addChannel as i,fail as o,publish as c,success as l,verifyConditions as p}from"@semantic-release/github";import{generateNotes as m}from"@semantic-release/release-notes-generator";const f="nextTag-stable.tar.gz",y={preset:"conventionalcommits",parserOpts:{headerPattern:RegExp("^(?<type>\\w+)(?<exclamation1>!?)(?:\\((?<scope>[^)]+)\\)(?<exclamation2>!?))?: (?<subject>.+)$"),headerCorrespondence:["type","exclamation1","scope","exclamation2","subject"]},releaseRules:[{type:"feat",exclamation1:"!",release:"major"},{type:"feat",exclamation2:"!",release:"major"},{type:"feat",release:"minor"},{type:"fix",release:"patch"},{type:"docs",release:"patch"},{type:"style",release:"patch"},{type:"refactor",release:"patch"},{type:"perf",release:"patch"},{type:"test",release:"patch"},{type:"build",release:"patch"},{type:"ci",release:"patch"},{type:"chore",release:"patch"},{type:"revert",release:"patch"}]};let u=!1;function h(e,a){const{options:t}=a,s=t.repositoryUrl,r=new URL(s).pathname,n=(r.startsWith("/")?r.slice(1):r).split("/").pop();return e.tap??`${n}.rb`}async function w(e,s){const{nextRelease:r,options:n}=s,i=`v${r.version}`,o=n.repositoryUrl,c=new URL(o).pathname,l=`https://github.com/${c.startsWith("/")?c.slice(1):c}/releases/download/${i}/${f.replace("nextTag",i)}`,p=function(e,s){const{nextRelease:r}=s,n=`v${r.version}`,i=f.replace("nextTag",n),o=t.readFileSync(i),c=a.createHash("sha256");return c.update(o),c.digest("hex")}(0,s),m=h(e,s);let y=t.readFileSync(m,"utf8");y=y.replace(/url ".*"/,`url "${l}"`),y=y.replace(/sha256 ".*"/,`sha256 "${p}"`),t.writeFileSync(m,y)}async function x(e,a){p&&await p(e,a),n&&await n(e,a),u=!0}const d={addChannel:async function(e,a){u||(await x(e,a),u=!0),i&&await i(e,a)},verifyConditions:x,analyzeCommits:async function(e,a){return u||(await x(e,a),u=!0),s(y,a)},generateNotes:async function(e,a){return u||(await x(e,a),u=!0),m({},a)},prepare:async function(a,t){if(u||(await x(a,t),u=!0),r){const{nextRelease:s}=t;if(!s?.version)throw new Error("Next release version is not available.");const n=h(a,t);!function(a,t){const{nextRelease:s}=t,r=`v${s.version}`,n=f.replace("nextTag",r);e(`git archive --format=tar.gz --output=${n} HEAD`)}(0,t),await w(a,t),await r({assets:[n],message:"chore(release): ${nextRelease.version}"},t)}},publish:async function(e,a){if(u||(await x(e,a),u=!0),c){const{nextRelease:t}=a,s=`v${t.version}`,r=f.replace("nextTag",s),n={...e,assets:[{path:r,label:`Homebrew Tarball (${s})`}]};await c(n,a)}return null},success:async function(e,a){u||(await x(e,a),u=!0),l&&await l(e,a)},fail:async function(e,a){o&&await r(e,a)}};export{d as default};
2
2
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","sources":["../../../src/semantic-release/brew/index.ts"],"sourcesContent":["import crypto from 'crypto';\nimport fs from 'fs';\n\nimport { Octokit } from '@octokit/rest';\n//@ts-ignore\nimport { analyzeCommits as commitAnalyzerAnalyzeCommits } from '@semantic-release/commit-analyzer';\n//@ts-ignore\nimport { generateNotes as notesGeneratorGenerateNotes } from '@semantic-release/release-notes-generator';\nimport {\n AddChannelContext,\n AnalyzeCommitsContext,\n FailContext,\n GenerateNotesContext,\n PrepareContext,\n PublishContext,\n SuccessContext,\n VerifyConditionsContext,\n} from 'semantic-release';\n\nimport { SemanticReleasePlugin } from '../types.js';\n\nconst analyzerConfig = {\n preset: 'conventionalcommits',\n parserOpts: {\n headerPattern: /^(?<type>\\w+)(?<exclamation1>!?)(?:\\((?<scope>[^)]+)\\)(?<exclamation2>!?))?: (?<subject>.+)$/,\n headerCorrespondence: ['type', 'exclamation1', 'scope', 'exclamation2', 'subject'],\n },\n releaseRules: [\n { type: 'feat', exclamation1: '!', release: 'major' },\n { type: 'feat', exclamation2: '!', release: 'major' },\n { type: 'feat', release: 'minor' },\n { type: 'fix', release: 'patch' },\n { type: 'docs', release: 'patch' },\n { type: 'style', release: 'patch' },\n { type: 'refactor', release: 'patch' },\n { type: 'perf', release: 'patch' },\n { type: 'test', release: 'patch' },\n { type: 'build', release: 'patch' },\n { type: 'ci', release: 'patch' },\n { type: 'chore', release: 'patch' },\n { type: 'revert', release: 'patch' },\n ],\n};\n\ntype PluginConfig = { tap?: string };\n\nlet verified = false;\n\nfunction getFormulaFile(pluginConfig: PluginConfig, repositoryUrl: string): string {\n const url = new URL(repositoryUrl);\n const repositoryPath = url.pathname;\n const repository = repositoryPath.startsWith('/') ? repositoryPath.slice(1) : repositoryPath;\n const project = repository.split('/').pop();\n\n return pluginConfig.tap ?? `${project}.rb`;\n}\n\nasync function commitFormulaFile(pluginConfig: PluginConfig, context: PrepareContext): Promise<void> {\n if (!process.env.GITHUB_TOKEN) {\n throw new Error('GITHUB_TOKEN is not set in the environment.');\n }\n\n const { nextRelease, logger, options } = context;\n\n const repositoryUrl = options.repositoryUrl!; // Guaranteed to be defined by semantic-release\n const [owner, repo] = new URL(repositoryUrl).pathname.slice(1).split('/');\n\n const formulaFile = getFormulaFile(pluginConfig, repositoryUrl);\n const branchName = options.branch ?? 'main';\n\n logger.log(`Committing updated formula file ${formulaFile} to branch ${branchName}...`);\n\n const octokit = new Octokit({\n auth: process.env.GITHUB_TOKEN,\n });\n\n try {\n // Get the latest commit SHA and tree SHA from the branch\n const { data: branch } = await octokit.repos.getBranch({\n owner,\n repo,\n branch: branchName,\n });\n\n const latestCommitSha = branch.commit.sha;\n const baseTreeSha = branch.commit.commit.tree.sha;\n\n logger.log(`Latest commit SHA: ${latestCommitSha}`);\n logger.log(`Base tree SHA: ${baseTreeSha}`);\n\n // Read the updated formula file content\n const formulaContent = fs.readFileSync(formulaFile, 'utf8');\n\n // Create a new blob for the updated formula file\n const { data: blob } = await octokit.git.createBlob({\n owner,\n repo,\n content: formulaContent,\n encoding: 'utf-8',\n });\n\n logger.log(`Created blob for ${formulaFile} with SHA: ${blob.sha}`);\n\n // Create a new tree with the updated formula file\n const { data: newTree } = await octokit.git.createTree({\n owner,\n repo,\n base_tree: baseTreeSha,\n tree: [\n {\n path: formulaFile,\n mode: '100644',\n type: 'blob',\n sha: blob.sha,\n },\n ],\n });\n\n logger.log(`Created new tree with SHA: ${newTree.sha}`);\n\n // Create a new commit with the updated tree\n const commitMessage = `chore(release): ${nextRelease.version}`;\n const { data: newCommit } = await octokit.git.createCommit({\n owner,\n repo,\n message: commitMessage,\n tree: newTree.sha,\n parents: [latestCommitSha],\n });\n\n logger.log(`Created new commit with SHA: ${newCommit.sha}`);\n\n // Update the branch reference to point to the new commit\n await octokit.git.updateRef({\n owner,\n repo,\n ref: `heads/${branchName}`,\n sha: newCommit.sha,\n });\n\n logger.log(`Branch ${branchName} updated to commit ${newCommit.sha}`);\n } catch (error) {\n logger.error(`Failed to commit formula file: ${(error as Error).message}`);\n throw error;\n }\n}\n\nasync function calculateSha256(url: string, context: PrepareContext): Promise<string> {\n const { logger } = context;\n\n logger.log(`Calculating SHA256 for URL: ${url}`);\n\n const response = await fetch(url);\n\n if (!response.ok) {\n throw new Error(`Failed to fetch file. Status Code: ${response.status}`);\n }\n\n if (!response.body) {\n throw new Error('Response body is null.');\n }\n\n const hash = crypto.createHash('sha256');\n const reader = response.body.getReader();\n\n return new Promise((resolve, reject) => {\n function read() {\n reader\n .read()\n .then(({ done, value }) => {\n if (done) {\n resolve(hash.digest('hex'));\n return;\n }\n if (value) {\n hash.update(value);\n }\n read();\n })\n .catch(reject);\n }\n read();\n });\n}\n\nasync function updateFormulaFile(pluginConfig: PluginConfig, context: PrepareContext): Promise<void> {\n const { nextRelease, logger, options } = context;\n\n if (!nextRelease?.version) {\n throw new Error('Next release version is not available.');\n }\n\n const tagName = `v${nextRelease.version}`;\n\n const repositoryUrl = options.repositoryUrl!; // Guaranteed to be defined by semantic-release\n const url = new URL(repositoryUrl);\n const repositoryPath = url.pathname;\n const repository = repositoryPath.startsWith('/') ? repositoryPath.slice(1) : repositoryPath;\n\n const tarUrl = `https://codeload.github.com/${repository}/tar.gz/refs/tags/${tagName}`;\n const sha256 = await calculateSha256(tarUrl, context);\n const formulaFile = getFormulaFile(pluginConfig, repositoryUrl);\n\n let formulaContent = fs.readFileSync(formulaFile, 'utf8');\n formulaContent = formulaContent.replace(/url \".*\"/, `url \"${tarUrl}\"`);\n formulaContent = formulaContent.replace(/sha256 \".*\"/, `sha256 \"${sha256}\"`);\n fs.writeFileSync(formulaFile, formulaContent);\n\n logger.log(`Updated formula with version ${tagName}, URL ${tarUrl}, and SHA256 ${sha256}`);\n}\n\nasync function addChannel(_pluginConfig: PluginConfig, _context: AddChannelContext): Promise<void> {\n //do nothing\n}\n\nasync function analyzeCommits(pluginConfig: PluginConfig, context: AnalyzeCommitsContext): Promise<string | false> {\n if (!verified) {\n await verifyConditions(pluginConfig, context);\n verified = true;\n }\n\n return commitAnalyzerAnalyzeCommits(analyzerConfig, context);\n}\n\nasync function fail(_pluginConfig: PluginConfig, _context: FailContext): Promise<void> {\n //do nothing\n}\n\nasync function generateNotes(pluginConfig: PluginConfig, context: GenerateNotesContext): Promise<string> {\n if (!verified) {\n await verifyConditions(pluginConfig, context);\n verified = true;\n }\n\n return notesGeneratorGenerateNotes({}, context);\n}\n\nasync function prepare(_pluginConfig: PluginConfig, _context: PrepareContext): Promise<void> {\n //do nothing\n}\n\nasync function publish(pluginConfig: PluginConfig, context: PublishContext): Promise<unknown> {\n if (!verified) {\n await verifyConditions(pluginConfig, context);\n verified = true;\n }\n\n await updateFormulaFile(pluginConfig, context);\n\n await commitFormulaFile(pluginConfig, context);\n\n return null;\n}\n\nasync function success(_pluginConfig: PluginConfig, _context: SuccessContext): Promise<void> {\n //do nothing\n}\n\nasync function verifyConditions(_pluginConfig: PluginConfig, _context: VerifyConditionsContext): Promise<void> {\n verified = true;\n}\n\nconst plugin: SemanticReleasePlugin<{ tap: string }> = {\n addChannel,\n verifyConditions,\n analyzeCommits,\n generateNotes,\n prepare,\n publish,\n success,\n fail,\n};\n\nexport default plugin;\n"],"names":["analyzerConfig","preset","parserOpts","headerPattern","RegExp","headerCorrespondence","releaseRules","type","exclamation1","release","exclamation2","verified","getFormulaFile","pluginConfig","repositoryUrl","repositoryPath","URL","pathname","project","startsWith","slice","split","pop","tap","async","updateFormulaFile","context","nextRelease","logger","options","version","Error","tagName","tarUrl","sha256","url","log","response","fetch","ok","status","body","hash","crypto","createHash","reader","getReader","Promise","resolve","reject","read","then","done","value","digest","update","catch","calculateSha256","formulaFile","formulaContent","fs","readFileSync","replace","writeFileSync","verifyConditions","_pluginConfig","_context","plugin","addChannel","analyzeCommits","commitAnalyzerAnalyzeCommits","generateNotes","notesGeneratorGenerateNotes","prepare","publish","process","env","GITHUB_TOKEN","owner","repo","branchName","branch","octokit","Octokit","auth","data","repos","getBranch","latestCommitSha","commit","sha","baseTreeSha","tree","blob","git","createBlob","content","encoding","newTree","createTree","base_tree","path","mode","commitMessage","newCommit","createCommit","message","parents","updateRef","ref","error","commitFormulaFile","success","fail"],"mappings":"6NAqBA,MAAMA,EAAiB,CACrBC,OAAQ,sBACRC,WAAY,CACVC,cAAeC,OAAA,mGACfC,qBAAsB,CAAC,OAAQ,eAAgB,QAAS,eAAgB,YAE1EC,aAAc,CACZ,CAAEC,KAAM,OAAQC,aAAc,IAAKC,QAAS,SAC5C,CAAEF,KAAM,OAAQG,aAAc,IAAKD,QAAS,SAC5C,CAAEF,KAAM,OAAQE,QAAS,SACzB,CAAEF,KAAM,MAAOE,QAAS,SACxB,CAAEF,KAAM,OAAQE,QAAS,SACzB,CAAEF,KAAM,QAASE,QAAS,SAC1B,CAAEF,KAAM,WAAYE,QAAS,SAC7B,CAAEF,KAAM,OAAQE,QAAS,SACzB,CAAEF,KAAM,OAAQE,QAAS,SACzB,CAAEF,KAAM,QAASE,QAAS,SAC1B,CAAEF,KAAM,KAAME,QAAS,SACvB,CAAEF,KAAM,QAASE,QAAS,SAC1B,CAAEF,KAAM,SAAUE,QAAS,WAM/B,IAAIE,GAAW,EAEf,SAASC,EAAeC,EAA4BC,GAClD,MACMC,EADM,IAAIC,IAAIF,GACOG,SAErBC,GADaH,EAAeI,WAAW,KAAOJ,EAAeK,MAAM,GAAKL,GAC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Ma,SAAkBhB,EAAQY,IAAIK,WAAW,CACrDrB,QACAC,OACAqB,UAAWT,EACXC,KAAM,CACJ,CACES,KAAM3C,EACN4C,KAAM,SACN/F,KAAM,OACNmF,IAAKG,EAAKH,QAKhB9D,EAAOQ,IAAI,8BAA8B8D,EAAQR,OAGjD,MAAMa,EAAgB,mBAAmB5E,EAAYG,WAC7CuD,KAAMmB,SAAoBtB,EAAQY,IAAIW,aAAa,CACzD3B,QACAC,OACA2B,QAASH,EACTX,KAAMM,EAAQR,IACdiB,QAAS,CAACnB,KAGZ5D,EAAOQ,IAAI,gCAAgCoE,EAAUd,aAG/CR,EAAQY,IAAIc,UAAU,CAC1B9B,QACAC,OACA8B,IAAK,SAAS7B,IACdU,IAAKc,EAAUd,MAGjB9D,EAAOQ,IAAI,UAAU4C,uBAAgCwB,EAAUd,MACjE,CAAE,MAAOoB,GAEP,MADAlF,EAAOkF,MAAM,kCAAkCA,EAAiBJ,WAC1DI,CACR,CACF,CAwGQC,CAAkBlG,EAAca,GAE/B,IACT,EAiBEsF,QAfFxF,eAAuByC,EAA6BC,GAEpD,EAcE+C,KA9CFzF,eAAoByC,EAA6BC,GAEjD"}
1
+ {"version":3,"file":"index.mjs","sources":["../../../src/semantic-release/brew/index.ts"],"sourcesContent":["import { execSync } from 'child_process';\nimport crypto from 'crypto';\nimport fs from 'fs';\n\n//@ts-ignore\nimport { analyzeCommits as commitAnalyzerAnalyzeCommits } from '@semantic-release/commit-analyzer';\nimport {\n prepare as gitPrepare,\n verifyConditions as gitVerifyConditions,\n //@ts-ignore\n} from '@semantic-release/git';\nimport {\n addChannel as gitHubAddChanel,\n fail as gitHubFail,\n publish as gitHubPublish,\n success as gitHubSuccess,\n verifyConditions as gitHubVerifyConditions,\n //@ts-ignore\n} from '@semantic-release/github';\n//@ts-ignore\nimport { generateNotes as notesGeneratorGenerateNotes } from '@semantic-release/release-notes-generator';\nimport {\n AddChannelContext,\n AnalyzeCommitsContext,\n FailContext,\n GenerateNotesContext,\n PrepareContext,\n PublishContext,\n SuccessContext,\n VerifyConditionsContext,\n} from 'semantic-release';\n\nimport { SemanticReleasePlugin } from '../types.js';\n\nconst tarballFile = 'nextTag-stable.tar.gz';\n\nconst analyzerConfig = {\n preset: 'conventionalcommits',\n parserOpts: {\n headerPattern: /^(?<type>\\w+)(?<exclamation1>!?)(?:\\((?<scope>[^)]+)\\)(?<exclamation2>!?))?: (?<subject>.+)$/,\n headerCorrespondence: ['type', 'exclamation1', 'scope', 'exclamation2', 'subject'],\n },\n releaseRules: [\n { type: 'feat', exclamation1: '!', release: 'major' },\n { type: 'feat', exclamation2: '!', release: 'major' },\n { type: 'feat', release: 'minor' },\n { type: 'fix', release: 'patch' },\n { type: 'docs', release: 'patch' },\n { type: 'style', release: 'patch' },\n { type: 'refactor', release: 'patch' },\n { type: 'perf', release: 'patch' },\n { type: 'test', release: 'patch' },\n { type: 'build', release: 'patch' },\n { type: 'ci', release: 'patch' },\n { type: 'chore', release: 'patch' },\n { type: 'revert', release: 'patch' },\n ],\n};\n\ntype PluginConfig = { tap?: string };\n\nlet verified = false;\n\nfunction getFormulaFile(pluginConfig: PluginConfig, context: PrepareContext): string {\n const { options } = context;\n const repositoryUrl = options.repositoryUrl!;\n const url = new URL(repositoryUrl);\n const repositoryPath = url.pathname;\n const repository = repositoryPath.startsWith('/') ? repositoryPath.slice(1) : repositoryPath;\n const project = repository.split('/').pop();\n\n return pluginConfig.tap ?? `${project}.rb`;\n}\n\nfunction generateTarball(_pluginConfig: PluginConfig, context: PrepareContext) {\n const { nextRelease } = context;\n\n const nextTag = `v${nextRelease.version}`;\n const tarFilePath = tarballFile.replace('nextTag', nextTag);\n\n execSync(`git archive --format=tar.gz --output=${tarFilePath} HEAD`);\n}\n\nfunction calculateSha256(_pluginConfig: PluginConfig, context: PrepareContext) {\n const { nextRelease } = context;\n\n const nextTag = `v${nextRelease.version}`;\n const tarFilePath = tarballFile.replace('nextTag', nextTag);\n\n const fileBuffer = fs.readFileSync(tarFilePath);\n const hash = crypto.createHash('sha256');\n hash.update(fileBuffer);\n\n return hash.digest('hex');\n}\n\nasync function updateFormulaFile(pluginConfig: PluginConfig, context: PrepareContext): Promise<void> {\n const { nextRelease, options } = context;\n\n const nextTag = `v${nextRelease.version}`;\n\n const repositoryUrl = options.repositoryUrl!;\n const url = new URL(repositoryUrl);\n const repositoryPath = url.pathname;\n const repository = repositoryPath.startsWith('/') ? repositoryPath.slice(1) : repositoryPath;\n const tarFilePath = tarballFile.replace('nextTag', nextTag);\n\n const tarUrl = `https://github.com/${repository}/releases/download/${nextTag}/${tarFilePath}`;\n //const tarUrl = `https://codeload.github.com/${repository}/tar.gz/refs/tags/${tarFilePath}`;\n\n const sha256 = calculateSha256(pluginConfig, context);\n const formulaFile = getFormulaFile(pluginConfig, context);\n\n let formulaContent = fs.readFileSync(formulaFile, 'utf8');\n formulaContent = formulaContent.replace(/url \".*\"/, `url \"${tarUrl}\"`);\n formulaContent = formulaContent.replace(/sha256 \".*\"/, `sha256 \"${sha256}\"`);\n fs.writeFileSync(formulaFile, formulaContent);\n}\n\nasync function addChannel(pluginConfig: PluginConfig, context: AddChannelContext): Promise<void> {\n if (!verified) {\n await verifyConditions(pluginConfig, context);\n verified = true;\n }\n\n if (gitHubAddChanel) {\n await gitHubAddChanel(pluginConfig, context);\n }\n}\n\nasync function analyzeCommits(pluginConfig: PluginConfig, context: AnalyzeCommitsContext): Promise<string | false> {\n if (!verified) {\n await verifyConditions(pluginConfig, context);\n verified = true;\n }\n\n return commitAnalyzerAnalyzeCommits(analyzerConfig, context);\n}\n\nasync function fail(pluginConfig: PluginConfig, context: FailContext): Promise<void> {\n if (gitHubFail) {\n await gitPrepare(pluginConfig, context);\n }\n}\n\nasync function generateNotes(pluginConfig: PluginConfig, context: GenerateNotesContext): Promise<string> {\n if (!verified) {\n await verifyConditions(pluginConfig, context);\n verified = true;\n }\n\n return notesGeneratorGenerateNotes({}, context);\n}\n\nasync function prepare(pluginConfig: PluginConfig, context: PrepareContext): Promise<void> {\n if (!verified) {\n await verifyConditions(pluginConfig, context);\n verified = true;\n }\n\n if (gitPrepare) {\n const { nextRelease } = context;\n if (!nextRelease?.version) {\n throw new Error('Next release version is not available.');\n }\n\n const formulaFile = getFormulaFile(pluginConfig, context);\n\n generateTarball(pluginConfig, context);\n\n await updateFormulaFile(pluginConfig, context);\n\n await gitPrepare(\n {\n assets: [formulaFile],\n message: 'chore(release): ${nextRelease.version}',\n },\n context,\n );\n }\n}\n\nasync function publish(pluginConfig: PluginConfig, context: PublishContext): Promise<unknown> {\n if (!verified) {\n await verifyConditions(pluginConfig, context);\n verified = true;\n }\n\n if (gitHubPublish) {\n const { nextRelease } = context;\n const nextTag = `v${nextRelease.version}`;\n const tarFilePath = tarballFile.replace('nextTag', nextTag);\n\n const customPluginConfig = {\n ...pluginConfig,\n assets: [\n {\n path: tarFilePath,\n label: `Homebrew Tarball (${nextTag})`,\n },\n ],\n };\n await gitHubPublish(customPluginConfig, context);\n }\n //await updateFormulaFile(pluginConfig, context);\n\n //await commitFormulaFile(pluginConfig, context);\n\n return null;\n}\n\nasync function success(pluginConfig: PluginConfig, context: SuccessContext): Promise<void> {\n if (!verified) {\n await verifyConditions(pluginConfig, context);\n verified = true;\n }\n\n if (gitHubSuccess) {\n await gitHubSuccess(pluginConfig, context);\n }\n}\n\nasync function verifyConditions(pluginConfig: PluginConfig, context: VerifyConditionsContext): Promise<void> {\n if (gitHubVerifyConditions) {\n await gitHubVerifyConditions(pluginConfig, context);\n }\n if (gitVerifyConditions) {\n await gitVerifyConditions(pluginConfig, context);\n }\n verified = true;\n}\n\nconst plugin: SemanticReleasePlugin<{ tap: string }> = {\n addChannel,\n verifyConditions,\n analyzeCommits,\n generateNotes,\n prepare,\n publish,\n success,\n fail,\n};\n\nexport default plugin;\n"],"names":["tarballFile","analyzerConfig","preset","parserOpts","headerPattern","RegExp","headerCorrespondence","releaseRules","type","exclamation1","release","exclamation2","verified","getFormulaFile","pluginConfig","context","options","repositoryUrl","repositoryPath","URL","pathname","project","startsWith","slice","split","pop","tap","async","updateFormulaFile","nextRelease","nextTag","version","tarUrl","replace","sha256","_pluginConfig","tarFilePath","fileBuffer","fs","readFileSync","hash","crypto","createHash","update","digest","calculateSha256","formulaFile","formulaContent","writeFileSync","verifyConditions","gitHubVerifyConditions","gitVerifyConditions","plugin","addChannel","gitHubAddChanel","analyzeCommits","commitAnalyzerAnalyzeCommits","generateNotes","notesGeneratorGenerateNotes","prepare","gitPrepare","Error","execSync","generateTarball","assets","message","publish","gitHubPublish","customPluginConfig","path","label","success","gitHubSuccess","fail","gitHubFail"],"mappings":"oZAkCA,MAAMA,EAAc,wBAEdC,EAAiB,CACrBC,OAAQ,sBACRC,WAAY,CACVC,cAAeC,OAAA,mGACfC,qBAAsB,CAAC,OAAQ,eAAgB,QAAS,eAAgB,YAE1EC,aAAc,CACZ,CAAEC,KAAM,OAAQC,aAAc,IAAKC,QAAS,SAC5C,CAAEF,KAAM,OAAQG,aAAc,IAAKD,QAAS,SAC5C,CAAEF,KAAM,OAAQE,QAAS,SACzB,CAAEF,KAAM,MAAOE,QAAS,SACxB,CAAEF,KAAM,OAAQE,QAAS,SACzB,CAAEF,KAAM,QAASE,QAAS,SAC1B,CAAEF,KAAM,WAAYE,QAAS,SAC7B,CAAEF,KAAM,OAAQE,QAAS,SACzB,CAAEF,KAAM,OAAQE,QAAS,SACzB,CAAEF,KAAM,QAASE,QAAS,SAC1B,CAAEF,KAAM,KAAME,QAAS,SACvB,CAAEF,KAAM,QAASE,QAAS,SAC1B,CAAEF,KAAM,SAAUE,QAAS,WAM/B,IAAIE,GAAW,EAEf,SAASC,EAAeC,EAA4BC,GAClD,MAAMC,QAAEA,GAAYD,EACdE,EAAgBD,EAAQC,cAExBC,EADM,IAAIC,IAAIF,GACOG,SAErBC,GADaH,EAAeI,WAAW,KAAOJ,EAAeK,MAAM,GAAKL,GACnDM,MAAM,KAAKC,MAEtC,OAAOX,EAAaY,KAAO,GAAGL,MAChC,CA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C,EAqFE4C,QAnFFhC,eAAuBb,EAA4BC,GAMjD,GALKH,UACGqC,EAAiBnC,EAAcC,GACrCH,GAAW,GAGTgD,EAAY,CACd,MAAM/B,YAAEA,GAAgBd,EACxB,IAAKc,GAAaE,QAChB,MAAM,IAAI8B,MAAM,0CAGlB,MAAMf,EAAcjC,EAAeC,EAAcC,IA5FrD,SAAyBoB,EAA6BpB,GACpD,MAAMc,YAAEA,GAAgBd,EAElBe,EAAU,IAAID,EAAYE,UAC1BK,EAAcpC,EAAYiC,QAAQ,UAAWH,GAEnDgC,EAAS,wCAAwC1B,SACnD,CAuFI2B,CAAgBjD,EAAcC,SAExBa,EAAkBd,EAAcC,SAEhC6C,EACJ,CACEI,OAAQ,CAAClB,GACTmB,QAAS,0CAEXlD,EAEJ,CACF,EA0DEmD,QAxDFvC,eAAuBb,EAA4BC,GAMjD,GALKH,UACGqC,EAAiBnC,EAAcC,GACrCH,GAAW,GAGTuD,EAAe,CACjB,MAAMtC,YAAEA,GAAgBd,EAClBe,EAAU,IAAID,EAAYE,UAC1BK,EAAcpC,EAAYiC,QAAQ,UAAWH,GAE7CsC,EAAqB,IACtBtD,EACHkD,OAAQ,CACN,CACEK,KAAMjC,EACNkC,MAAO,qBAAqBxC,cAI5BqC,EAAcC,EAAoBrD,EAC1C,CAKA,OAAO,IACT,EA8BEwD,QA5BF5C,eAAuBb,EAA4BC,GAC5CH,UACGqC,EAAiBnC,EAAcC,GACrCH,GAAW,GAGT4D,SACIA,EAAc1D,EAAcC,EAEtC,EAoBE0D,KArGF9C,eAAoBb,EAA4BC,GAC1C2D,SACId,EAAW9C,EAAcC,EAEnC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tarsilla/commit-wizard",
3
- "version": "1.4.8",
3
+ "version": "1.4.9",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -60,6 +60,7 @@
60
60
  },
61
61
  "dependencies": {
62
62
  "@octokit/rest": "^21.1.1",
63
+ "@semantic-release/github": "^11.0.1",
63
64
  "chokidar": "^4.0.3",
64
65
  "inquirer": "^8.2.6"
65
66
  },
@@ -1,9 +1,22 @@
1
+ import { execSync } from 'child_process';
1
2
  import crypto from 'crypto';
2
3
  import fs from 'fs';
3
4
 
4
- import { Octokit } from '@octokit/rest';
5
5
  //@ts-ignore
6
6
  import { analyzeCommits as commitAnalyzerAnalyzeCommits } from '@semantic-release/commit-analyzer';
7
+ import {
8
+ prepare as gitPrepare,
9
+ verifyConditions as gitVerifyConditions,
10
+ //@ts-ignore
11
+ } from '@semantic-release/git';
12
+ import {
13
+ addChannel as gitHubAddChanel,
14
+ fail as gitHubFail,
15
+ publish as gitHubPublish,
16
+ success as gitHubSuccess,
17
+ verifyConditions as gitHubVerifyConditions,
18
+ //@ts-ignore
19
+ } from '@semantic-release/github';
7
20
  //@ts-ignore
8
21
  import { generateNotes as notesGeneratorGenerateNotes } from '@semantic-release/release-notes-generator';
9
22
  import {
@@ -19,6 +32,8 @@ import {
19
32
 
20
33
  import { SemanticReleasePlugin } from '../types.js';
21
34
 
35
+ const tarballFile = 'nextTag-stable.tar.gz';
36
+
22
37
  const analyzerConfig = {
23
38
  preset: 'conventionalcommits',
24
39
  parserOpts: {
@@ -46,7 +61,9 @@ type PluginConfig = { tap?: string };
46
61
 
47
62
  let verified = false;
48
63
 
49
- function getFormulaFile(pluginConfig: PluginConfig, repositoryUrl: string): string {
64
+ function getFormulaFile(pluginConfig: PluginConfig, context: PrepareContext): string {
65
+ const { options } = context;
66
+ const repositoryUrl = options.repositoryUrl!;
50
67
  const url = new URL(repositoryUrl);
51
68
  const repositoryPath = url.pathname;
52
69
  const repository = repositoryPath.startsWith('/') ? repositoryPath.slice(1) : repositoryPath;
@@ -55,162 +72,60 @@ function getFormulaFile(pluginConfig: PluginConfig, repositoryUrl: string): stri
55
72
  return pluginConfig.tap ?? `${project}.rb`;
56
73
  }
57
74
 
58
- async function commitFormulaFile(pluginConfig: PluginConfig, context: PrepareContext): Promise<void> {
59
- if (!process.env.GITHUB_TOKEN) {
60
- throw new Error('GITHUB_TOKEN is not set in the environment.');
61
- }
62
-
63
- const { nextRelease, logger, options } = context;
64
-
65
- const repositoryUrl = options.repositoryUrl!; // Guaranteed to be defined by semantic-release
66
- const [owner, repo] = new URL(repositoryUrl).pathname.slice(1).split('/');
67
-
68
- const formulaFile = getFormulaFile(pluginConfig, repositoryUrl);
69
- const branchName = options.branch ?? 'main';
70
-
71
- logger.log(`Committing updated formula file ${formulaFile} to branch ${branchName}...`);
75
+ function generateTarball(_pluginConfig: PluginConfig, context: PrepareContext) {
76
+ const { nextRelease } = context;
72
77
 
73
- const octokit = new Octokit({
74
- auth: process.env.GITHUB_TOKEN,
75
- });
78
+ const nextTag = `v${nextRelease.version}`;
79
+ const tarFilePath = tarballFile.replace('nextTag', nextTag);
76
80
 
77
- try {
78
- // Get the latest commit SHA and tree SHA from the branch
79
- const { data: branch } = await octokit.repos.getBranch({
80
- owner,
81
- repo,
82
- branch: branchName,
83
- });
84
-
85
- const latestCommitSha = branch.commit.sha;
86
- const baseTreeSha = branch.commit.commit.tree.sha;
87
-
88
- logger.log(`Latest commit SHA: ${latestCommitSha}`);
89
- logger.log(`Base tree SHA: ${baseTreeSha}`);
90
-
91
- // Read the updated formula file content
92
- const formulaContent = fs.readFileSync(formulaFile, 'utf8');
93
-
94
- // Create a new blob for the updated formula file
95
- const { data: blob } = await octokit.git.createBlob({
96
- owner,
97
- repo,
98
- content: formulaContent,
99
- encoding: 'utf-8',
100
- });
101
-
102
- logger.log(`Created blob for ${formulaFile} with SHA: ${blob.sha}`);
103
-
104
- // Create a new tree with the updated formula file
105
- const { data: newTree } = await octokit.git.createTree({
106
- owner,
107
- repo,
108
- base_tree: baseTreeSha,
109
- tree: [
110
- {
111
- path: formulaFile,
112
- mode: '100644',
113
- type: 'blob',
114
- sha: blob.sha,
115
- },
116
- ],
117
- });
118
-
119
- logger.log(`Created new tree with SHA: ${newTree.sha}`);
120
-
121
- // Create a new commit with the updated tree
122
- const commitMessage = `chore(release): ${nextRelease.version}`;
123
- const { data: newCommit } = await octokit.git.createCommit({
124
- owner,
125
- repo,
126
- message: commitMessage,
127
- tree: newTree.sha,
128
- parents: [latestCommitSha],
129
- });
130
-
131
- logger.log(`Created new commit with SHA: ${newCommit.sha}`);
132
-
133
- // Update the branch reference to point to the new commit
134
- await octokit.git.updateRef({
135
- owner,
136
- repo,
137
- ref: `heads/${branchName}`,
138
- sha: newCommit.sha,
139
- });
140
-
141
- logger.log(`Branch ${branchName} updated to commit ${newCommit.sha}`);
142
- } catch (error) {
143
- logger.error(`Failed to commit formula file: ${(error as Error).message}`);
144
- throw error;
145
- }
81
+ execSync(`git archive --format=tar.gz --output=${tarFilePath} HEAD`);
146
82
  }
147
83
 
148
- async function calculateSha256(url: string, context: PrepareContext): Promise<string> {
149
- const { logger } = context;
150
-
151
- logger.log(`Calculating SHA256 for URL: ${url}`);
84
+ function calculateSha256(_pluginConfig: PluginConfig, context: PrepareContext) {
85
+ const { nextRelease } = context;
152
86
 
153
- const response = await fetch(url);
154
-
155
- if (!response.ok) {
156
- throw new Error(`Failed to fetch file. Status Code: ${response.status}`);
157
- }
158
-
159
- if (!response.body) {
160
- throw new Error('Response body is null.');
161
- }
87
+ const nextTag = `v${nextRelease.version}`;
88
+ const tarFilePath = tarballFile.replace('nextTag', nextTag);
162
89
 
90
+ const fileBuffer = fs.readFileSync(tarFilePath);
163
91
  const hash = crypto.createHash('sha256');
164
- const reader = response.body.getReader();
165
-
166
- return new Promise((resolve, reject) => {
167
- function read() {
168
- reader
169
- .read()
170
- .then(({ done, value }) => {
171
- if (done) {
172
- resolve(hash.digest('hex'));
173
- return;
174
- }
175
- if (value) {
176
- hash.update(value);
177
- }
178
- read();
179
- })
180
- .catch(reject);
181
- }
182
- read();
183
- });
92
+ hash.update(fileBuffer);
93
+
94
+ return hash.digest('hex');
184
95
  }
185
96
 
186
97
  async function updateFormulaFile(pluginConfig: PluginConfig, context: PrepareContext): Promise<void> {
187
- const { nextRelease, logger, options } = context;
188
-
189
- if (!nextRelease?.version) {
190
- throw new Error('Next release version is not available.');
191
- }
98
+ const { nextRelease, options } = context;
192
99
 
193
- const tagName = `v${nextRelease.version}`;
100
+ const nextTag = `v${nextRelease.version}`;
194
101
 
195
- const repositoryUrl = options.repositoryUrl!; // Guaranteed to be defined by semantic-release
102
+ const repositoryUrl = options.repositoryUrl!;
196
103
  const url = new URL(repositoryUrl);
197
104
  const repositoryPath = url.pathname;
198
105
  const repository = repositoryPath.startsWith('/') ? repositoryPath.slice(1) : repositoryPath;
106
+ const tarFilePath = tarballFile.replace('nextTag', nextTag);
199
107
 
200
- const tarUrl = `https://codeload.github.com/${repository}/tar.gz/refs/tags/${tagName}`;
201
- const sha256 = await calculateSha256(tarUrl, context);
202
- const formulaFile = getFormulaFile(pluginConfig, repositoryUrl);
108
+ const tarUrl = `https://github.com/${repository}/releases/download/${nextTag}/${tarFilePath}`;
109
+ //const tarUrl = `https://codeload.github.com/${repository}/tar.gz/refs/tags/${tarFilePath}`;
110
+
111
+ const sha256 = calculateSha256(pluginConfig, context);
112
+ const formulaFile = getFormulaFile(pluginConfig, context);
203
113
 
204
114
  let formulaContent = fs.readFileSync(formulaFile, 'utf8');
205
115
  formulaContent = formulaContent.replace(/url ".*"/, `url "${tarUrl}"`);
206
116
  formulaContent = formulaContent.replace(/sha256 ".*"/, `sha256 "${sha256}"`);
207
117
  fs.writeFileSync(formulaFile, formulaContent);
208
-
209
- logger.log(`Updated formula with version ${tagName}, URL ${tarUrl}, and SHA256 ${sha256}`);
210
118
  }
211
119
 
212
- async function addChannel(_pluginConfig: PluginConfig, _context: AddChannelContext): Promise<void> {
213
- //do nothing
120
+ async function addChannel(pluginConfig: PluginConfig, context: AddChannelContext): Promise<void> {
121
+ if (!verified) {
122
+ await verifyConditions(pluginConfig, context);
123
+ verified = true;
124
+ }
125
+
126
+ if (gitHubAddChanel) {
127
+ await gitHubAddChanel(pluginConfig, context);
128
+ }
214
129
  }
215
130
 
216
131
  async function analyzeCommits(pluginConfig: PluginConfig, context: AnalyzeCommitsContext): Promise<string | false> {
@@ -222,8 +137,10 @@ async function analyzeCommits(pluginConfig: PluginConfig, context: AnalyzeCommit
222
137
  return commitAnalyzerAnalyzeCommits(analyzerConfig, context);
223
138
  }
224
139
 
225
- async function fail(_pluginConfig: PluginConfig, _context: FailContext): Promise<void> {
226
- //do nothing
140
+ async function fail(pluginConfig: PluginConfig, context: FailContext): Promise<void> {
141
+ if (gitHubFail) {
142
+ await gitPrepare(pluginConfig, context);
143
+ }
227
144
  }
228
145
 
229
146
  async function generateNotes(pluginConfig: PluginConfig, context: GenerateNotesContext): Promise<string> {
@@ -235,8 +152,32 @@ async function generateNotes(pluginConfig: PluginConfig, context: GenerateNotesC
235
152
  return notesGeneratorGenerateNotes({}, context);
236
153
  }
237
154
 
238
- async function prepare(_pluginConfig: PluginConfig, _context: PrepareContext): Promise<void> {
239
- //do nothing
155
+ async function prepare(pluginConfig: PluginConfig, context: PrepareContext): Promise<void> {
156
+ if (!verified) {
157
+ await verifyConditions(pluginConfig, context);
158
+ verified = true;
159
+ }
160
+
161
+ if (gitPrepare) {
162
+ const { nextRelease } = context;
163
+ if (!nextRelease?.version) {
164
+ throw new Error('Next release version is not available.');
165
+ }
166
+
167
+ const formulaFile = getFormulaFile(pluginConfig, context);
168
+
169
+ generateTarball(pluginConfig, context);
170
+
171
+ await updateFormulaFile(pluginConfig, context);
172
+
173
+ await gitPrepare(
174
+ {
175
+ assets: [formulaFile],
176
+ message: 'chore(release): ${nextRelease.version}',
177
+ },
178
+ context,
179
+ );
180
+ }
240
181
  }
241
182
 
242
183
  async function publish(pluginConfig: PluginConfig, context: PublishContext): Promise<unknown> {
@@ -245,18 +186,47 @@ async function publish(pluginConfig: PluginConfig, context: PublishContext): Pro
245
186
  verified = true;
246
187
  }
247
188
 
248
- await updateFormulaFile(pluginConfig, context);
189
+ if (gitHubPublish) {
190
+ const { nextRelease } = context;
191
+ const nextTag = `v${nextRelease.version}`;
192
+ const tarFilePath = tarballFile.replace('nextTag', nextTag);
193
+
194
+ const customPluginConfig = {
195
+ ...pluginConfig,
196
+ assets: [
197
+ {
198
+ path: tarFilePath,
199
+ label: `Homebrew Tarball (${nextTag})`,
200
+ },
201
+ ],
202
+ };
203
+ await gitHubPublish(customPluginConfig, context);
204
+ }
205
+ //await updateFormulaFile(pluginConfig, context);
249
206
 
250
- await commitFormulaFile(pluginConfig, context);
207
+ //await commitFormulaFile(pluginConfig, context);
251
208
 
252
209
  return null;
253
210
  }
254
211
 
255
- async function success(_pluginConfig: PluginConfig, _context: SuccessContext): Promise<void> {
256
- //do nothing
212
+ async function success(pluginConfig: PluginConfig, context: SuccessContext): Promise<void> {
213
+ if (!verified) {
214
+ await verifyConditions(pluginConfig, context);
215
+ verified = true;
216
+ }
217
+
218
+ if (gitHubSuccess) {
219
+ await gitHubSuccess(pluginConfig, context);
220
+ }
257
221
  }
258
222
 
259
- async function verifyConditions(_pluginConfig: PluginConfig, _context: VerifyConditionsContext): Promise<void> {
223
+ async function verifyConditions(pluginConfig: PluginConfig, context: VerifyConditionsContext): Promise<void> {
224
+ if (gitHubVerifyConditions) {
225
+ await gitHubVerifyConditions(pluginConfig, context);
226
+ }
227
+ if (gitVerifyConditions) {
228
+ await gitVerifyConditions(pluginConfig, context);
229
+ }
260
230
  verified = true;
261
231
  }
262
232