|
| 1 | +import { Octokit } from '@octokit/rest' |
| 2 | +import { updateGitCredentialManagerDependencies } from './lib/dependencies' |
| 3 | +import { fetchAssetChecksum } from './fetch-asset-checksum' |
| 4 | + |
| 5 | +process.on('unhandledRejection', reason => { |
| 6 | + console.error(reason) |
| 7 | +}) |
| 8 | + |
| 9 | +async function run(): Promise<boolean> { |
| 10 | + const token = process.env.GITHUB_ACCESS_TOKEN |
| 11 | + if (token == null) { |
| 12 | + console.log(`🔴 No GITHUB_ACCESS_TOKEN environment variable set`) |
| 13 | + return false |
| 14 | + } |
| 15 | + |
| 16 | + const octokit = new Octokit({ auth: `token ${token}` }) |
| 17 | + |
| 18 | + const user = await octokit.users.getAuthenticated({}) |
| 19 | + const me = user.data.login |
| 20 | + |
| 21 | + console.log(`✅ Token found for ${me}`) |
| 22 | + |
| 23 | + const owner = 'git-ecosystem' |
| 24 | + const repo = 'git-credential-manager' |
| 25 | + |
| 26 | + const release = await octokit.repos.getLatestRelease({ owner, repo }) |
| 27 | + |
| 28 | + const { tag_name, id } = release.data |
| 29 | + const version = tag_name.replace(/^v/, '') |
| 30 | + |
| 31 | + console.log(`✅ Newest git-credential-manager release '${version}'`) |
| 32 | + |
| 33 | + const assets = await octokit.repos.listReleaseAssets({ |
| 34 | + owner, |
| 35 | + repo, |
| 36 | + release_id: id, |
| 37 | + }) |
| 38 | + |
| 39 | + const fileTemplates = [ |
| 40 | + { |
| 41 | + name: `gcm-linux_amd64.${version}.tar.gz`, |
| 42 | + platform: 'linux', |
| 43 | + arch: 'amd64', |
| 44 | + }, |
| 45 | + { |
| 46 | + name: `gcm-osx-arm64-${version}.tar.gz`, |
| 47 | + platform: 'darwin', |
| 48 | + arch: 'arm64', |
| 49 | + }, |
| 50 | + { |
| 51 | + name: `gcm-osx-x64-${version}.tar.gz`, |
| 52 | + platform: 'darwin', |
| 53 | + arch: 'amd64', |
| 54 | + }, |
| 55 | + ] |
| 56 | + |
| 57 | + const files = [] |
| 58 | + |
| 59 | + for (const ft of fileTemplates) { |
| 60 | + const asset = assets.data.find(a => a.name === ft.name) |
| 61 | + |
| 62 | + if (!asset) { |
| 63 | + throw new Error(`Could not find asset for file: ${ft.name}`) |
| 64 | + } |
| 65 | + |
| 66 | + const url = asset.browser_download_url |
| 67 | + console.log(`⏳ Fetching checksum for ${ft.name}`) |
| 68 | + const checksum = await fetchAssetChecksum(url) |
| 69 | + console.log(`🔑 ${checksum}`) |
| 70 | + files.push({ ...ft, url, checksum }) |
| 71 | + } |
| 72 | + |
| 73 | + updateGitCredentialManagerDependencies(version, files) |
| 74 | + |
| 75 | + console.log( |
| 76 | + `✅ Updated dependencies metadata to Git credential manager '${version}'` |
| 77 | + ) |
| 78 | + return true |
| 79 | +} |
| 80 | + |
| 81 | +run().then(success => process.exit(success ? 0 : 1)) |
0 commit comments