@r5n/sisyphus 0.15.0 → 0.15.1
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.
- package/dist/cli.js +1 -1
- package/dist/templates/github/sis-release.yml +33 -1
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -98,7 +98,7 @@ ${a}
|
|
|
98
98
|
`))});return`${g?"[":"{"}${S}${H.join(V)}${k}${g?"]":"}"}`}function c(l,p,m){if(!m)return co(l,o);let g=e.lastIndexOf(`
|
|
99
99
|
`,p-1)+1,h=e.slice(g,p).match(/^[\t ]*/)?.[0]??"";return JSON.stringify(l,null,s).replaceAll(`
|
|
100
100
|
`,i+h)}return e.slice(0,r.start)+a(r,n)+e.slice(r.end)}function co(e,t){if(Array.isArray(e))return`[${e.map((s)=>co(s,t)).join(`,${t}`)}]`;if(e===null||typeof e!=="object")return JSON.stringify(e);let n=Object.entries(e);if(n.length===0)return"{}";let r=n.map(([s,i])=>`${JSON.stringify(s)}:${t}${co(i,t)}`);return`{${t}${r.join(`,${t}`)}${t}}`}function uh(e){let t=e.matchAll(/"(?:[^"\\]|\\.)*"|[^\s{}[\],:]+|[{}[\],:]/g),n=t.next().value;function r(){if(!n)throw Error("Unexpected end of JSON");let i=n;return n=t.next().value,i}function s(){let i=r(),o=[],a=i[0]==="{";if(!a&&i[0]!=="[")return{end:i.index+i[0].length,entries:o,start:i.index,value:JSON.parse(i[0])};let c=a?"}":"]";while(n&&n[0]!==c){let p=n.index,m=a?JSON.parse(r()[0]):String(o.length);if(a)r();if(o.push({key:m,node:s(),start:p}),n?.[0]===",")r()}let l=r().index+1;return{end:l,entries:o,start:i.index,value:JSON.parse(e.slice(i.index,l))}}return s()}var ph=2,uo="ConfigError",dh=rn(Object);class po{loaded;configPath;defaultConfig;options;constructor(e,t,n={}){this.configPath=lo.resolve(e),this.defaultConfig=t,this.options=n}get path(){return this.configPath}get failure(){return this.state().failure}get(e){return this.current()[e]}set(e,t){let n=this.writable();this.update((r)=>({...r,[e]:t})),n.config={...n.config,[e]:t}}delete(e){let t=this.writable();this.update((n)=>(delete n[e],n)),delete t.config[e]}exists(){return We.existsSync(this.configPath)}getAll(){return structuredClone(this.current())}save(e){let t=this.writable();if(e)t.config={...e};this.update(()=>t.config)}state(){return this.loaded??=this.load(),this.loaded}current(){let{config:e,failure:t}=this.state();if(t)throw t;return e}writable(){let e=this.state();if(e.failure)throw e.failure;if(e.error)throw this.unreadable(e.error);return e}unreadable(e){return new u(`Cannot overwrite unreadable config at ${this.configPath}`,"Repair the file and try again",void 0,{cause:e,tag:uo})}readStored(){try{let e=this.readConfigFile();if(e===void 0)return structuredClone(this.defaultConfig);return Lt(structuredClone(this.defaultConfig),_l(e))}catch(e){throw this.unreadable(e)}}update(e){try{let t=this.savePath();xl(t,()=>this.write(t,e(this.readStored())))}catch(t){throw t instanceof u?t:this.saveFailure(t)}}savePath(){let e=this.exists()?We.realpathSync(this.configPath):Ol(this.configPath);return We.mkdirSync(lo.dirname(e),{recursive:!0}),e}write(e,t){let n=`${e}.${crypto.randomUUID()}.tmp`;try{let r=this.exists()?We.statSync(this.configPath).mode:void 0,s=this.exists()?Wn(We.readFileSync(this.configPath,"utf-8"),t):`${JSON.stringify(t,null,ph)}
|
|
101
|
-
`;if(We.writeFileSync(n,s,{flag:"wx",mode:r}),r!==void 0)We.chmodSync(n,r);We.renameSync(n,e)}finally{We.rmSync(n,{force:!0})}}saveFailure(e){return new u(`Cannot save config at ${this.configPath}: ${Ll(e)}`,`Check that ${lo.dirname(this.configPath)} is writable and that no other process is saving the file`,void 0,{cause:e,tag:uo})}load(){let{parse:e,strict:t}=this.options;try{let n=this.readConfigFile();if(n===void 0)return{config:structuredClone(this.defaultConfig)};let r=Lt(structuredClone(this.defaultConfig),_l(n));return{config:e?e(r):r}}catch(n){if(t)return{config:structuredClone(this.defaultConfig),failure:this.loadFailure(n)};return P.warn(d.yellow(`Config file corrupted at ${this.configPath}. Using defaults.`),{output:Gr()}),{config:structuredClone(this.defaultConfig),error:n}}}loadFailure(e){return new u(`Cannot read config at ${this.configPath}: ${Ll(e)}`,"Repair the file and try again",void 0,{cause:e,tag:uo})}readConfigFile(){try{return We.readFileSync(this.configPath,"utf-8")}catch(e){if(e.code==="ENOENT")return;throw e}}}function _l(e){let t=JSON.parse(e);if(Array.isArray(t))throw Error("Config must be an object");return dh(t)}function Ll(e){return e instanceof Error?e.message:String(e)}var Dl="0.15.
|
|
101
|
+
`;if(We.writeFileSync(n,s,{flag:"wx",mode:r}),r!==void 0)We.chmodSync(n,r);We.renameSync(n,e)}finally{We.rmSync(n,{force:!0})}}saveFailure(e){return new u(`Cannot save config at ${this.configPath}: ${Ll(e)}`,`Check that ${lo.dirname(this.configPath)} is writable and that no other process is saving the file`,void 0,{cause:e,tag:uo})}load(){let{parse:e,strict:t}=this.options;try{let n=this.readConfigFile();if(n===void 0)return{config:structuredClone(this.defaultConfig)};let r=Lt(structuredClone(this.defaultConfig),_l(n));return{config:e?e(r):r}}catch(n){if(t)return{config:structuredClone(this.defaultConfig),failure:this.loadFailure(n)};return P.warn(d.yellow(`Config file corrupted at ${this.configPath}. Using defaults.`),{output:Gr()}),{config:structuredClone(this.defaultConfig),error:n}}}loadFailure(e){return new u(`Cannot read config at ${this.configPath}: ${Ll(e)}`,"Repair the file and try again",void 0,{cause:e,tag:uo})}readConfigFile(){try{return We.readFileSync(this.configPath,"utf-8")}catch(e){if(e.code==="ENOENT")return;throw e}}}function _l(e){let t=JSON.parse(e);if(Array.isArray(t))throw Error("Config must be an object");return dh(t)}function Ll(e){return e instanceof Error?e.message:String(e)}var Dl="0.15.1";var T="sis",mo="\uD83E\uDEA8",mt="other",gt={build:23,chore:25,ci:24,docs:20,feat:10,"feat!":0,fix:11,"fix!":1,perf:12,refactor:13,style:21,test:22,["other"]:100},ft=50,on=".sisyphus",Ml="stones",Nl="released",ds=7;var Jn="unknown",jl="0.0.0",ye="latest",go=["bun","run","build"],Mt="main",Fl=4,Bl=8,ms="config.json";var ht={$schema:"https://raw.githubusercontent.com/r5n-labs/clis/refs/heads/develop/packages/sisyphus/schema.json",changelog:{append:!1,filename:"CHANGELOG.md",generate:!0,packageHeader:"{emoji} {version} ({date})",root:!1,rootHeader:"{date} - {packages}",sections:{breaking:"Breaking changes",build:"Build",chore:"Chores",ci:"CI",dependencies:"Dependency updates",docs:"Documentation",feat:"Features",fix:"Bug fixes",other:"Other changes",perf:"Performance",refactor:"Refactoring",style:"Styling",test:"Tests"}},commit:{author:"r5n-bot",email:"r5n-bot@users.noreply.github.com",message:"chore(release): {versions}"},commits:{skip:{authors:["r5n-bot[bot]"],messagePatterns:["^chore\\(release\\):","^chore: add stone"]}},dependents:{kinds:["dependencies","devDependencies","optionalDependencies","peerDependencies"],updateInternal:"always"},ignore:[],lastStone:{commit:"",date:""},plugins:[],pr:{labelMapping:{breaking:"major","breaking-change":"major",bug:"patch",chore:"patch",docs:"patch",enhancement:"minor",feature:"minor",fix:"patch"},skip:{authors:["r5n-bot[bot]"],labels:["sisyphus-release","skip-stone"],titlePatterns:["^chore\\(release\\):"]}},release:{build:{command:[...go],outputs:[],root:[]},createRelease:!1,npm:!1,npmVisibilityTimeout:0,push:!1,tags:!1},scripts:{post:{},pre:{}},single:!1,sisyphusDir:".sisyphus",stones:[],tag:"latest"};var M=jr();import{existsSync as Mh}from"fs";import{mkdir as Nh,writeFile as jh}from"fs/promises";import{dirname as Fh}from"path";var Je="ProviderRequestFailed",yt={bitbucket:"bitbucket.org",github:"github.com",gitlab:"gitlab.com"};function ze(e){return e.host??yt[e.provider]}class wt{owner;repo;remote;constructor(e){this.owner=e.owner,this.repo=e.repo,this.remote=e}get host(){return ze(this.remote)}}class gs extends wt{name="bitbucket";notImplemented(){throw new u("Bitbucket is not supported yet","Bitbucket support is coming soon")}async ensureAvailable(){this.notImplemented()}async getDefaultBranch(){this.notImplemented()}async findPr(e){this.notImplemented()}async createPr(e){this.notImplemented()}async updatePr(e,t){this.notImplemented()}async getPr(e){this.notImplemented()}async getPrFromCurrentBranch(){this.notImplemented()}async getPrCommits(e){this.notImplemented()}async getPrFiles(e){this.notImplemented()}async ensureLabelExists(e,t){this.notImplemented()}async getRelease(e){this.notImplemented()}async createRelease(e){this.notImplemented()}async deleteRelease(e){this.notImplemented()}}var gh=200,fh=404,hh=10,yh=3000,Ul=_().map((e)=>e.length>0?e:K()),wh=ne(ne(qn({filename:Ul,previous_filename:Ul.or(qe()),status:_()}).map((e)=>e.status==="renamed"&&e.previous_filename===void 0?K():e)));function bh(e){if(typeof e!=="object"||e===null)return!1;let t=e;return typeof t.tag_name==="string"&&typeof t.draft==="boolean"&&(typeof t.name==="string"||t.name===null)&&(typeof t.body==="string"||t.body===null)}class fs extends wt{name="github";get apiPath(){return`repos/${encodeURIComponent(this.owner)}/${encodeURIComponent(this.repo)}`}get repository(){return this.isPublicHost?`${this.owner}/${this.repo}`:`${this.host}/${this.owner}/${this.repo}`}get hostArgs(){return this.isPublicHost?[]:["--hostname",this.host]}get isPublicHost(){return this.host===yt.github}async gh(e,t){try{return(await t()).stdout.toString()}catch(n){let r=n&&typeof n==="object"&&"stderr"in n?String(n.stderr).trim():"";throw new u(`Failed to ${e} on ${this.repository}: ${r||n}`,"Check gh access and retry",1,{cause:n,tag:Je})}}async ensureAvailable(){try{await Bun.$`which gh`.quiet()}catch{throw new u("GitHub CLI (gh) is not installed",`Install from https://cli.github.com and run: gh auth login --hostname ${this.host}`)}try{await Bun.$`gh auth status --hostname ${this.host}`.env({...process.env,GH_HOST:this.host}).quiet()}catch{throw new u(`GitHub CLI (gh) is not authenticated for ${this.host}`,`Run: gh auth login --hostname ${this.host}`)}}async getDefaultBranch(){return(await this.gh("read the default branch",()=>Bun.$`gh api ${this.apiPath} ${this.hostArgs} --jq .default_branch`.quiet())).trim()||Mt}async findPr(e){let t=[];if(e.head)t.push("--head",e.head);if(e.label)t.push("--label",e.label);let n=await this.gh("list pull requests",()=>Bun.$`gh pr list --repo ${this.repository} --json number,url,title,body,labels,author,headRefName,baseRefName,mergeCommit,state --limit 1 ${t}`.quiet()),[r]=JSON.parse(n);return r?this.mapPrResponse(r):null}async createPr(e){let t=await this.gh("create a pull request",()=>Bun.$`gh api ${this.apiPath}/pulls ${this.hostArgs} --method POST -f head=${e.head} -f base=${e.base} -f title=${e.title} -f body=${e.body}`.quiet()),n=JSON.parse(t).number;if(e.labels&&e.labels.length>0){let r=e.labels.flatMap((s)=>["-f",`labels[]=${s}`]);await this.gh(`label pull request #${n}`,()=>Bun.$`gh api ${this.apiPath}/issues/${n}/labels ${this.hostArgs} --method POST ${r}`.quiet())}return this.getPr(n)}async updatePr(e,t){let n=[];if(t.title)n.push("--title",t.title);if(t.body)n.push("--body",t.body);await this.gh(`update pull request #${e}`,()=>Bun.$`gh pr edit ${e} --repo ${this.repository} ${n}`.quiet())}async getPr(e){try{let t=await Bun.$`gh api ${this.apiPath}/pulls/${e} ${this.hostArgs}`.quiet(),n=JSON.parse(t.stdout.toString());return this.mapRestApiResponse(n)}catch(t){throw new u(`Failed to fetch PR #${e}`,"Make sure the PR exists and you have access",1,{cause:t,tag:Je})}}async getPrFromCurrentBranch(){try{let e=(await Bun.$`git rev-parse --abbrev-ref HEAD`.quiet()).stdout.toString().trim(),t=await Bun.$`gh pr view ${e} --repo ${this.repository} --json number,title,body,labels,author,headRefName,baseRefName,url,mergeCommit,state`.quiet(),n=JSON.parse(t.stdout.toString());return this.mapPrResponse(n)}catch(e){throw new u("No PR found for current branch","Make sure you have an open PR or provide a URL with --url",1,{cause:e,tag:Je})}}async getPrCommits(e){return(await this.gh(`fetch PR #${e} commits`,()=>Bun.$`gh api ${this.apiPath}/pulls/${e}/commits ${this.hostArgs} --paginate --jq '.[].sha'`.quiet())).trim().split(`
|
|
102
102
|
`).filter(Boolean)}async getPrFiles(e){let t=await this.gh(`fetch PR #${e} files`,()=>Bun.$`gh api ${this.apiPath}/pulls/${e}/files ${this.hostArgs} --paginate --slurp`.quiet()),n=this.parsePrFiles(e,t);if(n.length>=yh)throw new u(`PR #${e} reaches the GitHub file limit`,"The complete changed file list cannot be established; create the stone from a complete local checkout");return[...new Set(n.flatMap((r)=>r.status==="renamed"&&r.previous_filename!==void 0?[r.previous_filename,r.filename]:[r.filename]))]}parsePrFiles(e,t){try{return wh(JSON.parse(t)).flat()}catch(n){throw new u(`Failed to fetch PR #${e} files on ${this.repository}: unexpected gh api response`,"Check GitHub access and retry the analysis",1,{cause:n,tag:Je})}}async ensureLabelExists(e,t){try{let n=t?.description??"",r=t?.color?["--color",t.color]:[];await Bun.$`gh label create ${e} --repo ${this.repository} --description ${n} ${r} --force`.quiet()}catch{}}async getRelease(e){let t=`${this.apiPath}/releases/tags/${encodeURIComponent(e)}`,n=await Bun.$`gh api ${t} ${this.hostArgs} --include`.quiet().nothrow(),r=n.stdout.toString().replaceAll(`\r
|
|
103
103
|
`,`
|
|
104
104
|
`),[s="",...i]=r.split(`
|
|
@@ -15,6 +15,7 @@ jobs:
|
|
|
15
15
|
if: github.event_name == 'workflow_dispatch' || (github.event.pull_request.merged == true && contains(github.event.pull_request.labels.*.name, 'sisyphus-release'))
|
|
16
16
|
runs-on: ubuntu-latest
|
|
17
17
|
permissions:
|
|
18
|
+
actions: read
|
|
18
19
|
contents: write
|
|
19
20
|
id-token: write
|
|
20
21
|
steps:
|
|
@@ -33,12 +34,33 @@ jobs:
|
|
|
33
34
|
rm -rf "$RELEASE_DIR"
|
|
34
35
|
|
|
35
36
|
- name: Restore release state
|
|
37
|
+
if: github.server_url != 'https://github.com'
|
|
36
38
|
uses: actions/cache/restore@v6
|
|
37
39
|
with:
|
|
38
40
|
path: ${{ env.SIS_RELEASE_DIR }}
|
|
39
41
|
key: sisyphus-release-${{ github.run_id }}-${{ github.run_attempt }}
|
|
40
42
|
restore-keys: sisyphus-release-${{ github.run_id }}-
|
|
41
43
|
|
|
44
|
+
- name: Find release state of an earlier attempt
|
|
45
|
+
id: earlier-attempt
|
|
46
|
+
if: github.server_url == 'https://github.com' && github.run_attempt > 1
|
|
47
|
+
env:
|
|
48
|
+
GH_TOKEN: ${{ github.token }}
|
|
49
|
+
run: |
|
|
50
|
+
set -eo pipefail
|
|
51
|
+
ARTIFACTS="$(gh api "repos/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID/artifacts")"
|
|
52
|
+
SAVED="$(jq '[.artifacts[] | select(.name == "sisyphus-release-state" and (.expired | not))] | length' <<<"$ARTIFACTS")"
|
|
53
|
+
if [ "$SAVED" != "0" ]; then
|
|
54
|
+
echo "found=true" >> "$GITHUB_OUTPUT"
|
|
55
|
+
fi
|
|
56
|
+
|
|
57
|
+
- name: Restore release state from the artifact
|
|
58
|
+
if: steps.earlier-attempt.outputs.found == 'true'
|
|
59
|
+
uses: actions/download-artifact@v8
|
|
60
|
+
with:
|
|
61
|
+
name: sisyphus-release-state
|
|
62
|
+
path: ${{ env.SIS_RELEASE_DIR }}
|
|
63
|
+
|
|
42
64
|
- name: Remove cached release lock
|
|
43
65
|
run: rm -f "$SIS_RELEASE_DIR/.write.lock" "$SIS_RELEASE_DIR"/.write.lock.*.owner "$SIS_RELEASE_DIR"/.write.lock.*.claim
|
|
44
66
|
|
|
@@ -77,8 +99,18 @@ jobs:
|
|
|
77
99
|
fi
|
|
78
100
|
|
|
79
101
|
- name: Save release state
|
|
80
|
-
if: always() && steps.release-state.outputs.save == 'true'
|
|
102
|
+
if: always() && github.server_url != 'https://github.com' && steps.release-state.outputs.save == 'true'
|
|
81
103
|
uses: actions/cache/save@v6
|
|
82
104
|
with:
|
|
83
105
|
path: ${{ env.SIS_RELEASE_DIR }}
|
|
84
106
|
key: sisyphus-release-${{ github.run_id }}-${{ github.run_attempt }}
|
|
107
|
+
|
|
108
|
+
- name: Save release state as an artifact
|
|
109
|
+
if: always() && github.server_url == 'https://github.com' && steps.release-state.outputs.save == 'true'
|
|
110
|
+
uses: actions/upload-artifact@v7
|
|
111
|
+
with:
|
|
112
|
+
name: sisyphus-release-state
|
|
113
|
+
path: ${{ env.SIS_RELEASE_DIR }}
|
|
114
|
+
include-hidden-files: true
|
|
115
|
+
overwrite: true
|
|
116
|
+
retention-days: 30
|
package/package.json
CHANGED