diff --git a/.circleci/config.yml b/.circleci/config.yml index e6550104da..f3ac59b056 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -337,6 +337,13 @@ jobs: - checkout - attach_workspace: 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: docker: - image: cimg/node:20.0.0-browsers diff --git a/.gitignore b/.gitignore index 01477ff7f7..bcc5be412a 100644 --- a/.gitignore +++ b/.gitignore @@ -15,6 +15,7 @@ soljson.js *_group*.*.ts *_group*.ts stats.json +release # compiled output diff --git a/apps/remix-ide/ci/update_desktop_release_assets.ts b/apps/remix-ide/ci/update_desktop_release_assets.ts index 8d55ea4a94..bddd7f8aaf 100644 --- a/apps/remix-ide/ci/update_desktop_release_assets.ts +++ b/apps/remix-ide/ci/update_desktop_release_assets.ts @@ -1,27 +1,41 @@ -import { Octokit } from 'octokit' +import {Octokit} from 'octokit' import * as fs from 'fs' import * as path from 'path' const owner = 'bunsenstraat' const repo = 'remix-desktop' const headers = { - 'X-GitHub-Api-Version': '2022-11-28' + 'X-GitHub-Api-Version': '2022-11-28', } const octokit = new Octokit({ - auth: process.env.GH_TOKEN + auth: process.env.GH_TOKEN, }) - async function getAllReleases() { const releases = await octokit.request('GET /repos/{owner}/{repo}/releases', { owner: owner, repo: repo, - headers: headers + headers: headers, }) 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() { // ignore ts error // eslint-disable-next-line @typescript-eslint/no-var-requires @@ -29,49 +43,57 @@ async function getVersionFromPackageJson() { return packageJson.version } -async function getReleaseByTag(tag_name: string) { - const releases = await octokit.request('GET /repos/{owner}/{repo}/releases/tags/{tag}', { - owner: owner, - repo: repo, - tag: tag_name, - headers: headers - }) - return releases.data +async function readReleaseFilesFromLocalDirectory() { + const directoryPath = path.join(__dirname, '../../../release') + const files = fs.readdirSync(directoryPath) + return files } -async function getReleaseAssets(release_id: number) { - const assets = await octokit.request('GET /repos/{owner}/{repo}/releases/{release_id}/assets', { +async function removeAsset(asset) { + await octokit.request('DELETE /repos/{owner}/{repo}/releases/assets/{asset_id}', { owner: owner, repo: repo, - release_id: release_id, - headers: headers + asset_id: asset.id, + 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 + } + }) + if (!release) { + console.log('No release found.') + return } -} + let files = await readReleaseFilesFromLocalDirectory() -async function readReleaseFilesFromLocalDirectory() { - const directoryPath = path.join(__dirname, '../../../release') - const files = fs.readdirSync(directoryPath) + 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`) console.log(files) -} - - -async function main() { - const version = await getVersionFromPackageJson() - console.log(version) - const release = await getReleaseByTag('v' + version) - console.log(release) if (!release.draft) { - console.log('Release is not a draft') + console.log(`Release ${version} is not a draft. Aborting...`) 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() -readReleaseFilesFromLocalDirectory() -console.log(process.env.GH_TOKEN) -//getReleaseAssets() \ No newline at end of file +main() + diff --git a/apps/remixdesktop/package.json b/apps/remixdesktop/package.json index f917c36730..6ed62fb98d 100644 --- a/apps/remixdesktop/package.json +++ b/apps/remixdesktop/package.json @@ -1,6 +1,6 @@ { "name": "remixdesktop", - "version": "0.0.11-Alpha", + "version": "0.0.12-Alpha", "main": "build/main.js", "license": "MIT", "type": "commonjs",