Begin work on testing the Github release portion of the action
This commit is contained in:
parent
45de56650a
commit
2ddcda676e
2 changed files with 85 additions and 12 deletions
83
scripts/createGithubRelease.mjs
Normal file
83
scripts/createGithubRelease.mjs
Normal file
|
|
@ -0,0 +1,83 @@
|
|||
/*
|
||||
Create draft release
|
||||
Assert HTTP 200
|
||||
Upload release.zip
|
||||
Upload system.json
|
||||
*/
|
||||
import { createReadStream } from "fs";
|
||||
import axios from "axios";
|
||||
|
||||
const {
|
||||
TAG,
|
||||
REPO,
|
||||
TOKEN,
|
||||
API_URL: API,
|
||||
} = process.env;
|
||||
|
||||
async function uploadFile(releaseID, localPath, remoteName = undefined) {
|
||||
remoteName ??= localPath.split(`/`).at(-1);
|
||||
const stream = createReadStream(localPath);
|
||||
return axios.post(
|
||||
`${API}/repos/${REPO}/releases/${releaseID}/assets`,
|
||||
{
|
||||
attachment: stream,
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
Authorization: `Bearer ${TOKEN}`,
|
||||
"Content-Type": `multipart/form-data`,
|
||||
"X-GitHub-Api-Version": `2022-11-28`,
|
||||
},
|
||||
params: { name: remoteName },
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
async function main() {
|
||||
|
||||
// Initial Release Data
|
||||
const release = await axios.post(
|
||||
`${API}/repos/${REPO}/releases`,
|
||||
{
|
||||
name: TAG,
|
||||
tag_name: TAG,
|
||||
draft: true,
|
||||
generate_release_notes: false,
|
||||
make_latest: false,
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
Authorization: `Bearer ${TOKEN}`,
|
||||
"X-GitHub-Api-Version": `2022-11-28`,
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
try {
|
||||
await uploadFile(release.data.id, `release.zip`);
|
||||
await uploadFile(release.data.id, `system.json`);
|
||||
} catch (e) {
|
||||
console.error(`Failed to upload files, deleting draft release`);
|
||||
console.error(e);
|
||||
|
||||
try {
|
||||
await axios.delete(
|
||||
`${API}/repos/${REPO}/releases/${release.data.id}`,
|
||||
{
|
||||
headers: {
|
||||
Authorization: `Bearer ${TOKEN}`,
|
||||
"X-GitHub-Api-Version": `2022-11-28`,
|
||||
},
|
||||
}
|
||||
)
|
||||
} catch {
|
||||
console.error(`Failed to delete draft release`);
|
||||
};
|
||||
|
||||
process.exit(1);
|
||||
};
|
||||
|
||||
console.log(`Release created, and files uploaded successfully!`);
|
||||
};
|
||||
|
||||
main();
|
||||
Loading…
Add table
Add a link
Reference in a new issue