Skip to content

Commit

Permalink
Merge pull request #4919 from ethereum/desktop-master
Browse files Browse the repository at this point in the history
Desktop master
  • Loading branch information
bunsenstraat committed Sep 19, 2024
2 parents a1675b2 + 511a746 commit 06512f3
Show file tree
Hide file tree
Showing 161 changed files with 10,422 additions and 2,268 deletions.
368 changes: 336 additions & 32 deletions .circleci/config.yml

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ soljson.js
*_group*.*.ts
*_group*.ts
stats.json
release


# compiled output
Expand Down Expand Up @@ -61,6 +62,7 @@ testem.log
apps/remixdesktop/.webpack
apps/remixdesktop/out
apps/remixdesktop/release/
apps/remixdesktop/build*/
apps/remix-ide/src/assets/list.json
apps/remix-ide/src/assets/esbuild.wasm
apps/remixdesktop/build*
Expand Down
2 changes: 1 addition & 1 deletion apps/remix-ide-e2e/src/commands/addLocalPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ function addLocalPlugin (browser: NightwatchBrowser, profile: Profile & Location

browser.waitForElementVisible('*[data-id="pluginManagerComponentPluginManager"]')
.execute(function () {
window.testmode = true
(window as any).testmode = true
})
.click('*[data-id="pluginManagerComponentPluginSearchButton"]')
.waitForElementVisible('*[data-id="pluginManagerLocalPluginModalDialogModalDialogContainer-react"]')
Expand Down
7 changes: 7 additions & 0 deletions apps/remix-ide-e2e/src/tests/dgit_github.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ module.exports = {
'disconnect github #group1': function (browser: NightwatchBrowser) {
browser
.waitForElementVisible('*[data-id="github-panel"]')
.pause(1000)
.click('*[data-id="github-panel"]')
.waitForElementVisible('*[data-id="disconnect-github"]')
.pause(1000)
Expand Down Expand Up @@ -370,11 +371,17 @@ module.exports = {
browser.
clickLaunchIcon('dgit')
.waitForElementVisible('*[data-id="github-panel"]')
.pause(1000)
.click('*[data-id="github-panel"]')
.pause(1000)
.setValue('*[data-id="githubToken"]', 'invalidtoken')
.pause(1000)
.setValue('*[data-id="gitubUsername"]', 'git')
.pause(1000)
.setValue('*[data-id="githubEmail"]', 'git@example.com')
.pause(1000)
.click('*[data-id="saveGitHubCredentials"]')
.pause(1000)
.modalFooterOKClick('github-credentials-error')
},
'check the commits panel for pagination #group3': function (browser: NightwatchBrowser) {
Expand Down
1 change: 1 addition & 0 deletions apps/remix-ide-e2e/src/tests/dgit_local.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ module.exports = {
.waitForElementVisible('*[data-id="initgit-btn"]')
.click('*[data-id="initgit-btn"]')
.waitForElementVisible('*[data-id="github-panel"]')
.pause(1000)
.click('*[data-id="github-panel"]')
.waitForElementVisible('*[data-id="gitubUsername"]')
.setValue('*[data-id="gitubUsername"]', 'git')
Expand Down
5 changes: 3 additions & 2 deletions apps/remix-ide-e2e/src/tests/workspace_git.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ module.exports = {
.waitForElementVisible('[data-id="workspaceGitPanel"]')
.waitForElementVisible('[data-id="workspaceGitBranchesDropdown"]')
.click('[data-id="workspaceGitBranchesDropdown"]')
.pause()
.pause(1000)
.waitForElementVisible('[data-id="custom-dropdown-menu"]')
.waitForElementContainsText('[data-id="custom-dropdown-items"]', 'origin/dev')
.waitForElementContainsText('[data-id="custom-dropdown-items"]', 'origin/production')
Expand Down Expand Up @@ -404,7 +404,7 @@ module.exports = {
.getEditorValue((content) => {
browser.assert.ok(content.indexOf(`contract Counter is BaseHook {`) !== -1,
'Incorrect content')
}).pause()
})
},

'Should create Remix default workspace with files #group5': function (browser: NightwatchBrowser) {
Expand All @@ -426,6 +426,7 @@ module.exports = {
.waitForElementVisible('*[data-id="initgit-btn"]')
.click('*[data-id="initgit-btn"]')
.waitForElementVisible('*[data-id="github-panel"]')
.pause(1000)
.click('*[data-id="github-panel"]')
.waitForElementVisible('*[data-id="gitubUsername"]')
.setValue('*[data-id="gitubUsername"]', 'git')
Expand Down
242 changes: 242 additions & 0 deletions apps/remix-ide/ci/update_desktop_release_assets.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,242 @@
import { Octokit } from 'octokit'
import * as fs from 'fs'
import * as path from 'path'
import YAML from 'yaml'
import crypto from 'crypto'

const owner = 'remix-project-org'
let repo = 'remix-desktop'
const headers = {
'X-GitHub-Api-Version': '2022-11-28',
}

const version = getVersionFromPackageJson()
let channel = 'latest'

if (version.includes('beta')) {
channel = 'beta'
}
if (version.includes('alpha')) {
channel = 'alpha'
}
if (version.includes('insiders')) {
channel = 'insiders'
}

if (channel !== 'latest') repo = `remix-desktop-${channel}`

const octokit = new Octokit({
auth: process.env.GH_TOKEN_DESKTOP_PUBLISH,
})

async function getAllReleases() {
const releases = await octokit.request('GET /repos/{owner}/{repo}/releases', {
owner: owner,
repo: repo,
headers: headers,
})
return releases.data
}

async function uploadReleaseAsset(release, name, file) {
const upload_url = release.upload_url
console.log(`Uploading ${name} to ${upload_url}`)
if (fs.existsSync(file)) {
octokit.request({
method: "POST",
url: upload_url,
headers: {
"content-type": "text/plain",
},
data: fs.readFileSync(file),
name,
label: name
});
} else {
console.log(`File ${file} does not exist. Skipping...`)
}
}

function getVersionFromPackageJson() {
// ignore ts error
// eslint-disable-next-line @typescript-eslint/no-var-requires
const packageJson = require(__dirname + '/../../../apps/remixdesktop/package.json')
return packageJson.version
}

async function readReleaseFilesFromLocalDirectory() {
const directoryPath = path.join(__dirname, '../../../release')
const files = fs.readdirSync(directoryPath)
return files
}

async function removeAsset(asset) {
await octokit.request('DELETE /repos/{owner}/{repo}/releases/assets/{asset_id}', {
owner: owner,
repo: repo,
asset_id: asset.id,
headers: headers,
})
}

async function hashFile(file): Promise<string> {
return new Promise((resolve, reject) => {
const hash = crypto.createHash('sha512').setEncoding('base64');
// hash.on('error', reject).setEncoding(encoding);
fs.createReadStream(
file,
Object.assign({}, {}, {
highWaterMark: 1024 * 1024,
/* better to use more memory but hash faster */
})
)
.on('error', reject)
.on('end', () => {
hash.end();
console.log('hash done');
console.log(hash.read());
resolve(hash.digest('base64'));
})
.pipe(
hash,
{
end: false,
}
);
});
}

async function main() {

const allReleases = await getAllReleases()

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.')
// create release
console.log(`Creating release ${version}`)
const r = await octokit.request('POST /repos/{owner}/{repo}/releases', {
owner: owner,
repo: repo,
tag_name: `v${version}`,
name: `${version}`,
draft: true,
prerelease: true,
headers: headers,
})
release = r.data
}

let ymlFiles = await readReleaseFilesFromLocalDirectory()
ymlFiles = ymlFiles.filter((file) => file.endsWith('.yml') && file.startsWith('latest'))

console.log(`Found ${ymlFiles.length} yml files to upload`)

// read and parse yml latest files
// the yml files contain the sha512 hash and file size of the executable
// we need to recalculate the hash and file size of the executable
// and update the yml files
// this is because the executable is resigned after the yml files are created
for (const file of ymlFiles) {
const content = fs.readFileSync(path.join(__dirname, '../../../release', file), 'utf8')
const parsed = YAML.parse(content)
const hashes: {
url: string,
sha512: string,
size: number
}[] = []
if (parsed.files) {
console.log(`Found`, parsed.files)
for (const f of parsed.files) {
const executable = f.url
const exists = fs.existsSync(path.join(__dirname, '../../../release', executable))
if (!exists) {
console.log(`File ${executable} does not exist on local fs. Skipping...`)
continue
} else {
console.log(`File ${executable} exists on local fs. Recalculating hash...`)
// calculate sha512 hash of executable
const hash: string = await hashFile(path.join(__dirname, '../../../release', executable))
console.log(hash)
// calculate file size of executable
const stats = fs.statSync(path.join(__dirname, '../../../release', executable))
const fileSizeInBytes = stats.size
console.log(fileSizeInBytes)
hashes.push({
url: executable,
sha512: hash,
size: fileSizeInBytes
})
if (parsed.path === executable) {
parsed.sha512 = hash
parsed.size = fileSizeInBytes
}
}
}
}
console.log(hashes)
parsed.files = hashes
const newYml = YAML.stringify(parsed)
fs.writeFileSync(path.join(__dirname, '../../../release', file), newYml)
}

let files = await readReleaseFilesFromLocalDirectory()

try {
if (fs.existsSync(path.join(__dirname, '../../../release', `latest-mac-arm64.yml`)) && fs.existsSync(path.join(__dirname, '../../../release', `latest-mac-x64.yml`))) {
// combine the two files
const macArm64 = fs.readFileSync(path.join(__dirname, '../../../release', `latest-mac-arm64.yml`), 'utf8')
const mac = fs.readFileSync(path.join(__dirname, '../../../release', `latest-mac-x64.yml`), 'utf8')
const parsedMacArm64 = YAML.parse(macArm64)
const parsedMac = YAML.parse(mac)
console.log(parsedMacArm64)
console.log(parsedMac)
const combined = {
...parsedMac,
files: [
...parsedMac.files,
...parsedMacArm64.files
]
}
console.log(combined)
const newYml = YAML.stringify(combined)
fs.writeFileSync(path.join(__dirname, '../../../release', `latest-mac.yml`), newYml)
// remove the arm64 file
fs.unlinkSync(path.join(__dirname, '../../../release', `latest-mac-arm64.yml`))
fs.unlinkSync(path.join(__dirname, '../../../release', `latest-mac-x64.yml`))
}
} catch (e) {
console.log(e)
}

files = await readReleaseFilesFromLocalDirectory()
files = files.
filter((file) => file.endsWith('.zip') || file.endsWith('.dmg') || file.endsWith('.exe') || file.endsWith('.AppImage') || file.endsWith('.snap') || file.endsWith('.deb') || file.startsWith(`latest`))
.filter((file) => !file.startsWith('._'))
console.log(`Found ${files.length} files to upload`)
console.log(files)
if (!release.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()

Loading

0 comments on commit 06512f3

Please sign in to comment.