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
|
|
@ -72,16 +72,6 @@ jobs:
|
|||
env:
|
||||
TAG: "v${{steps.version.outputs.version}}"
|
||||
|
||||
# - name: Upload artifacts
|
||||
# uses: https://data.forgejo.org/forgejo/upload-artifact@v4
|
||||
# with:
|
||||
# name: "forgejo-final"
|
||||
# path: |
|
||||
# system.json
|
||||
# release.zip
|
||||
# retention-days: 7
|
||||
# if-no-files-found: error
|
||||
|
||||
|
||||
github-release:
|
||||
runs-on: act
|
||||
|
|
@ -114,9 +104,9 @@ jobs:
|
|||
run: echo Syncing mirror
|
||||
|
||||
- name: Create draft release
|
||||
run: cat system.json
|
||||
run: node scripts/createGithubRelease.mjs
|
||||
env:
|
||||
TAG: "v${{steps.version.outputs.version}}"
|
||||
TOKEN: "Bearer ${{secrets.GH_TOKEN}}"
|
||||
TOKEN: ${{secrets.GH_TOKEN}}
|
||||
API_URL: "https://api.github.com"
|
||||
REPO: "${{vars.GH_USER}}/${{vars.GH_REPO}}"
|
||||
|
|
|
|||
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