upload assets

desktopautoupdate
filip mertens 10 months ago
parent 47577dd30c
commit ca0bd8a109
  1. 7
      .circleci/config.yml
  2. 1
      .gitignore
  3. 90
      apps/remix-ide/ci/update_desktop_release_assets.ts
  4. 2
      apps/remixdesktop/package.json

@ -337,6 +337,13 @@ jobs:
- checkout - checkout
- attach_workspace: - attach_workspace:
at: . at: .
- restore_cache:
keys:
- v1-deps-{{ checksum "yarn.lock" }}
- run: yarn
- run:
name: "Upload Artifacts"
command: npx ts-node apps/remix-ide/ci/update_desktop_release_assets.ts
lint: lint:
docker: docker:
- image: cimg/node:20.0.0-browsers - image: cimg/node:20.0.0-browsers

1
.gitignore vendored

@ -15,6 +15,7 @@ soljson.js
*_group*.*.ts *_group*.*.ts
*_group*.ts *_group*.ts
stats.json stats.json
release
# compiled output # compiled output

@ -5,23 +5,37 @@ import * as path from 'path'
const owner = 'bunsenstraat' const owner = 'bunsenstraat'
const repo = 'remix-desktop' const repo = 'remix-desktop'
const headers = { const headers = {
'X-GitHub-Api-Version': '2022-11-28' 'X-GitHub-Api-Version': '2022-11-28',
} }
const octokit = new Octokit({ const octokit = new Octokit({
auth: process.env.GH_TOKEN auth: process.env.GH_TOKEN,
}) })
async function getAllReleases() { async function getAllReleases() {
const releases = await octokit.request('GET /repos/{owner}/{repo}/releases', { const releases = await octokit.request('GET /repos/{owner}/{repo}/releases', {
owner: owner, owner: owner,
repo: repo, repo: repo,
headers: headers headers: headers,
}) })
return releases.data return releases.data
} }
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
});
}
async function getVersionFromPackageJson() { async function getVersionFromPackageJson() {
// ignore ts error // ignore ts error
// eslint-disable-next-line @typescript-eslint/no-var-requires // eslint-disable-next-line @typescript-eslint/no-var-requires
@ -29,49 +43,57 @@ async function getVersionFromPackageJson() {
return packageJson.version return packageJson.version
} }
async function getReleaseByTag(tag_name: string) { async function readReleaseFilesFromLocalDirectory() {
const releases = await octokit.request('GET /repos/{owner}/{repo}/releases/tags/{tag}', { const directoryPath = path.join(__dirname, '../../../release')
owner: owner, const files = fs.readdirSync(directoryPath)
repo: repo, return files
tag: tag_name,
headers: headers
})
return releases.data
} }
async function getReleaseAssets(release_id: number) { async function removeAsset(asset) {
const assets = await octokit.request('GET /repos/{owner}/{repo}/releases/{release_id}/assets', { await octokit.request('DELETE /repos/{owner}/{repo}/releases/assets/{asset_id}', {
owner: owner, owner: owner,
repo: repo, repo: repo,
release_id: release_id, asset_id: asset.id,
headers: headers headers: headers,
}) })
for (const asset of assets.data) {
console.log(asset.name)
} }
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
} }
})
async function readReleaseFilesFromLocalDirectory() { if (!release) {
const directoryPath = path.join(__dirname, '../../../release') console.log('No release found.')
const files = fs.readdirSync(directoryPath) return
console.log(files)
} }
let files = await readReleaseFilesFromLocalDirectory()
async function main() { files = files.filter((file) => file.endsWith('.dmg') || file.endsWith('.exe') || file.endsWith('.AppImage') || file.endsWith('.snap') || file.endsWith('.deb') || file.startsWith('latest'))
const version = await getVersionFromPackageJson() console.log(`Found ${files.length} files to upload`)
console.log(version) console.log(files)
const release = await getReleaseByTag('v' + version)
console.log(release)
if (!release.draft) { if (!release.draft) {
console.log('Release is not a draft') console.log(`Release ${version} is not a draft. Aborting...`)
return return
} }
// 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))
}
}
main()
//main()
readReleaseFilesFromLocalDirectory()
console.log(process.env.GH_TOKEN)
//getReleaseAssets()

@ -1,6 +1,6 @@
{ {
"name": "remixdesktop", "name": "remixdesktop",
"version": "0.0.11-Alpha", "version": "0.0.12-Alpha",
"main": "build/main.js", "main": "build/main.js",
"license": "MIT", "license": "MIT",
"type": "commonjs", "type": "commonjs",

Loading…
Cancel
Save