-
Notifications
You must be signed in to change notification settings - Fork 148
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #219 from desktop/automate-updating-config
automate updating the embedded Git details
- Loading branch information
Showing
7 changed files
with
181 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
{ | ||
"win32-x64": { | ||
"name": "dugite-native-v2.19.0-windows-x64.tar.gz", | ||
"url": "https://github.com/desktop/dugite-native/releases/download/v2.19.0-1/dugite-native-v2.19.0-windows-x64.tar.gz", | ||
"checksum": "d38baa1e5c559e2d0172a84f6e5ce996946f60ddd4432632c4ead90e49b73d60" | ||
}, | ||
"win32-ia32": { | ||
"name": "dugite-native-v2.19.0-windows-x86.tar.gz", | ||
"url": "https://github.com/desktop/dugite-native/releases/download/v2.19.0-1/dugite-native-v2.19.0-windows-x86.tar.gz", | ||
"checksum": "44dc57777959309ed4115e24ce0598dae19c93ce9731ef3a612f549b53e7ae9e" | ||
}, | ||
"darwin-x64": { | ||
"name": "dugite-native-v2.19.0-macOS.tar.gz", | ||
"url": "https://github.com/desktop/dugite-native/releases/download/v2.19.0-1/dugite-native-v2.19.0-macOS.tar.gz", | ||
"checksum": "53dcc276a404c8769104fa3ddf5595a86a7e22016449fb79d9bc5724a5563d80" | ||
}, | ||
"linux-x64": { | ||
"name": "dugite-native-v2.19.0-ubuntu.tar.gz", | ||
"url": "https://github.com/desktop/dugite-native/releases/download/v2.19.0-1/dugite-native-v2.19.0-ubuntu.tar.gz", | ||
"checksum": "04b4f70544e798467f07905b0b05853d6a34f4cfcbf63481e94907c6b9aa5876" | ||
}, | ||
"linux-arm64": { | ||
"name": "dugite-native-v2.19.0-arm64.tar.gz", | ||
"url": "https://github.com/desktop/dugite-native/releases/download/v2.19.0-1/dugite-native-v2.19.0-arm64.tar.gz", | ||
"checksum": "0589faac66321c27175f6fc9b19de13e6c1c091ea9de1f206d184d42ee020b47" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
const request = require('request') | ||
const fs = require('fs') | ||
const path = require('path') | ||
|
||
const options = { | ||
url: `https://api.github.com/repos/desktop/dugite-native/releases/latest`, | ||
headers: { | ||
Accept: 'application/json', | ||
'User-Agent': 'dugite' | ||
}, | ||
secureProtocol: 'TLSv1_2_method', | ||
json: true | ||
} | ||
|
||
request(options, async (err, response, release) => { | ||
if (err) { | ||
console.error('Unable to get latest release', err) | ||
return | ||
} | ||
|
||
const { tag_name, assets } = release | ||
|
||
console.log(`Updating embedded git config to use version ${tag_name}`) | ||
|
||
const output = { | ||
'win32-x64': await findWindows64BitRelease(assets), | ||
'win32-ia32': await findWindows32BitRelease(assets), | ||
'darwin-x64': await findMacOS64BitRelease(assets), | ||
'linux-x64': await findLinux64BitRelease(assets), | ||
'linux-arm64': await findLinuxARM64Release(assets) | ||
} | ||
|
||
const fileContents = JSON.stringify(output, null, 2) | ||
|
||
const embeddedGitPath = path.join(__dirname, 'embedded-git.json') | ||
|
||
fs.writeFileSync(embeddedGitPath, fileContents, 'utf8') | ||
|
||
console.log( | ||
`Done! Don't forget to commit any changes and run the test suite again with \`npm i\` to confirm they pass!` | ||
) | ||
}) | ||
|
||
function findWindows64BitRelease(assets) { | ||
const asset = assets.find(a => a.name.endsWith('-windows-x64.tar.gz')) | ||
if (asset == null) { | ||
throw new Error('Could not find Windows 64-bit archive in latest release') | ||
} | ||
return getDetailsForAsset(assets, asset) | ||
} | ||
|
||
function findWindows32BitRelease(assets) { | ||
const asset = assets.find(a => a.name.endsWith('-windows-x86.tar.gz')) | ||
if (asset == null) { | ||
throw new Error('Could not find Windows 32-bit archive in latest release') | ||
} | ||
return getDetailsForAsset(assets, asset) | ||
} | ||
|
||
function findMacOS64BitRelease(assets) { | ||
const asset = assets.find(a => a.name.endsWith('-macOS.tar.gz')) | ||
if (asset == null) { | ||
throw new Error('Could not find MacOS 64-bit archive in latest release') | ||
} | ||
return getDetailsForAsset(assets, asset) | ||
} | ||
|
||
function findLinux64BitRelease(assets) { | ||
const asset = assets.find(a => a.name.endsWith('-ubuntu.tar.gz')) | ||
if (asset == null) { | ||
throw new Error('Could not find Linux 64-bit archive in latest release') | ||
} | ||
return getDetailsForAsset(assets, asset) | ||
} | ||
|
||
function findLinuxARM64Release(assets) { | ||
const asset = assets.find(a => a.name.endsWith('-arm64.tar.gz')) | ||
if (asset == null) { | ||
throw new Error('Could not find Linux ARM64 archive in latest release') | ||
} | ||
return getDetailsForAsset(assets, asset) | ||
} | ||
|
||
function downloadChecksum(url) { | ||
return new Promise((resolve, reject) => { | ||
const options = { | ||
url, | ||
headers: { | ||
Accept: 'application/octet-stream', | ||
'User-Agent': 'dugite-native' | ||
}, | ||
secureProtocol: 'TLSv1_2_method' | ||
} | ||
|
||
request(options, (err, response, body) => { | ||
if (err) { | ||
reject(err) | ||
return | ||
} | ||
|
||
resolve(body) | ||
}) | ||
}) | ||
} | ||
|
||
async function getDetailsForAsset(assets, currentAsset) { | ||
const { name } = currentAsset | ||
const url = currentAsset.browser_download_url | ||
const checksumFile = assets.find(a => a.name === `${name}.sha256`) | ||
const checksumRaw = await downloadChecksum(checksumFile.browser_download_url) | ||
const checksum = checksumRaw.trim() | ||
return { name, url, checksum } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters