-
Notifications
You must be signed in to change notification settings - Fork 108
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 #510 from desktop/gcm
Bundle GCM on macOS and Linux
- Loading branch information
Showing
8 changed files
with
227 additions
and
24 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,21 @@ | ||
import { createHash } from 'crypto' | ||
|
||
export async function fetchAssetChecksum(uri: string) { | ||
const hs = createHash('sha256') | ||
|
||
const headers = { | ||
'User-Agent': 'dugite-native', | ||
accept: 'application/octet-stream', | ||
} | ||
|
||
await fetch(uri, { headers }) | ||
.then(x => | ||
x.ok | ||
? Promise.resolve(x) | ||
: Promise.reject(new Error(`Server responded with ${x.status}`)) | ||
) | ||
.then(x => x.arrayBuffer()) | ||
.then(x => hs.end(Buffer.from(x))) | ||
|
||
return hs.digest('hex') | ||
} |
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,81 @@ | ||
import { Octokit } from '@octokit/rest' | ||
import { updateGitCredentialManagerDependencies } from './lib/dependencies' | ||
import { fetchAssetChecksum } from './fetch-asset-checksum' | ||
|
||
process.on('unhandledRejection', reason => { | ||
console.error(reason) | ||
}) | ||
|
||
async function run(): Promise<boolean> { | ||
const token = process.env.GITHUB_ACCESS_TOKEN | ||
if (token == null) { | ||
console.log(`🔴 No GITHUB_ACCESS_TOKEN environment variable set`) | ||
return false | ||
} | ||
|
||
const octokit = new Octokit({ auth: `token ${token}` }) | ||
|
||
const user = await octokit.users.getAuthenticated({}) | ||
const me = user.data.login | ||
|
||
console.log(`✅ Token found for ${me}`) | ||
|
||
const owner = 'git-ecosystem' | ||
const repo = 'git-credential-manager' | ||
|
||
const release = await octokit.repos.getLatestRelease({ owner, repo }) | ||
|
||
const { tag_name, id } = release.data | ||
const version = tag_name.replace(/^v/, '') | ||
|
||
console.log(`✅ Newest git-credential-manager release '${version}'`) | ||
|
||
const assets = await octokit.repos.listReleaseAssets({ | ||
owner, | ||
repo, | ||
release_id: id, | ||
}) | ||
|
||
const fileTemplates = [ | ||
{ | ||
name: `gcm-linux_amd64.${version}.tar.gz`, | ||
platform: 'linux', | ||
arch: 'amd64', | ||
}, | ||
{ | ||
name: `gcm-osx-arm64-${version}.tar.gz`, | ||
platform: 'darwin', | ||
arch: 'arm64', | ||
}, | ||
{ | ||
name: `gcm-osx-x64-${version}.tar.gz`, | ||
platform: 'darwin', | ||
arch: 'amd64', | ||
}, | ||
] | ||
|
||
const files = [] | ||
|
||
for (const ft of fileTemplates) { | ||
const asset = assets.data.find(a => a.name === ft.name) | ||
|
||
if (!asset) { | ||
throw new Error(`Could not find asset for file: ${ft.name}`) | ||
} | ||
|
||
const url = asset.browser_download_url | ||
console.log(`⏳ Fetching checksum for ${ft.name}`) | ||
const checksum = await fetchAssetChecksum(url) | ||
console.log(`🔑 ${checksum}`) | ||
files.push({ ...ft, url, checksum }) | ||
} | ||
|
||
updateGitCredentialManagerDependencies(version, files) | ||
|
||
console.log( | ||
`✅ Updated dependencies metadata to Git credential manager '${version}'` | ||
) | ||
return true | ||
} | ||
|
||
run().then(success => process.exit(success ? 0 : 1)) |
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