remix-project mirror
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
remix-project/apps/remix-ide/ci/update_desktop_release_asse...

100 lines
2.6 KiB

10 months ago
import {Octokit} from 'octokit'
10 months ago
import * as fs from 'fs'
import * as path from 'path'
10 months ago
const owner = 'bunsenstraat'
const repo = 'remix-desktop'
const headers = {
10 months ago
'X-GitHub-Api-Version': '2022-11-28',
10 months ago
}
const octokit = new Octokit({
10 months ago
auth: process.env.GH_TOKEN,
10 months ago
})
async function getAllReleases() {
10 months ago
const releases = await octokit.request('GET /repos/{owner}/{repo}/releases', {
owner: owner,
repo: repo,
10 months ago
headers: headers,
10 months ago
})
return releases.data
10 months ago
}
10 months ago
async function uploadReleaseAsset(release, name, file) {
const upload_url = release.upload_url
console.log(upload_url)
octokit.request({
method: "POST",
url: upload_url,
headers: {
"content-type": "text/plain",
},
data: fs.readFileSync(file),
name,
label: name
});
}
10 months ago
async function getVersionFromPackageJson() {
10 months ago
// ignore ts error
// eslint-disable-next-line @typescript-eslint/no-var-requires
const packageJson = require(__dirname + '/../../../apps/remixdesktop/package.json')
return packageJson.version
10 months ago
}
10 months ago
async function readReleaseFilesFromLocalDirectory() {
const directoryPath = path.join(__dirname, '../../../release')
const files = fs.readdirSync(directoryPath)
return files
10 months ago
}
10 months ago
async function removeAsset(asset) {
await octokit.request('DELETE /repos/{owner}/{repo}/releases/assets/{asset_id}', {
10 months ago
owner: owner,
repo: repo,
10 months ago
asset_id: asset.id,
headers: headers,
10 months ago
})
10 months ago
}
10 months ago
10 months ago
async function main() {
const allReleases = await getAllReleases()
const version = await getVersionFromPackageJson()
console.log(`preparing release version: ${version}`)
let release
allReleases.find((r) => {
if (r.tag_name === `v${version}`) {
release = r
}
})
if (!release) {
console.log('No release found.')
return
10 months ago
}
10 months ago
10 months ago
let files = await readReleaseFilesFromLocalDirectory()
10 months ago
10 months ago
files = files.filter((file) => file.endsWith('.dmg') || file.endsWith('.exe') || file.endsWith('.AppImage') || file.endsWith('.snap') || file.endsWith('.deb') || file.startsWith('latest'))
console.log(`Found ${files.length} files to upload`)
10 months ago
console.log(files)
if (!release.draft) {
10 months ago
console.log(`Release ${version} is not a draft. Aborting...`)
10 months ago
return
}
10 months ago
// upload files
for (const file of files) {
// check if it is already uploaded
const asset = release.assets.find((a) => a.label === file)
if (asset) {
console.log(`Asset ${file} already uploaded... replacing it`)
// remove it first
await removeAsset(asset)
}
await uploadReleaseAsset(release, file, path.join(__dirname, '../../../release', file))
}
10 months ago
}
10 months ago
main()